Android 选项卡和映射V2,错误:无法实例化活动组件信息

Android 选项卡和映射V2,错误:无法实例化活动组件信息,android,Android,我已经阅读了其他人的问题和答案,我似乎找不到我的答案,所以我将发布我的main.java活动页面和我的android清单文件,如果你看到我做错了什么,请告诉我。记住,eclipse不会显示错误;当我尝试通过emulator来运行它时,它没有通过,并且无法在主活动上实例化活动组件的错误显示在我的日志cat上。谢谢大家! 1) main.java: package com.arthur.sos; import android.support.v4.app.Fragment; import jav

我已经阅读了其他人的问题和答案,我似乎找不到我的答案,所以我将发布我的main.java活动页面和我的android清单文件,如果你看到我做错了什么,请告诉我。记住,eclipse不会显示错误;当我尝试通过emulator来运行它时,它没有通过,并且无法在主活动上实例化活动组件的错误显示在我的日志cat上。谢谢大家!

1) main.java:

package com.arthur.sos;


import android.support.v4.app.Fragment;
import java.util.HashMap;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.TabHost;
import android.widget.TabHost.TabContentFactory;

import com.arthur.sos.R;


public class Main extends FragmentActivity implements TabHost.OnTabChangeListener {

    private TabHost mTabHost;
    private HashMap<String,Object> mapTabInfo = new HashMap<String,Object>();
    private TabInfo mLastTab = null;

    private class TabInfo {
         private String tag;
         @SuppressWarnings("rawtypes")
        private Class clss;
         private Bundle args;
         private android.support.v4.app.Fragment fragment;
         TabInfo(String tag, @SuppressWarnings("rawtypes") Class clazz, Bundle args) {
             this.tag = tag;
             this.clss = clazz;
             this.args = args;
         }

    }

    class TabFactory implements TabContentFactory {

        private final Context mContext;

        /**
         * @param context
         */
        public TabFactory(Context context) {
            mContext = context;
        }

        /** 
         * @see android.widget.TabHost.TabContentFactory#createTabContent(java.lang.String)
         */
        public View createTabContent(String tag) {
            View v = new View(mContext);
            v.setMinimumWidth(0);
            v.setMinimumHeight(0);
            return v;
        }

    }
    /** 
     * @see android.support.v4.app.FragmentActivity#onCreate(android.os.Bundle)
     */
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Step 1: Inflate layout
        setContentView(R.layout.tabs_layout);
        // Step 2: Setup TabHost
        initialiseTabHost(savedInstanceState);
        if (savedInstanceState != null) {
            mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab")); //set the tab as per the saved state
        }
    }

    /** 
     * @see android.support.v4.app.FragmentActivity#onSaveInstanceState(android.os.Bundle)
     */
    protected void onSaveInstanceState(Bundle outState) {
        outState.putString("tab", mTabHost.getCurrentTabTag()); //save the tab selected
        super.onSaveInstanceState(outState);
    }

    /**
     * Step 2: Setup TabHost
     */
    private void initialiseTabHost(Bundle args) {
        mTabHost = (TabHost)findViewById(android.R.id.tabhost);
        mTabHost.setup();
        TabInfo tabInfo = null;
        //This tab is for Vendor Maps, please note .setIndicator is purposely left blank. 
        Main.addTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab1").setIndicator("",getResources().getDrawable(R.drawable.map)), ( tabInfo = new TabInfo("Tab1", vendormaps.class, args)));
        this.mapTabInfo.put(tabInfo.tag, tabInfo);

        //This tab is for Reviews, please note .setIndicator is purposely left blank. 
        Main.addTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab2").setIndicator("",getResources().getDrawable(R.drawable.reviews)), ( tabInfo = new TabInfo("Tab2", reviews.class, args)));
        this.mapTabInfo.put(tabInfo.tag, tabInfo);

        //This tab is for Settings, please note .setIndicator is purposely left blank. 
        Main.addTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab3").setIndicator("",getResources().getDrawable(R.drawable.settings)), ( tabInfo = new TabInfo("Tab3", settings.class, args)));
        this.mapTabInfo.put(tabInfo.tag, tabInfo);

        //This tab is for My Account, please note .setIndicator is purposely left blank. 
        Main.addTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab4").setIndicator("",getResources().getDrawable(R.drawable.myaccount)), ( tabInfo = new TabInfo("Tab4", myaccount.class, args)));
        this.mapTabInfo.put(tabInfo.tag, tabInfo);


        // Default to first tab
        this.onTabChanged("Tab1");
        //
        mTabHost.setOnTabChangedListener(this);
    }

    /**
     * @param activity
     * @param tabHost
     * @param tabSpec
     * @param clss
     * @param args
     */
    private static void addTab(Main activity, TabHost tabHost, TabHost.TabSpec tabSpec, TabInfo tabInfo) {
        // Attach a Tab view factory to the spec
        tabSpec.setContent(activity.new TabFactory(activity));
        String tag = tabSpec.getTag();

        // Check to see if we already have a fragment for this tab, probably
        // from a previously saved state.  If so, deactivate it, because our
        // initial state is that a tab isn't shown.
        tabInfo.fragment = activity.getSupportFragmentManager().findFragmentByTag(tag);
        if (tabInfo.fragment != null && !tabInfo.fragment.isDetached()) {
            FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction();
            ft.detach(tabInfo.fragment);
            ft.commit();
            activity.getSupportFragmentManager().executePendingTransactions();
        }

        tabHost.addTab(tabSpec);
    }

    /** (non-Javadoc)
     * @see android.widget.TabHost.OnTabChangeListener#onTabChanged(java.lang.String)
     */
    public void onTabChanged(String tag) {
        TabInfo newTab = (TabInfo) this.mapTabInfo.get(tag);
        if (mLastTab != newTab) {
            FragmentTransaction ft = this.getSupportFragmentManager().beginTransaction();
            if (mLastTab != null) {
                if (mLastTab.fragment != null) {
                    ft.detach(mLastTab.fragment);
                }
            }
            if (newTab != null) {
                if (newTab.fragment == null) {
                    newTab.fragment = Fragment.instantiate(this,
                            newTab.clss.getName(), newTab.args);
                    ft.add(R.id.realtabcontent, newTab.fragment, newTab.tag);
                } else {
                    ft.attach(newTab.fragment);
                }
            }

            mLastTab = newTab;
            ft.commit();
            this.getSupportFragmentManager().executePendingTransactions();
        }
    }

}
6) 现在,logcat错误:

05-16 06:43:15.068: E/AndroidRuntime(2064): FATAL EXCEPTION: main
05-16 06:43:15.068: E/AndroidRuntime(2064): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.arthur.sos/com.arthur.sos.Main}: java.lang.ClassNotFoundException: com.arthur.sos.Main
05-16 06:43:15.068: E/AndroidRuntime(2064):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1879)
05-16 06:43:15.068: E/AndroidRuntime(2064):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
05-16 06:43:15.068: E/AndroidRuntime(2064):     at android.app.ActivityThread.access$600(ActivityThread.java:122)
05-16 06:43:15.068: E/AndroidRuntime(2064):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
05-16 06:43:15.068: E/AndroidRuntime(2064):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-16 06:43:15.068: E/AndroidRuntime(2064):     at android.os.Looper.loop(Looper.java:137)
05-16 06:43:15.068: E/AndroidRuntime(2064):     at android.app.ActivityThread.main(ActivityThread.java:4340)
05-16 06:43:15.068: E/AndroidRuntime(2064):     at java.lang.reflect.Method.invokeNative(Native Method)
05-16 06:43:15.068: E/AndroidRuntime(2064):     at java.lang.reflect.Method.invoke(Method.java:511)
05-16 06:43:15.068: E/AndroidRuntime(2064):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-16 06:43:15.068: E/AndroidRuntime(2064):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-16 06:43:15.068: E/AndroidRuntime(2064):     at dalvik.system.NativeStart.main(Native Method)
05-16 06:43:15.068: E/AndroidRuntime(2064): Caused by: java.lang.ClassNotFoundException: com.arthur.sos.Main
05-16 06:43:15.068: E/AndroidRuntime(2064):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
05-16 06:43:15.068: E/AndroidRuntime(2064):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
05-16 06:43:15.068: E/AndroidRuntime(2064):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
05-16 06:43:15.068: E/AndroidRuntime(2064):     at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
05-16 06:43:15.068: E/AndroidRuntime(2064):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1870)
05-16 06:43:15.068: E/AndroidRuntime(2064):     ... 11 more
您的错误是:

Caused by: java.lang.ClassNotFoundException: com.arthur.sos.Main
因此,在项目中查找主类存在问题

尝试从以下位置更改清单文件中的活动:

 <activity
        android:name="com.arthur.sos.Main"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

为此:

 <activity
        android:name=".Main"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>


由于您在应用程序中使用的是GMAP,确保你的模拟器支持谷歌Api…thr是一个独立的平台,你必须下载才能支持谷歌Api。因此,请确保你拥有该平台,并以支持谷歌Api的平台作为目标操作系统运行模拟器

你添加了支持库吗?这不是用于Maps V2的,OP正试图使用它。哦,对不起!我没注意到!另外,确保
android-support-v4.jar
位于
libs/
目录中。如果您使用的是R22版本的工具,请查看:
05-16 06:43:15.068: E/AndroidRuntime(2064): FATAL EXCEPTION: main
05-16 06:43:15.068: E/AndroidRuntime(2064): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.arthur.sos/com.arthur.sos.Main}: java.lang.ClassNotFoundException: com.arthur.sos.Main
05-16 06:43:15.068: E/AndroidRuntime(2064):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1879)
05-16 06:43:15.068: E/AndroidRuntime(2064):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
05-16 06:43:15.068: E/AndroidRuntime(2064):     at android.app.ActivityThread.access$600(ActivityThread.java:122)
05-16 06:43:15.068: E/AndroidRuntime(2064):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
05-16 06:43:15.068: E/AndroidRuntime(2064):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-16 06:43:15.068: E/AndroidRuntime(2064):     at android.os.Looper.loop(Looper.java:137)
05-16 06:43:15.068: E/AndroidRuntime(2064):     at android.app.ActivityThread.main(ActivityThread.java:4340)
05-16 06:43:15.068: E/AndroidRuntime(2064):     at java.lang.reflect.Method.invokeNative(Native Method)
05-16 06:43:15.068: E/AndroidRuntime(2064):     at java.lang.reflect.Method.invoke(Method.java:511)
05-16 06:43:15.068: E/AndroidRuntime(2064):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-16 06:43:15.068: E/AndroidRuntime(2064):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-16 06:43:15.068: E/AndroidRuntime(2064):     at dalvik.system.NativeStart.main(Native Method)
05-16 06:43:15.068: E/AndroidRuntime(2064): Caused by: java.lang.ClassNotFoundException: com.arthur.sos.Main
05-16 06:43:15.068: E/AndroidRuntime(2064):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
05-16 06:43:15.068: E/AndroidRuntime(2064):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
05-16 06:43:15.068: E/AndroidRuntime(2064):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
05-16 06:43:15.068: E/AndroidRuntime(2064):     at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
05-16 06:43:15.068: E/AndroidRuntime(2064):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1870)
05-16 06:43:15.068: E/AndroidRuntime(2064):     ... 11 more
Caused by: java.lang.ClassNotFoundException: com.arthur.sos.Main
 <activity
        android:name="com.arthur.sos.Main"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
 <activity
        android:name=".Main"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>