MapsDemo活动中的运行时错误

时间:2013-08-01 13:06:58

标签: android google-maps fragment

我正在使用this tutorial from Google for MapsActivity但由于某种原因我没有获得所需的输出,应用程序崩溃了。

以下是我正在使用的代码:

  1. 的Manifest.xml

    <uses-sdk
        android:minSdkVersion="15"
        android:targetSdkVersion="15" />
    
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.ajinkya.samplemapsdemo.permission.MAPS_RECEIVE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    
    <permission
        android:name="com.ajinkya.samplemapsdemo.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />
    
    <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.ajinkya.samplemapsdemo.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>
    
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="blahblahblahkey" />
    </application>
    

  2. main.xml中

    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/map"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:name="com.google.android.gms.maps.MapFragment"/>
    

  3. MainActivity.java

     package com.ajinkya.samplemapsdemo;
     import android.os.Bundle;
     import android.app.Activity;
     import android.view.Menu;
    
     public class MainActivity extends Activity {
    
    
     @Override
      protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
      }
    
    @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;
    }}
    
  4. 根据谷歌的说法,应该显示一张没有发生的地图。它给了我一个信息:

    Unfortunately, samplemapsdemo has stopped.
    

    这是日志:

    08-01 18:30:21.671: D/ActivityThread(10657): setTargetHeapUtilization:0.25
    08-01 18:30:21.671: D/ActivityThread(10657): setTargetHeapIdealFree:8388608
    08-01 18:30:21.671: D/ActivityThread(10657): setTargetHeapConcurrentStart:2097152
    08-01 18:30:21.741: W/dalvikvm(10657): threadid=1: thread exiting with uncaught exception (group=0x40a9f390)
    08-01 18:31:36.581: D/ActivityThread(10705): setTargetHeapUtilization:0.25
    08-01 18:31:36.581: D/ActivityThread(10705): setTargetHeapIdealFree:8388608
    08-01 18:31:36.591: D/ActivityThread(10705): setTargetHeapConcurrentStart:2097152
    08-01 18:31:36.801: W/dalvikvm(10705): threadid=1: thread exiting with uncaught exception (group=0x40a9f390)
    08-01 18:31:36.831: E/AndroidRuntime(10705): FATAL EXCEPTION: main
    08-01 18:31:36.831: E/AndroidRuntime(10705): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ajinkya.samplemapsdemo/com.ajinkya.samplemapsdemo.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
    08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1959)
    08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1984)
    08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.app.ActivityThread.access$600(ActivityThread.java:126)
    08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1150)
    08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.os.Handler.dispatchMessage(Handler.java:99)
    08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.os.Looper.loop(Looper.java:137)
    08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.app.ActivityThread.main(ActivityThread.java:4456)
    08-01 18:31:36.831: E/AndroidRuntime(10705):    at java.lang.reflect.Method.invokeNative(Native Method)
    08-01 18:31:36.831: E/AndroidRuntime(10705):    at java.lang.reflect.Method.invoke(Method.java:511)
    08-01 18:31:36.831: E/AndroidRuntime(10705):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
    08-01 18:31:36.831: E/AndroidRuntime(10705):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
    08-01 18:31:36.831: E/AndroidRuntime(10705):    at dalvik.system.NativeStart.main(Native Method)
    08-01 18:31:36.831: E/AndroidRuntime(10705): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
    08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
    08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
    08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
    08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
    08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
    08-01 18:31:36.831: E/AndroidRuntime(10705):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
    08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.app.Activity.setContentView(Activity.java:1835)
    08-01 18:31:36.831: E/AndroidRuntime(10705):    at com.ajinkya.samplemapsdemo.MainActivity.onCreate(MainActivity.java:15)
    08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.app.Activity.performCreate(Activity.java:4465)
    08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
    08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1923)
    08-01 18:31:36.831: E/AndroidRuntime(10705):    ... 11 more
    08-01 18:31:36.831: E/AndroidRuntime(10705): 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
    08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.app.Fragment.instantiate(Fragment.java:581)
    08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.app.Fragment.instantiate(Fragment.java:549)
    08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.app.Activity.onCreateView(Activity.java:4235)
    08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:673)
    08-01 18:31:36.831: E/AndroidRuntime(10705):    ... 21 more
    08-01 18:31:36.831: E/AndroidRuntime(10705): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment
    08-01 18:31:36.831: E/AndroidRuntime(10705):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
    08-01 18:31:36.831: E/AndroidRuntime(10705):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
    08-01 18:31:36.831: E/AndroidRuntime(10705):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
    08-01 18:31:36.831: E/AndroidRuntime(10705):    at android.app.Fragment.instantiate(Fragment.java:571)
    08-01 18:31:36.831: E/AndroidRuntime(10705):    ... 24 more
    

    我认为这条线可能是所有问题的根本原因:

    08-01 18:31:36.831: E/AndroidRuntime(10705): 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
    

    任何帮助将不胜感激。

0 个答案:

没有答案