2011-07-30 40 views
0

我點擊按鈕時已經通過啓動新選項卡活動時的疊加流程上的鏈接。在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); 

而且我已經添加了三個不同的活動changePassword,editprofile和homeActivity在homeTabActivity上。

我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

你在網上獲得空指針異常沒有。 28在HelloTtabActivity。裏面onCreate()方法。郵編號碼28在這裏或者另外解決它。

+0

//爲每個選項卡初始化TabSpec並將其添加到TabHost spec = tabHost.newTabSpec(「Home」)。setIndicator(「Home」).setContent(intent); //第28行請告訴我在這條線上wat是錯誤的? – Hisenberg

+0

請確保您在xml文件中聲明tabhost爲android:id =「@ android:id/tabhost」。 –

相關問題