0

所以我有一个应用程序,它包含所有 google play 服务....但我仍然收到错误和强制崩溃..在此先感谢。MainActivity.java

        public class MainActivity extends FragmentActivity {
        SupportMapFragment mMap;
        GoogleMap googleMap;
        TabHost tabHost;

        @SuppressLint("SetJavaScriptEnabled")
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            // Load Webview
            WebView myWebView = (WebView) findViewById(R.id.webView1);
            WebSettings webSettings = myWebView.getSettings();
            webSettings.setJavaScriptEnabled(true);
            myWebView.setWebViewClient(new WebViewClient());
            myWebView.loadUrl("http://www.salespharma.com/sptouch/msplogin.htm");
            // Remove ActionBar
            getActionBar().hide();
            // Setup the tabhost
            tabHost = (TabHost) findViewById(R.id.tabHost);
            tabHost.setup();

            TabSpec spec1 = tabHost.newTabSpec("SPtouch");
            spec1.setContent(R.id.tab1);
            spec1.setIndicator("SPtouch");

            TabSpec spec2 = tabHost.newTabSpec("GeoLocation");
            spec2.setIndicator("GeoLocation");
            spec2.setContent(R.id.tab2);

            tabHost.addTab(spec1);
            tabHost.addTab(spec2);
            mMap = (SupportMapFragment) getSupportFragmentManager()
                    .findFragmentById(R.id.map);

            googleMap = mMap.getMap();
            // mMap = ((MapFragment)
            // getFragmentManager().findFragmentById(R.id.map)).getMap();
            // Flip view

        }

        public void LoadActivity() {
            Intent startNewActivityOpen = new Intent(MainActivity.this,
                    Settings.class);
            startActivityForResult(startNewActivityOpen, 0);
        }

        public boolean onOptionsItemSelected(MenuItem item) {
            // Handle item selection
            switch (item.getItemId()) {
            case R.id.action_settings:
                LoadActivity();
                return true;
            default:
                return super.onOptionsItemSelected(item);
            }
        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);

            return true;
        }

         }

XML

        <TabHost
            android:id="@+id/tabHost"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentLeft="true" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" >

                <TabWidget
                    android:id="@android:id/tabs"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" >
                </TabWidget>

                <FrameLayout
                    android:id="@android:id/tabcontent"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >

                    <LinearLayout
                        android:id="@+id/tab1"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent" >

                        <WebView
                            android:id="@+id/webView1"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent" />
                    </LinearLayout>

                    <LinearLayout
                        android:id="@+id/tab2"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent" >

                        <fragment
                            android:id="@+id/map"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            class="com.google.android.gms.maps.SupportMapFragment" />
                    </LinearLayout>
                </FrameLayout>
            </LinearLayout>
        </TabHost>

    </RelativeLayout>

清单

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="17" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="***********************************" />

    <permission
        android:name="com.salespharma.sptouchbeta.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.salespharma.sptouchbeta.permission.MAPS_RECEIVE" />

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity
            android:name="com.salespharma.sptouchbeta.MainActivity"
            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="Settings"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
        </activity>
    </application>

</manifest>

最后是 logcat ......请记住,我已经引用了该库!logcat 告诉我找不到。

05-28 19:21:05.210: D/webcoreglue(29886): netstack: Memory Cache feature is OFF
05-28 19:21:05.330: E/ActivityThread(29886): Failed to inflate
05-28 19:21:05.330: E/ActivityThread(29886): android.view.InflateException: Binary XML file line #2: Error inflating class fragment
05-28 19:21:05.330: E/ActivityThread(29886):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
05-28 19:21:05.330: E/ActivityThread(29886):    at android.view.LayoutInflater.parseInclude(LayoutInflater.java:807)
05-28 19:21:05.330: E/ActivityThread(29886):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:736)
05-28 19:21:05.330: E/ActivityThread(29886):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
05-28 19:21:05.330: E/ActivityThread(29886):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
05-28 19:21:05.330: E/ActivityThread(29886):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
05-28 19:21:05.330: E/ActivityThread(29886):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
05-28 19:21:05.330: E/ActivityThread(29886):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
05-28 19:21:05.330: E/ActivityThread(29886):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-28 19:21:05.330: E/ActivityThread(29886):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-28 19:21:05.330: E/ActivityThread(29886):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:276)
05-28 19:21:05.330: E/ActivityThread(29886):    at android.app.Activity.setContentView(Activity.java:1867)
05-28 19:21:05.330: E/ActivityThread(29886):    at com.salespharma.sptouchbeta.MainActivity.onCreate(MainActivity.java:29)
05-28 19:21:05.330: E/ActivityThread(29886):    at android.app.Activity.performCreate(Activity.java:5008)
05-28 19:21:05.330: E/ActivityThread(29886):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
05-28 19:21:05.330: E/ActivityThread(29886):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2145)
05-28 19:21:05.330: E/ActivityThread(29886):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2216)
05-28 19:21:05.330: E/ActivityThread(29886):    at android.app.ActivityThread.access$600(ActivityThread.java:146)
05-28 19:21:05.330: E/ActivityThread(29886):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1212)
05-28 19:21:05.330: E/ActivityThread(29886):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-28 19:21:05.330: E/ActivityThread(29886):    at android.os.Looper.loop(Looper.java:137)
05-28 19:21:05.330: E/ActivityThread(29886):    at android.app.ActivityThread.main(ActivityThread.java:5012)
05-28 19:21:05.330: E/ActivityThread(29886):    at java.lang.reflect.Method.invokeNative(Native Method)
05-28 19:21:05.330: E/ActivityThread(29886):    at java.lang.reflect.Method.invoke(Method.java:511)
05-28 19:21:05.330: E/ActivityThread(29886):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
05-28 19:21:05.330: E/ActivityThread(29886):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
05-28 19:21:05.330: E/ActivityThread(29886):    at dalvik.system.NativeStart.main(Native Method)
05-28 19:21:05.330: E/ActivityThread(29886): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.MapFragment: make sure class name exists, is public, and has an empty constructor that is public
05-28 19:21:05.330: E/ActivityThread(29886):    at android.app.Fragment.instantiate(Fragment.java:584)
05-28 19:21:05.330: E/ActivityThread(29886):    at android.app.Fragment.instantiate(Fragment.java:552)
05-28 19:21:05.330: E/ActivityThread(29886):    at android.app.Activity.onCreateView(Activity.java:4656)
05-28 19:21:05.330: E/ActivityThread(29886):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
05-28 19:21:05.330: E/ActivityThread(29886):    ... 26 more
05-28 19:21:05.330: E/ActivityThread(29886): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment
05-28 19:21:05.330: E/ActivityThread(29886):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
05-28 19:21:05.330: E/ActivityThread(29886):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
05-28 19:21:05.330: E/ActivityThread(29886):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
05-28 19:21:05.330: E/ActivityThread(29886):    at android.app.Fragment.instantiate(Fragment.java:574)
05-28 19:21:05.330: E/ActivityThread(29886):    ... 29 more
05-28 19:21:05.350: D/AndroidRuntime(29886): Shutting down VM
05-28 19:21:05.350: W/dalvikvm(29886): threadid=1: thread exiting with uncaught exception (group=0x41ffd500)
05-28 19:21:05.350: E/AndroidRuntime(29886): FATAL EXCEPTION: main
05-28 19:21:05.350: E/AndroidRuntime(29886): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.salespharma.sptouchbeta/com.salespharma.sptouchbeta.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
05-28 19:21:05.350: E/AndroidRuntime(29886):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2191)
05-28 19:21:05.350: E/AndroidRuntime(29886):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2216)
05-28 19:21:05.350: E/AndroidRuntime(29886):    at android.app.ActivityThread.access$600(ActivityThread.java:146)
05-28 19:21:05.350: E/AndroidRuntime(29886):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1212)
05-28 19:21:05.350: E/AndroidRuntime(29886):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-28 19:21:05.350: E/AndroidRuntime(29886):    at android.os.Looper.loop(Looper.java:137)
05-28 19:21:05.350: E/AndroidRuntime(29886):    at android.app.ActivityThread.main(ActivityThread.java:5012)
05-28 19:21:05.350: E/AndroidRuntime(29886):    at java.lang.reflect.Method.invokeNative(Native Method)
05-28 19:21:05.350: E/AndroidRuntime(29886):    at java.lang.reflect.Method.invoke(Method.java:511)
05-28 19:21:05.350: E/AndroidRuntime(29886):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
05-28 19:21:05.350: E/AndroidRuntime(29886):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
05-28 19:21:05.350: E/AndroidRuntime(29886):    at dalvik.system.NativeStart.main(Native Method)
05-28 19:21:05.350: E/AndroidRuntime(29886): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
05-28 19:21:05.350: E/AndroidRuntime(29886):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
05-28 19:21:05.350: E/AndroidRuntime(29886):    at android.view.LayoutInflater.parseInclude(LayoutInflater.java:807)
05-28 19:21:05.350: E/AndroidRuntime(29886):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:736)
05-28 19:21:05.350: E/AndroidRuntime(29886):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
05-28 19:21:05.350: E/AndroidRuntime(29886):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
05-28 19:21:05.350: E/AndroidRuntime(29886):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
05-28 19:21:05.350: E/AndroidRuntime(29886):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
05-28 19:21:05.350: E/AndroidRuntime(29886):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
05-28 19:21:05.350: E/AndroidRuntime(29886):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-28 19:21:05.350: E/AndroidRuntime(29886):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-28 19:21:05.350: E/AndroidRuntime(29886):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:276)
05-28 19:21:05.350: E/AndroidRuntime(29886):    at android.app.Activity.setContentView(Activity.java:1867)
05-28 19:21:05.350: E/AndroidRuntime(29886):    at com.salespharma.sptouchbeta.MainActivity.onCreate(MainActivity.java:29)
05-28 19:21:05.350: E/AndroidRuntime(29886):    at android.app.Activity.performCreate(Activity.java:5008)
05-28 19:21:05.350: E/AndroidRuntime(29886):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
05-28 19:21:05.350: E/AndroidRuntime(29886):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2145)
05-28 19:21:05.350: E/AndroidRuntime(29886):    ... 11 more
05-28 19:21:05.350: E/AndroidRuntime(29886): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.MapFragment: make sure class name exists, is public, and has an empty constructor that is public
05-28 19:21:05.350: E/AndroidRuntime(29886):    at android.app.Fragment.instantiate(Fragment.java:584)
05-28 19:21:05.350: E/AndroidRuntime(29886):    at android.app.Fragment.instantiate(Fragment.java:552)
05-28 19:21:05.350: E/AndroidRuntime(29886):    at android.app.Activity.onCreateView(Activity.java:4656)
05-28 19:21:05.350: E/AndroidRuntime(29886):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
05-28 19:21:05.350: E/AndroidRuntime(29886):    ... 26 more
05-28 19:21:05.350: E/AndroidRuntime(29886): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment
05-28 19:21:05.350: E/AndroidRuntime(29886):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
05-28 19:21:05.350: E/AndroidRuntime(29886):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
05-28 19:21:05.350: E/AndroidRuntime(29886):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
05-28 19:21:05.350: E/AndroidRuntime(29886):    at android.app.Fragment.instantiate(Fragment.java:574)
05-28 19:21:05.350: E/AndroidRuntime(29886):    ... 29 more

一些截图供参考!

http://i.stack.imgur.com/0IcLu.png http://i.stack.imgur.com/gzmfS.png

4

1 回答 1

1

这里有几个指针:

  1. 在你的 AndroidManifest.xml 里面:

    <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="***********************************" />

    应该位于<application>标签内

  2. 您没有google-play-services_lib项目经理的内部信息,这是我的设置:

    项目设置

    请注意,我有google-play-services_lib.jargoogle-play-services.jar您需要将 导入Google Play Services Library到您的工作区,确保项目已打开,然后将其导入为其他项目的库

祝你好运!!

编辑 :

此链接将为您提供 Android API v2 的分步快速入门指南,对于您的情况,我认为您只需要遵循从第 1 步到第 4 步的指南 :)

编辑 2:

现在,我建议您对这个问题进行更多研究,方法如下:

  1. 尝试在您的应用程序上仅显示地图,如果地图显示,那么您的布局声明有错误。如果应用程序崩溃,那么您有库引用错误。
  2. 如果出现引用错误,请尝试创建一个新项目,将其导入google-play-services_lib到您的项目中,然后尝试先显示地图。当它显示时,修改您的代码以匹配您在此处拥有的当前代码。

祝你好运:D

于 2013-05-29T00:14:51.743 回答