Note that there are some explanatory texts on larger screens.

plurals
  1. PONullPointerException wit Simple TabActivity
    primarykey
    data
    text
    <p>I'm new to developing for Android and got really excited when I made my first app (and fully understand it or so I thought), but I just can't get it to run. It looks clean to me and I'm not sure what to look for based on the debug information. At least an explanation of what I should look for and why would be very much appreciated. I can provide any additional code you think would be helpful.</p> <p>Thank you.</p> <p>Here is my main Class:</p> <pre>package com.couchcode.realtime; import android.app.TabActivity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.widget.TabHost; import android.widget.TextView; public class Realtime extends TabActivity { TabHost tabHost = getTabHost(); TabHost.TabSpec spec; Intent intent; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); tabHost.getTabWidget().setDividerDrawable(R.drawable.tab_divider); makeTab("test"); } private void makeTab(String tabTag) { intent = new Intent().setClass(this, SearchTab.class); View tabview = createTabView(tabHost.getContext(), tabTag); spec = tabHost.newTabSpec(tabTag).setIndicator(tabview).setContent(intent); tabHost.addTab(spec); tabHost.setCurrentTabByTag(tabTag); } private static View createTabView(final Context context, final String text) { View view = LayoutInflater.from(context).inflate(R.layout.tabs_bg, null); TextView tv = (TextView) view.findViewById(R.id.tabsText); tv.setText(text); return view; } } </pre> <p>And here is the output from logcat while running the debugger:</p> <pre>06-15 07:35:33.447: WARN/dalvikvm(25209): threadid=1: thread exiting with uncaught exception (group=0x401bd560) 06-15 07:35:33.477: ERROR/AndroidRuntime(25209): FATAL EXCEPTION: main 06-15 07:35:33.477: ERROR/AndroidRuntime(25209): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.couchcode.realtime/com.couchcode.realtime.Realtime}: java.lang.NullPointerException 06-15 07:35:33.477: ERROR/AndroidRuntime(25209): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1680) 06-15 07:35:33.477: ERROR/AndroidRuntime(25209): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784) 06-15 07:35:33.477: ERROR/AndroidRuntime(25209): at android.app.ActivityThread.access$1500(ActivityThread.java:123) 06-15 07:35:33.477: ERROR/AndroidRuntime(25209): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939) 06-15 07:35:33.477: ERROR/AndroidRuntime(25209): at android.os.Handler.dispatchMessage(Handler.java:99) 06-15 07:35:33.477: ERROR/AndroidRuntime(25209): at android.os.Looper.loop(Looper.java:130) 06-15 07:35:33.477: ERROR/AndroidRuntime(25209): at android.app.ActivityThread.main(ActivityThread.java:3835) 06-15 07:35:33.477: ERROR/AndroidRuntime(25209): at java.lang.reflect.Method.invokeNative(Native Method) 06-15 07:35:33.477: ERROR/AndroidRuntime(25209): at java.lang.reflect.Method.invoke(Method.java:507) 06-15 07:35:33.477: ERROR/AndroidRuntime(25209): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841) 06-15 07:35:33.477: ERROR/AndroidRuntime(25209): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599) 06-15 07:35:33.477: ERROR/AndroidRuntime(25209): at dalvik.system.NativeStart.main(Native Method) 06-15 07:35:33.477: ERROR/AndroidRuntime(25209): Caused by: java.lang.NullPointerException 06-15 07:35:33.477: ERROR/AndroidRuntime(25209): at android.app.Activity.setContentView(Activity.java:1657) 06-15 07:35:33.477: ERROR/AndroidRuntime(25209): at android.app.TabActivity.ensureTabHost(TabActivity.java:114) 06-15 07:35:33.477: ERROR/AndroidRuntime(25209): at android.app.TabActivity.getTabHost(TabActivity.java:136) 06-15 07:35:33.477: ERROR/AndroidRuntime(25209): at com.couchcode.realtime.Realtime.(Realtime.java:14) 06-15 07:35:33.477: ERROR/AndroidRuntime(25209): at java.lang.Class.newInstanceImpl(Native Method) 06-15 07:35:33.477: ERROR/AndroidRuntime(25209): at java.lang.Class.newInstance(Class.java:1409) 06-15 07:35:33.477: ERROR/AndroidRuntime(25209): at android.app.Instrumentation.newActivity(Instrumentation.java:1021) 06-15 07:35:33.477: ERROR/AndroidRuntime(25209): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1672) 06-15 07:35:33.477: ERROR/AndroidRuntime(25209): ... 11 more </pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload