在扩展Acitvity时它会正常运行,但每当扩展ActionBarActivity应用程序崩溃时

时间:2016-10-24 06:06:25

标签: java android

public class MainActivity extends ActionBarActivity  {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }
}

这是我得到的错误

10-24 01:49:30.135: E/AndroidRuntime(1390): FATAL EXCEPTION: main
10-24 01:49:30.135: E/AndroidRuntime(1390): Process: com.example.nevigation, PID: 1390
10-24 01:49:30.135: E/AndroidRuntime(1390): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.nevigation/com.example.nevigation.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.nevigation.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.nevigation-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.nevigation-1, /system/lib]]
10-24 01:49:30.135: E/AndroidRuntime(1390):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2102)
10-24 01:49:30.135: E/AndroidRuntime(1390):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
10-24 01:49:30.135: E/AndroidRuntime(1390):     at android.app.ActivityThread.access$700(ActivityThread.java:135)
10-24 01:49:30.135: E/AndroidRuntime(1390):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
10-24 01:49:30.135: E/AndroidRuntime(1390):     at android.os.Handler.dispatchMessage(Handler.java:102)
10-24 01:49:30.135: E/AndroidRuntime(1390):     at android.os.Looper.loop(Looper.java:137)
10-24 01:49:30.135: E/AndroidRuntime(1390):     at android.app.ActivityThread.main(ActivityThread.java:4998)
10-24 01:49:30.135: E/AndroidRuntime(1390):     at java.lang.reflect.Method.invokeNative(Native Method)
10-24 01:49:30.135: E/AndroidRuntime(1390):     at java.lang.reflect.Method.invoke(Method.java:515)
10-24 01:49:30.135: E/AndroidRuntime(1390):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
10-24 01:49:30.135: E/AndroidRuntime(1390):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
10-24 01:49:30.135: E/AndroidRuntime(1390):     at dalvik.system.NativeStart.main(Native Method)
10-24 01:49:30.135: E/AndroidRuntime(1390): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.nevigation.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.nevigation-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.nevigation-1, /system/lib]]
10-24 01:49:30.135: E/AndroidRuntime(1390):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
10-24 01:49:30.135: E/AndroidRuntime(1390):     at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
10-24 01:49:30.135: E/AndroidRuntime(1390):     at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
10-24 01:49:30.135: E/AndroidRuntime(1390):     at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
10-24 01:49:30.135: E/AndroidRuntime(1390):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2093)

3 个答案:

答案 0 :(得分:0)

尝试使用SupportActionBarActivity而不是ActionBar Activity

答案 1 :(得分:0)

下面super.onCreate(savedInstanceState);添加setContentView(R.layout.activity_main);然后再次清理并构建项目。 希望这会对您有所帮助,或者粘贴完整的logcat错误。

答案 2 :(得分:0)

检查AndroidManifest.xml中提到的包裹。

应该是<activity name="com.example.nevtest.MainActivity"。此处指定的包应与MainActivity.java文件的第一行相同。

这通常是通过不同的包在你的Activity课程中移动的效果。您Activity的套餐中的任何更改都应反映在AndroidManifest.xml