NPE when drawing TabWidget in android (only on HTC Magic?)
I've received report from the user of an app I've written that he gets FC whenever starting a certain activity. I have not been able to reproduce the issue on the emulator or on my HTC Hero (running 1.5), but this user running HTC Magic (with 1.6) is facing this error every time.
What bothers me is that no single step in the stacktrace actually includes any code in my app (com.filmtipset
)
01-07 00:10:26.773 I/ActivityManager( 141): Starting activity: Intent { cmp=com.filmtipset/.ViewMovie (has extras) }
01-07 00:10:27.023 D/AndroidRuntime( 2402): Shutting down VM
01-07 00:10:27.023 W/dalvikvm( 2402): threadid=3: thread exiting with uncaught exception (group=0x4001e170)
01-07 00:10:27.023 E/AndroidRuntime( 2402): Uncaught handler: thread main exiting due to uncaught exception
01-07 00:10:27.083 E/AndroidRuntime( 2402): java.lang.NullPointerException
01-07 00:10:27.083 E/AndroidRuntime( 2402): at android.widget.TabWidget.dispatchDraw(TabWidget.java:173)
01-07 00:10:27.083 E/AndroidRuntime( 2402): at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
01-07 00:10:27.083 E/AndroidRuntime( 2402): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
01-07 00:10:27.083 E/AndroidRuntime( 2402): at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
01-07 00:10:27.083 E/AndroidRuntime( 2402): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
01-07 00:10:27.083 E/AndroidRuntime( 2402): at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
01-07 00:10:27.083 E/AndroidRuntime( 2402): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
01-07 00:10:27.083 E/AndroidRuntime( 2402): at android.view.View.draw(View.java:6552)
01-07 00:10:27.083 E/AndroidRuntime( 2402): at android.widget.FrameLayout.draw(FrameLayout.java:352)
01-07 00:10:27.083 E/AndroidRuntime( 2402): at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
01-07 00:10:27.083 E/AndroidRuntime( 2402): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
01-07 00:10:27.083 E/AndroidRuntime( 2402): at android.view.View.draw(View.java:6552)
01-07 00:10:27.083 E/AndroidRuntime( 2402): at android.widget.FrameLayout.draw(FrameLayout.java:352)
01-07 00:10:27.083 E/AndroidRuntime( 2402): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1883)
01-07 00:10:27.083 E/AndroidRuntime( 2402): at android.view.ViewRoot.draw(ViewRoot.java:1332)
01-07 00:10:27.083 E/AndroidRuntime( 2402): at android.view.ViewRoot.performTraversals(ViewRoot.java:1097)
01-07 00:10:27.083 E/AndroidRuntime( 2402): at android.view.ViewRoot.handleMessage(ViewRoot.java:1613)
01-07 00:10:27.083 E/AndroidRuntime( 2402): at android.os.Handler.dispatchMessage(Handler.java:99)
01-07 00:10:27.083 E/AndroidRuntime( 2402): at android.os.Looper.loop(Looper.java:123)
01-07 00:10:27.083 E/AndroidRuntime( 2402): at android.app.ActivityThread.main(ActivityThread.java:4320)
01-07 00:10:27.083 E/AndroidRuntime( 2402): at java.lang.reflect.Method.invokeNative(Native Method)
01-07 00:10:27.083 E/AndroidRuntime( 2402): at java.lang.reflect.Method.invoke(Method.java:521)
01-07 00:10:27.083 E/AndroidRuntime( 2402): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
01-07 00:10:27.083 E/AndroidRuntime( 2402): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
01-07 00:10:27.083 E/AndroidRuntime( 2402): at dalvik.system.NativeStart.main(Native Method)
Full dump here if I've missed anything of interest
I'm guessing, then, that there might be something wrong with my layout. It's quite verbose, so I'm posting it here, rather than pasting the whole thing on SO.
There is a tabwidget, where one tab is connected to the scrollview, svFilmInfo
, and one to the linear layout llComments
.
The tab host is populated as such:
Drawable commentSelector = getResources().getDrawable(R.drawable.tabcomment);
Drawable infoSelector = getResources().getDrawable(R.drawable.tabinfo);
mTabHost = getTabHost();
mTabHost.getTabWidget().setBackgroundColor(Color.BLACK);
mTabHost.addTab(mTabHost.newTabSpec("tabInfo").setIndicator("Filminfo", infoSelector).setContent(R.id.svFilmInfo));
mTabHost.addTab(mTabHost.newTabSpec("tabInfo").setIndicator("Kommentarer", commentSelector).setContent(R.id.llComments));
Since I cannot reproduce the error myself, and since I cannot find any mention in the stack trace of what might be causing the error, I don't quite know where to start troubleshooting this.
I'd appreciate any pointers.
Asked by: Dainton595 | Posted: 24-01-2022
Answer 1
I run into stack traces like that when people have a TabHost
in their layout but do not add TabSpecs
to it. You show the code where you add tabs -- are you sure that is being called in all circumstances?
Answer 2
I got the same error in my application, but only on Android 1.6 and higher - it worked on 1.5.
The reason: initial application Activity extended TabActivity but layout XML with TabHost widget was not loaded via setContentView() in onCreate() scope (it was scheduled to load via Runnable a little bit later).
Then first try to actually draw such not-fully-processed TabActivity on screen caused crash with NullPointerException at android.widget.TabWidget.dispatchDraw(TabWidget.java:173)
You have to load XML or instantiate TabHost and fill with newTabSpecs programatically before onCreate ends.
Answered by: Tara451 | Posted: 25-02-2022Similar questions
android - TabWidget NullpointerException?
I am trying to create a tab widget with two tabs to open two different activities and written following layout to achieve this but it is giving me a NullPointerException.
Where is my mistake?
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabhost"
android:layout_width="fill_parent"
and...
Running an Android App in Eclipse Causes NullPointerException
I have been following the Android getting started docs and when I try to run the project I get:
!MESSAGE An internal error occurred during: "Launching HelloAndroid".
!STACK 0
java.lang.NullPointerException
at com.android.ide.eclipse.adt.internal.launch.AndroidLaunchController.launch(Unknown Source)
NullPointerException while building android app using ant
While building the android app using ant am getting the following exception.
Couldn't figure out why these exception are thrown!!!
Execute:Java13CommandLauncher: Executing 'D:\Android-2.0\android-sdk-windows\platforms\android-1.5\tools\aapt.exe' with arguments:
'package'
'-f'
'-M'
'E:\manish_test\timetrack\client\static\android\AndroidManifest.xml'
'-S'
'E:\manish_test\timetrack\client\static\android\res'...
android - TabWidget NullpointerException?
I am trying to create a tab widget with two tabs to open two different activities and written following layout to achieve this but it is giving me a NullPointerException.
Where is my mistake?
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabhost"
android:layout_width="fill_parent"
and...
Problem running android HelloTabWidget example - NullPointerException on addTab()
I've tried the Tab Layout example, and I've also fixed the few typos in the example (and added all the activities to the manifest). However, when I run it on the emulator I get a NullPointerException on the first line that says
tabHost.addTab(spec);
So my question...
java - Receiving a NullPointerException when calling a cursor in Android
I am creating an application which tracks the users location using GPS, stores the longitude and latitude in a database using a content provider then output the first long and lat to a mapview.
I am able to create the cursor using this line of code:
Cursor c = getContentResolver().query(GPSContentProvider.CONTENT_URI,
null, null, null, null);
s...
installation - NullPointerException when installing the Android SDK on Mac OS X
I'm installing the Android SDK on Mac OS X. Following the instructions on the Android Development site, I've downloaded the SDK and modified my .bash_profile to include the path. The next step is to use the Android SDK and AVD Manager to actually download the platforms.
However, when I use the Manager to install the platforms, I get the following error in the Terminal. I've looked around for similar problems in th...
android - TabHost NullPointerException in layout
I been following the Tab example provided by Google. I am trying to use the XML layout provided to setup a tab layout.
I use this XML layout @ http://developer.android.com/guide/tutorials/views/hello-tabwidget.html
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="htt...
android - Cannot understand NullPointerException with custom adapter
I am trying to create a list view which as TextView that can display html content , an WebView and other basic TextViews.I tried to extend SimpleAdapter but i struck with the problem ,I will be glad if someone can point out the mistake i am doing.
In onCreate method
ArrayList<HashMap<String, String>> mylist= resultfromXmlparser();
adap = new MyAdapter(TourLandingPage.this, mylist, R.l...
android - Nullpointerexception getSystemService
Following line will only not result in a nullpointer exception if I'm connected to a WLAN:
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
Otherwise I get a nullpointer-exception straight ahead? How can I fix this? I want my background service to only work, when it is connected to wlan. But that Nullpointerexception just kills the whole app......
NullPointerException when trying to connect to web service using kSoap method Android
My web service should be returning an integer, but every time i run the code i get the NullPointerException error.
Any ideas or help would be very appreciated
Here's my code:
public class CGCountTest extends Activity {
TextView testTV;
private static final String NAMESPACE = "http://passport-america.com/webservices/";
private static final String URL = "http://localhost:11746/Service1.a...
Still can't find your answer? Check out these communities...
Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android