[android-developers] Re: Encountered NullPointerException. Could anyone give me a hand ?Thanks

2010-11-22 Thread pramod.deore
Hi Shawn_Chiu,

you had not override onCreate() method of HelloTabActivity class.
override it as

 public void onCreate(Bundle savedInstanceState)
{
  super.onCreate (savedInstanceState);
   }

your activity is extending from TabActivity, so remove line
setContentView(R.layout.main); from onCreate () method.



On Nov 23, 6:50 am, Shawn_Chiu  wrote:
> Hi, all
>   I encountered an excepiton when I used TabActivity. Each tab content
> is a seperate activity.
> Could anyone give me a hand ?Thanks :-)
>
> The exception stack trace is as follow:
> -
> Thread [<3> main] (Suspended (exception NullPointerException))
>         TabHost.dispatchWindowFocusChanged(boolean) line: 295
>         FrameLayout(ViewGroup).dispatchWindowFocusChanged(boolean) line: 661
>         LinearLayout(ViewGroup).dispatchWindowFocusChanged(boolean) line:
> 661
>         PhoneWindow$DecorView(ViewGroup).dispatchWindowFocusChanged(boolean)
> line: 661
>         ViewRoot.handleMessage(Message) line: 1819
>         ViewRoot(Handler).dispatchMessage(Message) line: 99
>         Looper.loop() line: 123
>         ActivityThread.main(String[]) line: 4363
>         Method.invokeNative(Object, Object[], Class, Class[], Class, int,
> boolean) line: not available [native method]
>         Method.invoke(Object, Object...) line: 521
>         ZygoteInit$MethodAndArgsCaller.run() line: 860
>         ZygoteInit.main(String[]) line: 618
>         NativeStart.main(String[]) line: not available [native method]
> -
>
> layout/main.xml
> -
> 
> http://schemas.android.com/apk/res/android";
>         android:id="@+id/tabhost"
>         android:layout_width="fill_parent"
>         android:layout_height="fill_parent"
>         android:layout_weight="1">
>
>              android:layout_width="fill_parent"
>         android:layout_height="wrap_content"/>
>
>              android:layout_width="fill_parent"
>         android:layout_height="wrap_content"
>         android:paddingTop="64dip">
>     
> 
> -
> strings.xml
> 
> 
> 
>     Hello World, HelloTabActivity!
>     HelloTabWidget
>     song
>     album
>     acc
> 
> ---
>
> classes are placed into com.qiu.test package.
>
> HelloTabActivity.java
> --
> package com.qiu.test;
>
> import android.app.Activity;
> import android.app.TabActivity;
> import android.content.Intent;
> import android.content.res.Resources;
> import android.os.Bundle;
> import android.widget.ScrollView;
> import android.widget.TabHost;
>
> public class HelloTabActivity extends TabActivity {
>         protected TabHost tabs;
>
>     protected void OnCreate (Bundle bundle)
>     {
>         super.onCreate (bundle);
>         setContentView(R.layout.main);
>
>         tabs = getTabHost();
>
>         Resources res = getResources();
>
>         TabHost.TabSpec syncTabSpec = tabs.newTabSpec("sync");
>         syncTabSpec.setContent (new Intent (this,
> SongActivity.class));
>         syncTabSpec.setIndicator("sync");
>         tabs.addTab(syncTabSpec);
>
>         TabHost.TabSpec accTabSpec = tabs.newTabSpec("acc");
>         accTabSpec.setContent (new Intent (this,
> AlbumsActivity.class));
>         accTabSpec.setIndicator("acc");
>         tabs.addTab(accTabSpec);
>
>         tabs.setCurrentTab(0);
>     }}
>
> --
>
> SongActivity.java
> --
> package com.qiu.test;
>
> import android.app.Activity;
> import android.os.Bundle;
> import android.widget.TextView;
>
> public class SongActivity extends Activity {
>
>         public void onCreate (Bundle savedInstanceState)
>         {
>             super.onCreate (savedInstanceState);
>
>             TextView textview = new TextView (this);
>             textview.setText("This is the song tab");
>             setContentView (textview);
>         }}
>
> 
> AlbumsActivity.java
> --
> package com.qiu.test

[android-developers] Re: Encountered NullPointerException. Could anyone give me a hand ?Thanks

2010-11-22 Thread pramod.deore

Hi Shawn_Chiu,

You have not override onCreate method in HelloTabActivity class
correctly.
override it as

@Override
public void onCreate(Bundle savedInstanceState)
{
  super.onCreate (savedInstanceState);
}

And remove statement
super.onCreate (savedInstanceState);
Because your activity is extending from TabActivity.

and try to run program.

On Nov 23, 6:50 am, Shawn_Chiu  wrote:
> Hi, all
>   I encountered an excepiton when I used TabActivity. Each tab content
> is a seperate activity.
> Could anyone give me a hand ?Thanks :-)
>
> The exception stack trace is as follow:
> -
> Thread [<3> main] (Suspended (exception NullPointerException))
>         TabHost.dispatchWindowFocusChanged(boolean) line: 295
>         FrameLayout(ViewGroup).dispatchWindowFocusChanged(boolean) line: 661
>         LinearLayout(ViewGroup).dispatchWindowFocusChanged(boolean) line:
> 661
>         PhoneWindow$DecorView(ViewGroup).dispatchWindowFocusChanged(boolean)
> line: 661
>         ViewRoot.handleMessage(Message) line: 1819
>         ViewRoot(Handler).dispatchMessage(Message) line: 99
>         Looper.loop() line: 123
>         ActivityThread.main(String[]) line: 4363
>         Method.invokeNative(Object, Object[], Class, Class[], Class, int,
> boolean) line: not available [native method]
>         Method.invoke(Object, Object...) line: 521
>         ZygoteInit$MethodAndArgsCaller.run() line: 860
>         ZygoteInit.main(String[]) line: 618
>         NativeStart.main(String[]) line: not available [native method]
> -
>
> layout/main.xml
> -
> 
> http://schemas.android.com/apk/res/android";
>         android:id="@+id/tabhost"
>         android:layout_width="fill_parent"
>         android:layout_height="fill_parent"
>         android:layout_weight="1">
>
>              android:layout_width="fill_parent"
>         android:layout_height="wrap_content"/>
>
>              android:layout_width="fill_parent"
>         android:layout_height="wrap_content"
>         android:paddingTop="64dip">
>     
> 
> -
> strings.xml
> 
> 
> 
>     Hello World, HelloTabActivity!
>     HelloTabWidget
>     song
>     album
>     acc
> 
> ---
>
> classes are placed into com.qiu.test package.
>
> HelloTabActivity.java
> --
> package com.qiu.test;
>
> import android.app.Activity;
> import android.app.TabActivity;
> import android.content.Intent;
> import android.content.res.Resources;
> import android.os.Bundle;
> import android.widget.ScrollView;
> import android.widget.TabHost;
>
> public class HelloTabActivity extends TabActivity {
>         protected TabHost tabs;
>
>     protected void OnCreate (Bundle bundle)
>     {
>         super.onCreate (bundle);
>         setContentView(R.layout.main);
>
>         tabs = getTabHost();
>
>         Resources res = getResources();
>
>         TabHost.TabSpec syncTabSpec = tabs.newTabSpec("sync");
>         syncTabSpec.setContent (new Intent (this,
> SongActivity.class));
>         syncTabSpec.setIndicator("sync");
>         tabs.addTab(syncTabSpec);
>
>         TabHost.TabSpec accTabSpec = tabs.newTabSpec("acc");
>         accTabSpec.setContent (new Intent (this,
> AlbumsActivity.class));
>         accTabSpec.setIndicator("acc");
>         tabs.addTab(accTabSpec);
>
>         tabs.setCurrentTab(0);
>     }}
>
> --
>
> SongActivity.java
> --
> package com.qiu.test;
>
> import android.app.Activity;
> import android.os.Bundle;
> import android.widget.TextView;
>
> public class SongActivity extends Activity {
>
>         public void onCreate (Bundle savedInstanceState)
>         {
>             super.onCreate (savedInstanceState);
>
>             TextView textview = new TextView (this);
>             textview.setText("This is the song tab");
>             setContentView (textview);
>         }}
>
> 
> AlbumsActivity.java
> ---