3

I am trying to generate a custom tabView in android

AndroidTabRestaurantDescListView.java

public class AndroidTabRestaurantDescListView extends TabActivity {
    // TabSpec Names
        private static final String INBOX_SPEC = "Rating";
        private static final String OUTBOX_SPEC = "Price";
        private static final String PROFILE_SPEC = "Distance";
        private TabHost Photos;

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            Photos=(TabHost) findViewById(R.id.PhotoButton); 
            TabHost tabHost = getTabHost();
            Photos.getTabWidget().setDividerDrawable(R.drawable.tab_divider);

            // Inbox Tab
            TabSpec inboxSpec = tabHost.newTabSpec(INBOX_SPEC);
            Intent inboxIntent = new Intent(this, MainActivity.class);
            inboxSpec.setIndicator(INBOX_SPEC);
            // Tab Content
            inboxSpec.setContent(inboxIntent);

            // Outbox Tab
            TabSpec PriceSpec = tabHost.newTabSpec(OUTBOX_SPEC);
            Intent PriceIntent = new Intent(this, PriceDescriptionActivity.class);
            PriceSpec .setIndicator(OUTBOX_SPEC);
            PriceSpec.setContent(PriceIntent);

            // Profile Tab
            TabSpec DistanceSpec = tabHost.newTabSpec(PROFILE_SPEC);
            Intent DistanceIntent = new Intent(this, DistanceDiscriptionActivity.class);
            DistanceSpec .setIndicator(PROFILE_SPEC); 
            DistanceSpec.setContent(DistanceIntent);

            // Adding all TabSpec to TabHost
            tabHost.addTab(inboxSpec); 
            tabHost.addTab(PriceSpec); 
            tabHost.addTab(DistanceSpec); 

            //Set the current value tab to default first tab
            tabHost.setCurrentTab(0);

            //Setting custom height for the tabs
            final int height = 45;
            tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = height;
            tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = height;
            tabHost.getTabWidget().getChildAt(2).getLayoutParams().height = height;

            Photos.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    Intent PhotoIntent = new Intent(AndroidTabRestaurantDescListView.this, AndroidTabRestaurantDescImageListView.class);
                    startActivity(PhotoIntent);             
                }
            });
        }
}

Log::

10-03 18:49:34.710: D/AndroidRuntime(561): Shutting down VM
10-03 18:49:34.710: W/dalvikvm(561): threadid=1: thread exiting with uncaught exception (group=0x40015560)
10-03 18:49:34.740: E/AndroidRuntime(561): FATAL EXCEPTION: main
10-03 18:49:34.740: E/AndroidRuntime(561): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androidbegin.jsonparsetutorial/com.project.findmybuffet.AndroidTabRestaurantDescListView}: java.lang.ClassCastException: android.widget.Button
10-03 18:49:34.740: E/AndroidRuntime(561):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
10-03 18:49:34.740: E/AndroidRuntime(561):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
10-03 18:49:34.740: E/AndroidRuntime(561):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
10-03 18:49:34.740: E/AndroidRuntime(561):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
10-03 18:49:34.740: E/AndroidRuntime(561):  at android.os.Handler.dispatchMessage(Handler.java:99)
10-03 18:49:34.740: E/AndroidRuntime(561):  at android.os.Looper.loop(Looper.java:123)
10-03 18:49:34.740: E/AndroidRuntime(561):  at android.app.ActivityThread.main(ActivityThread.java:3683)
10-03 18:49:34.740: E/AndroidRuntime(561):  at java.lang.reflect.Method.invokeNative(Native Method)
10-03 18:49:34.740: E/AndroidRuntime(561):  at java.lang.reflect.Method.invoke(Method.java:507)
10-03 18:49:34.740: E/AndroidRuntime(561):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-03 18:49:34.740: E/AndroidRuntime(561):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-03 18:49:34.740: E/AndroidRuntime(561):  at dalvik.system.NativeStart.main(Native Method)
10-03 18:49:34.740: E/AndroidRuntime(561): Caused by: java.lang.ClassCastException: android.widget.Button
10-03 18:49:34.740: E/AndroidRuntime(561):  at com.project.findmybuffet.AndroidTabRestaurantDescListView.onCreate(AndroidTabRestaurantDescListView.java:27)
10-03 18:49:34.740: E/AndroidRuntime(561):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-03 18:49:34.740: E/AndroidRuntime(561):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
10-03 18:49:34.740: E/AndroidRuntime(561):  ... 11 more

Any inputs to resolve this Thanks

4

1 に答える 1

3

問題は次の行にあります。

Photos=(TabHost) findViewById(R.id.PhotoButton);

R.id.PhotoButton私はそれが であると仮定しButton、あなたはそれを にキャストしようとしてTabHostいますが、これはできません。

基本的にすべてがログに表示されます。次の 2 行が最も関連性があります。

10-03 18:49:34.740: E/AndroidRuntime(561): Caused by: java.lang.ClassCastException: android.widget.Button
10-03 18:49:34.740: E/AndroidRuntime(561):  at com.project.findmybuffet.AndroidTabRestaurantDescListView.onCreate(AndroidTabRestaurantDescListView.java:27)
于 2013-10-03T13:40:13.927 に答える