NullPointerException

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

NullPointerException

Postby mr_muskuraha » Wed Feb 17, 2010 4:36 pm

dear friends,

i am using following layout to display tabs in my acitivity when click layout tab to check its design
it gives me nullpointerexception and same is the case when i run it. please help me out to solve this issue.

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
  4.  
  5.    android:id="@+id/tabhost"
  6.  
  7.    android:layout_width="fill_parent"
  8.  
  9.    android:layout_height="fill_parent">
  10.  
  11.     <LinearLayout
  12.  
  13.        android:orientation="vertical"
  14.  
  15.        android:layout_width="fill_parent"
  16.  
  17.        android:layout_height="fill_parent">
  18.  
  19.         <TabWidget
  20.  
  21.            android:id="@android:id/tabs"
  22.  
  23.            android:layout_width="fill_parent"
  24.  
  25.            android:layout_height="wrap_content" />
  26.  
  27.         <FrameLayout
  28.  
  29.            android:id="@android:id/tabcontent"
  30.  
  31.            android:layout_width="fill_parent"
  32.  
  33.            android:layout_height="fill_parent">
  34.  
  35.      
  36.  
  37.         </FrameLayout>
  38.  
  39.         </LinearLayout>
  40.  
  41. </TabHost>
Parsed in 0.003 seconds, using GeSHi 1.0.8.4
mr_muskuraha
Senior Developer
Senior Developer
 
Posts: 142
Joined: Wed Jan 13, 2010 8:49 am

Top

Postby padde » Wed Feb 17, 2010 9:34 pm

Since when nullpointerexecptions hiding in XML code?!
We need the java code... the XML isnt helping @ all.
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

java code

Postby mr_muskuraha » Thu Feb 18, 2010 7:00 am

setContentView(R.layout.more);

TabHost mTabHost = (TabHost) this.findViewById(R.id.tabhost);
mTabHost.setup();

Intent intent;

intent = new Intent().setClass(this, Settings.class);
mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator(
"Calculator",
getResources().getDrawable(R.drawable.tab01)).setContent(intent));

intent = new Intent().setClass(this, Post.class);
mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator(
"YouTube",
getResources().getDrawable(R.drawable.tab02)).setContent(intent));
mr_muskuraha
Senior Developer
Senior Developer
 
Posts: 142
Joined: Wed Jan 13, 2010 8:49 am

Postby padde » Thu Feb 18, 2010 10:11 am

Even its hard to read.. it looks fine to me. In which line the error gets thrown?!
And please post the complete error message.. maybe there are more hints about
what is null.
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Postby mr_muskuraha » Fri Feb 19, 2010 7:12 am

solved the problem


actually the problem was in my layout file.


in tabactivity you must use id like "@android:id/tabhost" instead of "="@+id/tabhost"

thats why i was getting null pointer exception while assigning layout in activity.
mr_muskuraha
Senior Developer
Senior Developer
 
Posts: 142
Joined: Wed Jan 13, 2010 8:49 am

Postby padde » Fri Feb 19, 2010 8:29 am

good to know.. thanks.
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Google Feedfetcher and 7 guests