开发者

Error switching from splash screen to tabs menu, on android

开发者 https://www.devze.com 2023-02-23 23:57 出处:网络
I am stuck... Error: 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.con

I am stuck...

Error:

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 e开发者_如何转开发xception
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)

Main class:

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);
    }
}


Try to declare TabMain activity in your manifest, as it is done with Main.

You have screwed with TabHost layout. YOu tab_main.xml should look like the following:

<?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>

Please, see this article.

And try always to show the actual stacktrace instead of old one.


Declare all the activities in manifest.xml file... like

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号