我正在Android开发者资源页面(http://developer.android.com/resources/tutorials/views/hello-mapview.html)上使用HelloGoogleMaps教程,当我在模拟器上运行应用程序的第1部分(“创建地图活动”)时,我收到了消息“应用程序HelloGoogleMaps(进程com.example)已意外停止。请再试一次。”我很确定我正确地遵循了所有指令,但是我不确定我是否正确设置了我的模拟器环境。任何人都可以帮我弄清楚发生了什么事吗?感谢。
这是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
答案 0 :(得分:2)
您好我不确定您是否遇到与我相同的问题,但请确保您的清单中的地图和互联网许可在活动括号内,而不是清单中,即:
</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” &GT;
答案 1 :(得分:1)
以下内容有效(它显示的是地图而不仅仅是网格):
的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
第二步:那99:99 ......
在http://code.google.com/android/maps-api-signup.html给了谷歌
并获得了关键。
如果没有此键,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
并不意味着有错误。地图可以工作,并且仍会将其打印在日志中。
工作应用程序的日志如下所示:
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
答案 2 :(得分:1)
“uses-library”应该在应用程序标记内。 “uses-permission”应该在应用程序标记之外。
答案 3 :(得分:0)
您还需要设置一个使用相同Google API部署目标的新AVD
你做到了吗?