我在按钮点击时启动新选项卡活动时已经浏览了堆栈流的链接。
我正在关注logcat:
07-30 13:08:10.460: ERROR/AndroidRuntime(304): FATAL EXCEPTION: main
07-30 13:08:10.460: ERROR/AndroidRuntime(304): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.biz.mlm/com.biz.mlm.HomeTabActivity}: java.lang.NullPointerException
07-30 13:08:10.460: ERROR/AndroidRuntime(304): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
07-30 13:08:10.460: ERROR/AndroidRuntime(304): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-30 13:08:10.460: ERROR/AndroidRuntime(304): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-30 13:08:10.460: ERROR/AndroidRuntime(304): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-30 13:08:10.460: ERROR/AndroidRuntime(304): at android.os.Handler.dispatchMessage(Handler.java:99)
07-30 13:08:10.460: ERROR/AndroidRuntime(304): at android.os.Looper.loop(Looper.java:123)
07-30 13:08:10.460: ERROR/AndroidRuntime(304): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-30 13:08:10.460: ERROR/AndroidRuntime(304): at java.lang.reflect.Method.invokeNative(Native Method)
07-30 13:08:10.460: ERROR/AndroidRuntime(304): at java.lang.reflect.Method.invoke(Method.java:521)
07-30 13:08:10.460: ERROR/AndroidRuntime(304): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-30 13:08:10.460: ERROR/AndroidRuntime(304): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-30 13:08:10.460: ERROR/AndroidRuntime(304): at dalvik.system.NativeStart.main(Native Method)
07-30 13:08:10.460: ERROR/AndroidRuntime(304): Caused by: java.lang.NullPointerException
07-30 13:08:10.460: ERROR/AndroidRuntime(304): at com.biz.mlm.HomeTabActivity.onCreate(HomeTabActivity.java:28)
07-30 13:08:10.460: ERROR/AndroidRuntime(304): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-30 13:08:10.460: ERROR/AndroidRuntime(304): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
07-30 13:08:10.460: ERROR/AndroidRuntime(304): ... 11 more
07-30 13:08:10.520: WARN/ActivityManager(58): Force finishing activity com.biz.mlm/.HomeTabActivity
07-30 13:08:10.520: WARN/ActivityManager(58): Force finishing activity com.biz.mlm/.login
我试图点击登录按钮启动HomeTabActivity:
Intent newIntent = new Intent(
getApplicationContext(), HomeTabActivity.class);
newIntent.putExtra("Userid", message);
newIntent.putExtra("Password", txtPswrd.getText()
.toString());
startActivity(newIntent);
此外,我在homeTabActivity上添加了三个不同的活动changePassword,editprofile和homeActivity。
我的homeTabActivity.java的代码是
TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost); // The activity TabHost
TabHost.TabSpec spec; // Reusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this,HomeActivity.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("Home").setIndicator("Home").setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, changePasswordActivity.class);
spec = tabHost.newTabSpec("Change Password").setIndicator("Change Password").setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, editProfileActivity.class);
spec = tabHost.newTabSpec("Edit Profile").setIndicator("Edit Profile").setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(2);
我在清单文件中为此添加的代码段是:
<activity android:name=".HomeTabActivity" android:label="Home"
android:theme="@android:style/Theme.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".HomeActivity">
<intent-filter>
<action android:name="com.biz.mlm.HomeActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".editProfileActivity">
<intent-filter>
<action android:name="com.biz.mlm.editProfileActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".changePasswordActivity">
<intent-filter>
<action android:name="com.biz.mlm.changePasswordActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
答案 0 :(得分:0)
你在行号上得到空指针异常。 HelloTtabActivity
中的28。在onCreate
()方法内。邮政编号28在这里或者自己解决。