无法实例化活动 - ClassNotFoundException

时间:2013-04-25 12:35:23

标签: java android

我的android应用程序抛出ClassNotFoundException异常。

这是我在MainActivity.java中的代码:

    package pl.advancedsoftware.manga;
    public class MainActivity extends FragmentActivity {
    ViewPager viewPager; 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        setContentView(R.layout.activity_main);
        Favourites.context= getApplicationContext();
        SectionsPagerAdapter sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
        viewPager= (ViewPager)findViewById(R.id.pager);
        viewPager.setAdapter(sectionsPagerAdapter); 
    }

    @Override   
    public boolean onCreateOptionsMenu(Menu menu) {
      //  getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}
AndroidManifest.xml中的

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="pl.advancedsoftware.manga"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15" /> 

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="pl.advancedsoftware.manga.MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="pl.advancedsoftware.manga.BookActivity" 
            android:label="Books" />
        <activity
            android:name="pl.advancedsoftware.manga.EpisodeActivity"
            android:label="Epsiode" />
    </application>

</manifest>

我的例外是:

> 04-25 12:28:08.868: E/AndroidRuntime(898): FATAL EXCEPTION: main 04-25
> 12:28:08.868: E/AndroidRuntime(898): java.lang.RuntimeException:
> Unable to instantiate activity
> ComponentInfo{pl.advancedsoftware.manga/pl.advancedsoftware.manga.MainActivity}:
> java.lang.ClassNotFoundException: Didn't find class
> "pl.advancedsoftware.manga.MainActivity" on path:
> /data/app/pl.advancedsoftware.manga-1.apk 04-25 12:28:08.868:
> E/AndroidRuntime(898):    at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
> 04-25 12:28:08.868: E/AndroidRuntime(898):    at
> android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
> 04-25 12:28:08.868: E/AndroidRuntime(898):    at
> android.app.ActivityThread.access$600(ActivityThread.java:141) 04-25
> 12:28:08.868: E/AndroidRuntime(898):  at
> android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
> 04-25 12:28:08.868: E/AndroidRuntime(898):    at
> android.os.Handler.dispatchMessage(Handler.java:99) 04-25
> 12:28:08.868: E/AndroidRuntime(898):  at
> android.os.Looper.loop(Looper.java:137) 04-25 12:28:08.868:
> E/AndroidRuntime(898):    at
> android.app.ActivityThread.main(ActivityThread.java:5041) 04-25
> 12:28:08.868: E/AndroidRuntime(898):  at
> java.lang.reflect.Method.invokeNative(Native Method) 04-25
> 12:28:08.868: E/AndroidRuntime(898):  at
> java.lang.reflect.Method.invoke(Method.java:511) 04-25 12:28:08.868:
> E/AndroidRuntime(898):    at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
> 04-25 12:28:08.868: E/AndroidRuntime(898):    at
> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 04-25
> 12:28:08.868: E/AndroidRuntime(898):  at
> dalvik.system.NativeStart.main(Native Method) 04-25 12:28:08.868:
> E/AndroidRuntime(898): Caused by: java.lang.ClassNotFoundException:
> Didn't find class "pl.advancedsoftware.manga.MainActivity" on path:
> /data/app/pl.advancedsoftware.manga-1.apk 04-25 12:28:08.868:
> E/AndroidRuntime(898):    at
> dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
> 04-25 12:28:08.868: E/AndroidRuntime(898):    at
> java.lang.ClassLoader.loadClass(ClassLoader.java:501) 04-25
> 12:28:08.868: E/AndroidRuntime(898):  at
> java.lang.ClassLoader.loadClass(ClassLoader.java:461) 04-25
> 12:28:08.868: E/AndroidRuntime(898):  at
> android.app.Instrumentation.newActivity(Instrumentation.java:1054)
> 04-25 12:28:08.868: E/AndroidRuntime(898):    at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
> 04-25 12:28:08.868: E/AndroidRuntime(898):    ... 11 more

我看到路径可能有问题/data/app/pl.advancedsoftware.manga-1.apk但我不知道。我想说这个项目在从存储库中克隆后停止工作。

2 个答案:

答案 0 :(得分:1)

检查您是从android.support.v4.app.Fragment而不是android.app.Fragment继承。

答案 1 :(得分:0)

尝试从您的设备卸载应用,然后清理重建项目。在极少数情况下,重启Eclipse可能会有所作为。