Question

I have two tabs in a activity. When I run the app with both tabs, it's showing force close error. When I run the same app by commenting tabHost.addTab(spec) line for wifisettings tab, timeclock settings tab is opening. But I need to open both the tabs i.e wifi settings and time clock settings.

Code is here:

 setContentView(R.layout.preferences);
    pref_close   = (Button) findViewById(R.id.close_prefs);
    TabHost tabHost = getTabHost();  // The activity TabHost
    TabHost.TabSpec spec;  // Resusable 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( WifiManager.ACTION_PICK_WIFI_NETWORK);

    // Initialize a TabSpec for each tab and add it to the TabHost
    spec = tabHost.newTabSpec("wifi").setIndicator("Wifi Settings",null).setContent(intent);
    tabHost.addTab(spec);

    // Do the same for the other tabs
    intent = new Intent(this, AppSettings.class);

    spec = tabHost.newTabSpec("settings").setIndicator(" Clock Settings",null).setContent(intent);
    tabHost.addTab(spec);

    tabHost.setCurrentTab(0);

    pref_close.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {

            finish();               
        }

});
}
   }

Same code is working for the device (Android3.0.1) but not working for device (4.1.1). And my logcat is:

03-30 07:47:35.921: E/AndroidRuntime(8712): FATAL EXCEPTION: main
03-30 07:47:35.921: E/AndroidRuntime(8712): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.visionexceed.timeclock/com.vision.timeclock.activity.Preferences}: java.lang.IllegalArgumentException: you must specify a way to create the tab content
03-30 07:47:35.921: E/AndroidRuntime(8712):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
03-30 07:47:35.921: E/AndroidRuntime(8712):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122)
03-30 07:47:35.921: E/AndroidRuntime(8712):     at android.app.ActivityThread.access$600(ActivityThread.java:140)
03-30 07:47:35.921: E/AndroidRuntime(8712):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228)
03-30 07:47:35.921: E/AndroidRuntime(8712):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-30 07:47:35.921: E/AndroidRuntime(8712):     at  android.os.Looper.loop(Looper.java:137)
03-30 07:47:35.921: E/AndroidRuntime(8712):     at android.app.ActivityThread.main(ActivityThread.java:4895)
03-30 07:47:35.921: E/AndroidRuntime(8712):     at java.lang.reflect.Method.invokeNative(Native Method)
03-30 07:47:35.921: E/AndroidRuntime(8712):     at java.lang.reflect.Method.invoke(Method.java:511)
03-30 07:47:35.921: E/AndroidRuntime(8712):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
03-30 07:47:35.921: E/AndroidRuntime(8712):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
03-30 07:47:35.921: E/AndroidRuntime(8712):     at dalvik.system.NativeStart.main(Native Method)
03-30 07:47:35.921: E/AndroidRuntime(8712): Caused by: java.lang.IllegalArgumentException:  you must specify a way to create the tab content
03-30 07:47:35.921: E/AndroidRuntime(8712):     at android.widget.TabHost.addTab(TabHost.java:231)
03-30 07:47:35.921: E/AndroidRuntime(8712):     at com.visionexceed.timeclock.activity.Preferences.onCreate(Preferences.java:35)
03-30 07:47:35.921: E/AndroidRuntime(8712):     at android.app.Activity.performCreate(Activity.java:5163)
03-30 07:47:35.921: E/AndroidRuntime(8712):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
03-30 07:47:35.921: E/AndroidRuntime(8712):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2061)
Was it helpful?

Solution

You cannot embed a third-party activity into your app's UI. At best, you will get the widgets, but nothing will work, because you do not have the permissions that the third-party app has. At worst, you will crash, as you see here.

Please launch WifiManager.ACTION_PICK_WIFI_NETWORK as a regular activity, outside of your tabs.

OTHER TIPS

i have check your code & its working fine in below 4.0 device. check that code without tab in 4.0 device.

because its working in above 4.0 device check this & this links.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top