开发者

Problem in starting tab activity on button click

开发者 https://www.devze.com 2023-03-23 19:16 出处:网络
I have gone through links on stackover flow on starting new tab activity on button click. I am getting following on logcat :

I have gone through links on stackover flow on starting new tab activity on button click.

I am getting following on 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

I am trying to start HomeTabActivity on click of login button as :

Intent newIntent = new Intent(
                                    getApplicationContext(), HomeTabActivity.class);
                            newIntent.putExtra("Userid", message);
                            newIntent.putExtra("Password", txtPswrd.getText()
                                    .toString());
                            startActivity(newIntent);

Also I have added three different activities changePassword,editprofile and homeActivity on homeTabActivity.

the code for my homeTabActivity.java is

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);

and the code segment i added for this in manifest file is :

<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" /&g开发者_如何转开发t;
            </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>


you are getting null pointer exception on line no. 28 in HelloTtabActivity. Inside onCreate() Method. Post line no. 28 here or solve it yourself otherwise.

0

精彩评论

暂无评论...
验证码 换一张
取 消