我正在使用此代码切换到我的类Main_menu.java:
Intent myIntent = new Intent(view.getContext(), Main_menu.class); /** Class name here */
startActivityForResult(myIntent, 0);
当我运行这个时,我崩溃了这个异常
03-02 10:13:05.933: E/AndroidRuntime(5963): FATAL EXCEPTION: main
03-02 10:13:05.933: E/AndroidRuntime(5963): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.CarbonDev.codecabana/com.CarbonDev.codecabana.Main_menu}: java.lang.ClassCastException: com.CarbonDev.codecabana.Main_menu
03-02 10:13:05.933: E/AndroidRuntime(5963): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1680)
03-02 10:13:05.933: E/AndroidRuntime(5963): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
03-02 10:13:05.933: E/AndroidRuntime(5963): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
03-02 10:13:05.933: E/AndroidRuntime(5963): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
03-02 10:13:05.933: E/AndroidRuntime(5963): at android.os.Handler.dispatchMessage(Handler.java:99)
03-02 10:13:05.933: E/AndroidRuntime(5963): at android.os.Looper.loop(Looper.java:130)
03-02 10:13:05.933: E/AndroidRuntime(5963): at android.app.ActivityThread.main(ActivityThread.java:3835)
03-02 10:13:05.933: E/AndroidRuntime(5963): at java.lang.reflect.Method.invokeNative(Native Method)
03-02 10:13:05.933: E/AndroidRuntime(5963): at java.lang.reflect.Method.invoke(Method.java:507)
03-02 10:13:05.933: E/AndroidRuntime(5963): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
03-02 10:13:05.933: E/AndroidRuntime(5963): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
03-02 10:13:05.933: E/AndroidRuntime(5963): at dalvik.system.NativeStart.main(Native Method)
03-02 10:13:05.933: E/AndroidRuntime(5963): Caused by: java.lang.ClassCastException: com.CarbonDev.codecabana.Main_menu
03-02 10:13:05.933: E/AndroidRuntime(5963): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
03-02 10:13:05.933: E/AndroidRuntime(5963): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1672)
03-02 10:13:05.933: E/AndroidRuntime(5963): ... 11 more
这是我的Main_menu类代码:
package com.CarbonDev.codecabana;
import android.app.Activity;
import android.os.Bundle;
public class Main_menu {
public class settings extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu_activity);
}
}
}
这是我的清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.CarbonDev.codecabana"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.CarbonDev.codecabana.CodeEditor"
android:label="@string/app_name"
android:windowSoftInputMode="adjustResize"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.CarbonDev.codecabana.Main_menu"></activity>
</application>
</manifest>
有什么想法吗?
答案 0 :(得分:0)
package com.CarbonDev.codecabana;
import android.app.Activity;
import android.os.Bundle;
public class Main_menu extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu_activity);
}
}
}
这应该解决它,请查看Here以获得一个良好的起点。