我刚刚从 Eclipse 新的 Android 文件向导创建了一个新活动。我使用选项卡式导航创建了活动。但是,当我尝试从主要活动移至该活动时,应用程序崩溃并出现错误:unfortunately myAppName has stopped
在我的主要活动中,单击一个按钮,我想将用户带到一个选项卡式活动。我正在使用以下代码将它们移动到下一个活动:
Intent calActivityIntent = new Intent(this, CalendarActivity.class);
this.startActivity(calActivityIntent);
这段代码有问题吗?当我通过 Eclipse 向导添加选项卡式活动时,我假设该新活动的代码是正确的。
编辑:
日志猫:
01-14 18:42:15.770: E/AndroidRuntime(23918): FATAL EXCEPTION: main
01-14 18:42:15.770: E/AndroidRuntime(23918): java.lang.IllegalStateException: Could not execute method of the activity
01-14 18:42:15.770: E/AndroidRuntime(23918): at android.view.View$1.onClick(View.java:3071)
01-14 18:42:15.770: E/AndroidRuntime(23918): at android.view.View.performClick(View.java:3538)
01-14 18:42:15.770: E/AndroidRuntime(23918): at android.view.View$PerformClick.run(View.java:14319)
01-14 18:42:15.770: E/AndroidRuntime(23918): at android.os.Handler.handleCallback(Handler.java:608)
01-14 18:42:15.770: E/AndroidRuntime(23918): at android.os.Handler.dispatchMessage(Handler.java:92)
01-14 18:42:15.770: E/AndroidRuntime(23918): at android.os.Looper.loop(Looper.java:156)
01-14 18:42:15.770: E/AndroidRuntime(23918): at android.app.ActivityThread.main(ActivityThread.java:5045)
01-14 18:42:15.770: E/AndroidRuntime(23918): at java.lang.reflect.Method.invokeNative(Native Method)
01-14 18:42:15.770: E/AndroidRuntime(23918): at java.lang.reflect.Method.invoke(Method.java:511)
01-14 18:42:15.770: E/AndroidRuntime(23918): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-14 18:42:15.770: E/AndroidRuntime(23918): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-14 18:42:15.770: E/AndroidRuntime(23918): at dalvik.system.NativeStart.main(Native Method)
01-14 18:42:15.770: E/AndroidRuntime(23918): Caused by: java.lang.reflect.InvocationTargetException
01-14 18:42:15.770: E/AndroidRuntime(23918): at java.lang.reflect.Method.invokeNative(Native Method)
01-14 18:42:15.770: E/AndroidRuntime(23918): at java.lang.reflect.Method.invoke(Method.java:511)
01-14 18:42:15.770: E/AndroidRuntime(23918): at android.view.View$1.onClick(View.java:3066)
01-14 18:42:15.770: E/AndroidRuntime(23918): ... 11 more
01-14 18:42:15.770: E/AndroidRuntime(23918): Caused by: java.lang.NullPointerException
01-14 18:42:15.770: E/AndroidRuntime(23918): at com.example.MyAppName.MainActivity.mainMenuButtonClicked(MainActivity.java:94)
01-14 18:42:15.770: E/AndroidRuntime(23918): ... 14 more
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myappname"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
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.example.myappname.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.myappname.CalendarActivity"
android:label="@string/title_activity_calendar" >
</activity>
</application>
</manifest>
注意:名为“CalendarActivity”的活动是选项卡式活动。