在android上从错误切换到标签菜单时出错

时间:2011-04-11 12:38:08

标签: android splash-screen

我被卡住了......

错误:

04-11 14:30:11.606: ERROR/AndroidRuntime(1012): Uncaught handler: thread Thread-8 exiting due to uncaught exception 04-11 14:30:11.616: ERROR/AndroidRuntime(1012): android.content.ActivityNotFoundException: Unable to find explicit activity class {mapa.montenegro/mapa.montenegro.TabMain}; have you declared this activity in your AndroidManifest.xml?
04-11 14:30:11.616: ERROR/AndroidRuntime(1012):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
04-11 14:30:11.616: ERROR/AndroidRuntime(1012):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
04-11 14:30:11.616: ERROR/AndroidRuntime(1012):     at android.app.Activity.startActivityForResult(Activity.java:2749)
04-11 14:30:11.616: ERROR/AndroidRuntime(1012):     at android.app.Activity.startActivity(Activity.java:2855)
04-11 14:30:11.616: ERROR/AndroidRuntime(1012):     at mapa.montenegro.Main$1.run(Main.java:49)
04-11 14:30:11.606: ERROR/AndroidRuntime(1012): Uncaught handler: thread Thread-8 exiting due to uncaught exception
04-11 14:30:11.616: ERROR/AndroidRuntime(1012): android.content.ActivityNotFoundException: Unable to find explicit activity class {mapa.montenegro/mapa.montenegro.TabMain}; have you declared this activity in your AndroidManifest.xml?
04-11 14:30:11.616: ERROR/AndroidRuntime(1012):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
04-11 14:30:11.616: ERROR/AndroidRuntime(1012):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
04-11 14:30:11.616: ERROR/AndroidRuntime(1012):     at android.app.Activity.startActivityForResult(Activity.java:2749)
04-11 14:30:11.616: ERROR/AndroidRuntime(1012):     at android.app.Activity.startActivity(Activity.java:2855)
04-11 14:30:11.616: ERROR/AndroidRuntime(1012):     at mapa.montenegro.Main$1.run(Main.java:49)

主要课程:

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;

public class Main extends Activity {
    //some properties..     
    boolean _active = true;
    // time to display the splash screen in ms
    int _splashTime = 3000; 

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // thread for displaying the SplashScreen
        Thread splashTread = new Thread() {
            @Override
            public void run() {
                try {
                    int waited = 0;
                    while(_active && (waited < _splashTime)) {
                        sleep(100);
                        if(_active) {
                            waited += 100;
                        }
                    }
                } catch(InterruptedException e) {
                    // print error
                    Log.v("InterruptedException", e.toString());
                } finally {
                    //finish                    
                    finish();

                    //print
                    Log.v("splashTread", "Finished");

                    //start new activity
                    // Here we start the next activity, and then call finish()
                    // so that our own will stop running and be removed from the
                    // history stack.
                    Intent intent = new Intent();
                    intent.setClass(Main.this, TabMain.class); // here starts error
                    startActivity(intent);
                    finish();                   
                }
            }
        };
        splashTread.start();
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        // TODO Auto-generated method stub
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            _active = false;
        }
        //trurn default value
        return true;
    }
}

// tab main classs

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class TabMain extends TabActivity{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

        //tabhost
        TabHost tabHostMain=(TabHost) findViewById(R.layout.tab_main);

        /**
         * TabSpec used to create a new tab. By using TabSpec only we can able
         * to setContent to the tab. By using TabSpec setIndicator() we can set
         * name to tab.
         */

        /** tid1 is firstTabSpec Id. Its used to access outside. */
        TabSpec mapTabSpec = tabHostMain.newTabSpec("tid1");
        TabSpec settingsTabSpec = tabHostMain.newTabSpec("tid1");
        TabSpec homeTabSpec = tabHostMain.newTabSpec("tid1");

        /** TabSpec setIndicator() is used to set name for the tab. */
        /** TabSpec setContent() is used to set content for a particular tab. */
        mapTabSpec.setIndicator("Map Tab Name",getResources().getDrawable(R.drawable.ico_map)).setContent(
                new Intent(this, TabMap.class));
        settingsTabSpec.setIndicator("Settigs Tab Name", getResources().getDrawable(R.drawable.ico_settings)).setContent(
                new Intent(this, TabSettings.class));
        homeTabSpec.setIndicator("Home Tab Name", getResources().getDrawable(R.drawable.ico_home)).setContent(
                new Intent(this, TabHome.class));

        /** Add tabSpec to the TabHost to display. */
        tabHostMain.addTab(mapTabSpec);
        tabHostMain.addTab(settingsTabSpec);
        tabHostMain.addTab(homeTabSpec);
    }
}

2 个答案:

答案 0 :(得分:1)

尝试在清单中声明TabMain活动,就像使用Main一样。

你已经搞砸了TabHost布局。你的tab_main.xml应该如下所示:

<?xml version="1.0" encoding="utf-8"?>
<TabHost
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@android:id/tabhost"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
    <TabWidget android:id="@android:id/tabs"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"/>
              <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:padding="5dp">
                    <FrameLayout
                        android:id="@android:id/tabcontent"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:padding="5dp" />
                </LinearLayout>
</TabHost>

请参阅此article

并尝试始终显示实际的堆栈跟踪而不是旧堆栈跟踪。

答案 1 :(得分:0)

声明manifest.xml文件中的所有活动......比如

<activity android:name=".ActivityName"
                  android:label="@string/app_name">
        </activity>