Android无法实例化活动:找不到path上的类

我已经导入项目到Eclipse中,当我尝试运行它,然后引发这个exception:

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.polygraf/com.polygraf.activity.Dashboard}: java.lang.ClassNotFoundException: Didn't find class "com.polygraf.activity.Dashboard" on path: /data/app/com.polygraf-1.apk

我试图清理项目,然后检查所有的类名和清单是否正常,但仍然无法find为什么会发生这种情况。 你能帮我一下吗?

Dashbard类:

 public class Dashboard extends FragmentActivity { private static final String WELCOME_TYPE = "WELCOME_TYPE"; private static final String HELP_TYPE = "HELP_TYPE"; public static final String ADRESS_CONTENT = "ADRESS_CONTENT"; public static final String DOC_NAME = "DOC_NAME"; private Transcript mContent; private ISettableContent mListOfDocument; private String mAddress; private String mDocName; public Dashboard() { } /** Called with the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.dashboard); boolean content = false; // View gc = (NoSaveStateFrameLayout) // findViewById(R.id.content_fragment); // Fragment frContent = getSupportFragmentManager().findFragmentById(R.id.content_fragment); mContent = ((IGetContent) frContent).getContent(); TranscriptSetting cc = Polygraf.getInstance().getContentSetting(); Fragment frDocumentsList = getSupportFragmentManager().findFragmentById(R.id.documents); mListOfDocument = (ISettableContent) frDocumentsList; cc.registerContent(mListOfDocument); if (getIntent().hasExtra(ADRESS_CONTENT)) { mAddress = getIntent().getStringExtra(ADRESS_CONTENT); mDocName = getIntent().getStringExtra(DOC_NAME); mContent.setAddress(mAddress, mDocName); content = true; } else if (getIntent().hasExtra(WELCOME_TYPE)) { content = true; prepareVisibilityBtnTranscript(); } else if (getIntent().hasExtra(HELP_TYPE)) { content = true; mContent.showHelp(); } if (content) { FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.hide(frDocumentsList); ft.commit(); // because on diferent layouts for small and large device // some views missing, so the test is inportant View contentLayout = findViewById(R.id.contentLayout); if (contentLayout != null) { contentLayout.setVisibility(View.VISIBLE); } prepareVisibilityBtnWelcome(); // cp.setContent(mContent); } cc.registerContent(mContent); // cp.setListener(cc); } . . . } 

和清单文件:

 <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="17" /> <application android:name=".Polygraf" android:allowBackup="true" android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/skeleton_app" android:theme="@android:style/Theme.Black.NoTitleBar" > <activity android:name="com.polygraf.activity.Dashboard" android:configChanges="orientation|keyboard" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <!-- This places this activity into the main app list. --> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="com.polygraf.activity.SettingActivity" android:label="@string/skeleton_app" /> <activity android:name="com.polygraf.activity.ContentActivity" android:label="@string/skeleton_app" > </activity> <activity android:name="com.polygraf.activity.PlayVideo" android:configChanges="orientation|keyboard" android:label="@string/skeleton_app" /> </application> 

我想你正在使用Eclipse。 你的活动没问题,但Eclipse没有在APK中包含支持包…如果你在stacktrace中查看错误,你会Unable to find FragmentActivity问题的根源:“ Unable to find FragmentActivity ”。 或者你可以解压apk,undex它,你会看到兼容性包类不包括在内。

要解决这个问题,请右键单击您的项目,属性,构buildpath并转到导出选项卡。 确保检查“ Android private libraries ”。 干净和重build应该把你跟踪…

我在这个问题上花了一段时间后,我发现的解决scheme是在libs文件夹中添加的属性> Android – appcompat_v7和appcompat_v4之间的冲突。 我删除appcompat_v4后,错误不再出现。 我希望这个答案可以帮助未来的某个人。

你应该从sdk导入新的appcompat_v7,并将其作为内置path使用,这对我很有用。