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 <qiuping...@gmail.com> 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
> -------------------------------------------------------------------------------------------------------------
> <?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"
>         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"/>
>
>     <FrameLayout android:id="@android:id/tabcontent"
>         android:layout_width="fill_parent"
>         android:layout_height="wrap_content"
>         android:paddingTop="64dip">
>     </FrameLayout>
> </TabHost>
> -------------------------------------------------------------------------------------------------------------
> strings.xml
> ------------------------------------------------------------------------------------------------------------
> <?xml version="1.0" encoding="utf-8"?>
> <resources>
>     <string name="hello">Hello World, HelloTabActivity!</string>
>     <string name="app_name">HelloTabWidget</string>
>     <string name="song">song</string>
>     <string name="album">album</string>
>     <string name="acc">acc</string>
> </resources>
> -----------------------------------------------------------------------------------------------------------
>
> 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;
>
> import android.app.Activity;
> import android.os.Bundle;
> import android.widget.TextView;
>
> public class AlbumsActivity extends Activity {
>
>         public void onCreate (Bundle savedInstanceState)
>         {
>             super.onCreate (savedInstanceState);
>
>             TextView textview = new TextView (this);
>             textview.setText("This is the albumns tab");
>             setContentView (textview);
>         }}
>
> -----------------------------------------------------------------------------------------------------------------

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to