- Forum posts: 17
Nov 26, 2014, 8:24:13 AM via Website
Nov 26, 2014 8:24:13 AM via Website
Hi friends,
Here is my code for tab view in my application.
My problem is when this activity starts the app force closes.
Please help me to sort out the issue
Java
package info.androidhive.slidingmenu.Tulip;
import info.androidhive.slidingmenu.Projects;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
@SuppressWarnings("deprecation")
public class Tulip extends TabActivity{
static TabHost tabHost;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tulip);
setTab();
}
public void setTab(){
addTab("Overview", R.drawable.overview_tab, Projects.class);
addTab("Location Map", R.drawable.locationmap_tab, Projects.class);
addTab("Amenities", R.drawable.amenities_tab, Projects.class);
addTab("Specifications", R.drawable.specifications_tab, Projects.class);
addTab("Plans", R.drawable.plans_tab, Projects.class);
addTab("Apartment Plans", R.drawable.apartment_plans, Projects.class);
addTab("E-brochure", R.drawable.ebrochure_tab, Projects.class);
}
private void addTab(String labelId, int drawableId, Class<?> c)
{
tabHost = getTabHost();
Intent intent = new Intent(this, c);
TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId);
View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false);
ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
icon.setImageResource(drawableId);
spec.setIndicator(tabIndicator);
spec.setContent(intent);
tabHost.addTab(spec);
}
}
XML
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
/>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:tabStripEnabled="false"
android:gravity="center"
android:layout_weight="0" />
</LinearLayout>
Log cat
11-26 07:20:47.863: D/OpenGLRenderer(996): TextureCache::get: create texture(0xb78978a8): name, size, mSize = 55, 900, 2599480
11-26 07:20:49.435: D/AndroidRuntime(996): Shutting down VM
11-26 07:20:49.435: W/dalvikvm(996): threadid=1: thread exiting with uncaught exception (group=0xa62d2288)
11-26 07:20:49.439: E/AndroidRuntime(996): FATAL EXCEPTION: main
11-26 07:20:49.439: E/AndroidRuntime(996): java.lang.RuntimeException: Unable to start activity ComponentInfo{info.androidhive.CrescentBuilders/info.androidhive.slidingmenu.Tulip.Tulip}: java.lang.RuntimeException: Unable to start activity ComponentInfo{info.androidhive.CrescentBuilders/info.androidhive.slidingmenu.Projects}: java.lang.NullPointerException
11-26 07:20:49.439: E/AndroidRuntime(996): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
11-26 07:20:49.439: E/AndroidRuntime(996): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
11-26 07:20:49.439: E/AndroidRuntime(996): at android.app.ActivityThread.access$600(ActivityThread.java:130)
11-26 07:20:49.439: E/AndroidRuntime(996): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
11-26 07:20:49.439: E/AndroidRuntime(996): at android.os.Handler.dispatchMessage(Handler.java:99)
11-26 07:20:49.439: E/AndroidRuntime(996): at android.os.Looper.loop(Looper.java:137)
11-26 07:20:49.439: E/AndroidRuntime(996): at android.app.ActivityThread.main(ActivityThread.java:4745)
11-26 07:20:49.439: E/AndroidRuntime(996): at java.lang.reflect.Method.invokeNative(Native Method)
11-26 07:20:49.439: E/AndroidRuntime(996): at java.lang.reflect.Method.invoke(Method.java:511)
11-26 07:20:49.439: E/AndroidRuntime(996): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-26 07:20:49.439: E/AndroidRuntime(996): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-26 07:20:49.439: E/AndroidRuntime(996): at dalvik.system.NativeStart.main(Native Method)
11-26 07:20:49.439: E/AndroidRuntime(996): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{info.androidhive.CrescentBuilders/info.androidhive.slidingmenu.Projects}: java.lang.NullPointerException
11-26 07:20:49.439: E/AndroidRuntime(996): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
11-26 07:20:49.439: E/AndroidRuntime(996): at android.app.ActivityThread.startActivityNow(ActivityThread.java:1900)
11-26 07:20:49.439: E/AndroidRuntime(996): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)
11-26 07:20:49.439: E/AndroidRuntime(996): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:347)
11-26 07:20:49.439: E/AndroidRuntime(996): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:694)
11-26 07:20:49.439: E/AndroidRuntime(996): at android.widget.TabHost.setCurrentTab(TabHost.java:358)
11-26 07:20:49.439: E/AndroidRuntime(996): at android.widget.TabHost.addTab(TabHost.java:236)
11-26 07:20:49.439: E/AndroidRuntime(996): at info.androidhive.slidingmenu.Tulip.Tulip.addTab(Tulip.java:47)
11-26 07:20:49.439: E/AndroidRuntime(996): at info.androidhive.slidingmenu.Tulip.Tulip.setTab(Tulip.java:28)
11-26 07:20:49.439: E/AndroidRuntime(996): at info.androidhive.slidingmenu.Tulip.Tulip.onCreate(Tulip.java:23)
11-26 07:20:49.439: E/AndroidRuntime(996): at android.app.Activity.performCreate(Activity.java:5008)
11-26 07:20:49.439: E/AndroidRuntime(996): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
11-26 07:20:49.439: E/AndroidRuntime(996): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
11-26 07:20:49.439: E/AndroidRuntime(996): ... 11 more
11-26 07:20:49.439: E/AndroidRuntime(996): Caused by: java.lang.NullPointerException
11-26 07:20:49.439: E/AndroidRuntime(996): at info.androidhive.slidingmenu.Projects.onCreate(Projects.java:31)
11-26 07:20:49.439: E/AndroidRuntime(996): at android.app.Activity.performCreate(Activity.java:5008)
11-26 07:20:49.439: E/AndroidRuntime(996): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
11-26 07:20:49.439: E/AndroidRuntime(996): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
11-26 07:20:49.439: E/AndroidRuntime(996): ... 23 more
11-26 07:20:50.567: I/Process(996): Sending signal. PID: 996 SIG: 9
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.