首页 文章

Android HelloGoogleMaps教程例外

提问于
浏览
1

我'm working with the HelloGoogleMaps tutorial on the Android Developers'资源页面(http://developer.android.com/resources/tutorials/views/hello-mapview.html),当我在我的模拟器上运行应用程序的第1部分("Creating a Map Activity")时,我收到消息"The application HelloGoogleMaps (process com.example) has stopped unexpectedly. Please try again."我'm pretty sure that I followed all of the instructions correctly, however I'我不确定我是否正确设置了我的模拟器环境 . 任何人都可以帮我弄清楚发生了什么事吗?谢谢 .

这是logcat的输出:

I/ActivityManager(   63): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example/.HelloGoogleMaps }
I/ActivityManager(   63): Start proc com.example for activity com.example/.HelloGoogleMaps: pid=344 uid=10026 gids={3003, 1015}
D/ddm-heap(  344): Got feature list request
W/dalvikvm(  344): Class resolved by unexpected DEX: Lcom/example/HelloGoogleMaps;(0x43d02e18):0x11fbb0 ref [Lcom/google/android/maps/MapActivity;] Lcom/google/android/maps/MapActivity;(0x43d02e18):0x11f510
W/dalvikvm(  344): (Lcom/example/HelloGoogleMaps; had used a different Lcom/google/android/maps/MapActivity; during pre-verification)
W/dalvikvm(  344): Unable to resolve superclass of Lcom/example/HelloGoogleMaps; (41)
W/dalvikvm(  344): Link of class 'Lcom/example/HelloGoogleMaps;' failed
D/AndroidRuntime(  344): Shutting down VM
W/dalvikvm(  344): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
E/AndroidRuntime(  344): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime(  344): java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
E/AndroidRuntime(  344):     at dalvik.system.DexFile.defineClass(Native Method)
E/AndroidRuntime(  344):     at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:209)
E/AndroidRuntime(  344):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:203)
E/AndroidRuntime(  344):     at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
E/AndroidRuntime(  344):     at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
E/AndroidRuntime(  344):     at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
E/AndroidRuntime(  344):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2409)
E/AndroidRuntime(  344):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
E/AndroidRuntime(  344):     at android.app.ActivityThread.access$2200(ActivityThread.java:119)
E/AndroidRuntime(  344):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
E/AndroidRuntime(  344):     at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(  344):     at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(  344):     at android.app.ActivityThread.main(ActivityThread.java:4363)
E/AndroidRuntime(  344):     at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(  344):     at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(  344):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
E/AndroidRuntime(  344):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
E/AndroidRuntime(  344):     at dalvik.system.NativeStart.main(Native Method)
I/Process (   63): Sending signal. PID: 344 SIG: 3
I/dalvikvm(  344): threadid=7: reacting to signal 3
E/dalvikvm(  344): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
W/ActivityManager(   63): Launch timeout has expired, giving up wake lock!
W/ActivityManager(   63): Activity idle timeout for HistoryRecord{43dc9818 com.example/.HelloGoogleMaps}
D/dalvikvm(  143): GC freed 2317 objects / 132032 bytes in 107ms

4 回答

  • 0

    嗨,我不确定您是否遇到了与我相同的问题,但请确保您的清单中的 Map 和互联网许可是在活动括号内,而不是清单,即:

    </activity>
        <uses-library android:name="com.google.android.maps" />
       <uses-permission android:name="android.permission.INTERNET" />
    
    <activity android:name=".champ" android:label="@string/app_name"
    

    机器人:主题= “@安卓风格/ Theme.NoTitleBar”>

  • 2

    以下内容有效(它显示的是 Map 而不仅仅是网格):

    AndroidManifest.xml中

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="ru.studiomobile.example"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:label="@string/app_name" android:icon="@drawable/icon">
        <activity android:name="HelloMapsActivity"
                  android:label="@string/app_name"
                  android:theme="@android:style/Theme.NoTitleBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <uses-library android:name="com.google.android.maps" />
    </application>
    </manifest>
    

    将这些使用许可放在哪里很重要 . 此外,我怀疑它在添加ACCESS_COARSE_LOCATION后开始工作 .

    main.xml中

    <?xml version="1.0" encoding="utf-8"?>
    <com.google.android.maps.MapView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"
    android:apiKey="9AaAaaaA7AAA_9AaAAARottenAAAAkMJD8h084Q"
    />
    

    密钥是通过以下两步程序获得的:

    步骤1:

    $keytool -list -alias androiddebugkey -keystore ~/.android/debug.keystore -storepass android -keypass android
    androiddebugkey, May 5, 2011, PrivateKeyEntry, 
    Certificate fingerprint (MD5): 99:99:99:99:99:99:99:99:99:99:99:99:99:99:99:99
    

    step2:99:99 ...在http://code.google.com/android/maps-api-signup.html给了google,获得了密钥 .

    没有此键,MapView只显示一个网格,但不起作用 .

    import android.os.Bundle;
    import com.google.android.maps.MapActivity;
    import com.google.android.maps.MapView;
    
    public class HelloMapsActivity extends MapActivity
    {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            MapView mapView = (MapView) findViewById(R.id.mapview);
            mapView.setBuiltInZoomControls(true);
        }
    
        @Override
        protected boolean isRouteDisplayed() {
            return false;
        }
    }
    

    但是......我必须尝试使用释放密钥,然后再使用调试密钥再次运行 . 不知道我改变了什么 . 也许诀窍是用不同的证书安装它 .

    我必须补充一点

    E/MapActivity Couldn't get connection factory client
    

    并不意味着有一个错误 . Map 可以工作,并仍然在日志中打印 .

    工作应用程序的日志如下所示:

    I/ActivityManager(  110): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=xx.yy.example/.HelloMapsActivity } from pid 211
    I/ActivityManager(  110): Start proc xx.yy.example for activity xx.yy.example/.HelloMapsActivity: pid=21102 uid=10064 gids={3003, 1015}
    V/RenderScript_jni(  211): surfaceDestroyed
    D/dalvikvm(21102): GC_CONCURRENT freed 1163K, 54% free 3149K/6727K, external 1625K/2137K, paused 3ms+2ms
    D/dalvikvm(21102): GC_CONCURRENT freed 532K, 51% free 3308K/6727K, external 1625K/2137K, paused 1ms+3ms
    I/MapActivity(21102): Handling network change notification:CONNECTED
    E/MapActivity(21102): Couldn't get connection factory client
    D/dalvikvm(21102): GC_EXTERNAL_ALLOC freed 880K, 55% free 3034K/6727K, external 1993K/2137K, paused 23ms
    I/ActivityManager(  110): Displayed xx.yy.example/.HelloMapsActivity: +584ms
    
  • 1

    “uses-library”应该在应用程序标记内 . “uses-permission”应该在应用程序标记之外 .

  • 1

    您还需要设置一个使用相同Google API部署目标的新AVD

    你做到了吗?

相关问题