0

Hi when i am trying to add tabs i am getting nullpointer exception.I am creating one activity MyLanguageActivity this extends Activity and i am creating one more activity MyTabActivity this extends TabActivity.Inside of MyLangugeActivity i am selecting language and i am tapping on done button i am adding tabs one more time like this :

public void setTabs(){
Intent intent, intent1, intent2, intent3;
    TabHost tabHost = MyTabActivity.tabHost;
    System.out.println(tabHost);
    TextView tv;
    intent = new Intent(
            "com.activitygroups.RequestTabActivtyGroup");
    intent1 = new Intent(
            "com.activitygroups.OffersTabActivityGroup");

    intent.putExtra("content", "requests");
    intent1.putExtra("content", "offers");


    System.out.println("request string : "
            + getResources().getString(R.string.requests));
    System.out.println("drowable id : "
            + getResources().getDrawable(R.drawable.request_tab_selector));

    tabHost.addTab(tabHost
            .newTabSpec("request_tab")
            .setIndicator(
                    LanguageUtils.getLanguage(MyLanguageActivity.this,
                            getResources().getString(R.string.requests)),
                    getResources().getDrawable(
                            R.drawable.request_tab_selector))
            .setContent(
                    new Intent(intent)
                            .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));

}

inside og done button onclick i am calling this method.When i tap on done i am getting nullpointer exception.. My logcat here :

02-10 12:32:37.112: E/AndroidRuntime(5560): FATAL EXCEPTION: main
02-10 12:32:37.112: E/AndroidRuntime(5560): java.lang.NullPointerException
02-10 12:32:37.112: E/AndroidRuntime(5560):     at         android.widget.TabWidget.setCurrentTab(TabWidget.java:339)
02-10 12:32:37.112: E/AndroidRuntime(5560):     at android.widget.TabWidget.focusCurrentTab(TabWidget.java:363)
02-10 12:32:37.112: E/AndroidRuntime(5560):     at android.widget.TabHost.setCurrentTab(TabHost.java:320)
02-10 12:32:37.112: E/AndroidRuntime(5560):     at android.widget.TabHost.addTab(TabHost.java:213)
02-10 12:32:37.112: E/AndroidRuntime(5560):     at com.melhoroferta.LanguageSettingActivity.setUpTabs(MyLanguageActivity.java:204)
02-10 12:32:37.112: E/AndroidRuntime(5560):     at com.melhoroferta.LanguageSettingActivity.onClick(MyLanguageActivity.java:142)
02-10 12:32:37.112: E/AndroidRuntime(5560):     at android.view.View.performClick(View.java:2408)
02-10 12:32:37.112: E/AndroidRuntime(5560):     at android.view.View$PerformClick.run(View.java:8818)
02-10 12:32:37.112: E/AndroidRuntime(5560):     at   android.os.Handler.handleCallback(Handler.java:587)
  02-10 12:32:37.112: E/AndroidRuntime(5560):   at android.os.Handler.dispatchMessage(Handler.java:92)
        02-10 12:32:37.112: E/AndroidRuntime(5560):     at android.os.Looper.loop(Looper.java:123)
         02-10 12:32:37.112: E/AndroidRuntime(5560):    at android.app.ActivityThread.main(ActivityThread.java:4627)
          02-10 12:32:37.112: E/AndroidRuntime(5560):   at java.lang.reflect.Method.invokeNative(Native Method)
  02-10 12:32:37.112: E/AndroidRuntime(5560):   at java.lang.reflect.Method.invoke(Method.java:521)
   02-10 12:32:37.112: E/AndroidRuntime(5560):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:871)
   02-10 12:32:37.112: E/AndroidRuntime(5560):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
        02-10 12:32:37.112: E/AndroidRuntime(5560):     at dalvik.system.NativeStart.main(Native Method)

Sorry guys i am forgot to remove those intent 2 and intent 3 actually this intents are i am not using..

6
  • 6
    Hello Rajesh, nullpointerexception bcaz of not created objects of intent2,intent3. Commented Feb 10, 2014 at 7:28
  • this must be as answer @AmolSawant96Kuli Commented Feb 10, 2014 at 7:30
  • @AmolSawant96Kuli post it as answer.. Commented Feb 10, 2014 at 7:30
  • 1
    Rajesh as @AmolSawant96Kuli said your Intents are not init..that too you are not using it anywhere why you need it.. Commented Feb 10, 2014 at 7:32
  • please check my edit.i am not using this intent 2 and intent 3.sorry i forgot to remove this intents.I am getting exceptions in tabhost.addTab(...) in this line.. Commented Feb 10, 2014 at 7:59

2 Answers 2

4
 intent = new Intent(
            "com.activitygroups.RequestTabActivtyGroup");
 intent1 = new Intent(
            "com.activitygroups.OffersTabActivityGroup");

Add Intents,

 intent2 = new Intent(
            "profile activity");
 intent3 = new Intent(
            "setting activity");
Sign up to request clarification or add additional context in comments.

2 Comments

please check my edit.i am not using this intent 2 and intent 3.sorry i forgot to remove this intents.I am getting exceptions in tabhost.addTab(...) in this line..
might be problem with this. setContent(new Intent(intent) .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))); try to replace with .setContent(intent.addFlag(Intent.FLAG_ACTIVITY_CLEAR_TOP));
0

You have to initialize your intent2 and intent3.Because you use .putExtra to 2 not initialized Intents

Just add:

intent2 = new Intent(); //put in the brackets what you want or need
intent3 = new Intent();

1 Comment

please check my edit.i am not using this intent 2 and intent 3.sorry i forgot to remove this intents.I am getting exceptions in tabhost.addTab(...) in this line..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.