我正在尝试在 android 中使用谷歌地图功能。我按照https://developers.google.com/maps/documentation/android/hello-mapview的说明进行操作。但是当我运行该应用程序时,似乎存在某种问题。我不确定它是什么,但应用程序不会加载。这是 logcat 中列出的错误。
07-26 02:01:01.771: ERROR/AndroidRuntime(158): ERROR: thread attach failed
07-26 02:01:06.761: ERROR/AndroidRuntime(211): Uncaught handler: thread main exiting due to uncaught exception
07-26 02:01:06.841: ERROR/AndroidRuntime(211): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.trainingcenter.maps/com.trainingcenter.maps.HelloGoogleMaps}: java.lang.ClassNotFoundException: com.trainingcenter.maps.HelloGoogleMaps in loader dalvik.system.PathClassLoader@43b7d958
07-26 02:01:06.841: ERROR/AndroidRuntime(211): Caused by: java.lang.ClassNotFoundException: com.trainingcenter.maps.HelloGoogleMaps in loader dalvik.system.PathClassLoader@43b7d958
07-26 02:01:06.931: ERROR/dalvikvm(211): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
07-26 02:01:17.400: ERROR/AndroidRuntime(242): ERROR: thread attach failed
07-26 02:01:26.391: ERROR/ActivityThread(63): Failed to find provider info for com.google.settings
07-26 02:02:24.580: ERROR/AndroidRuntime(323): ERROR: thread attach failed
07-26 02:07:12.640: ERROR/AndroidRuntime(417): Uncaught handler: thread main exiting due to uncaught exception
07-26 02:07:12.640: ERROR/AndroidRuntime(417): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.trainingcenter.maps/com.trainingcenter.maps.HelloGoogleMaps}: java.lang.ClassNotFoundException: com.trainingcenter.maps.HelloGoogleMaps in loader dalvik.system.PathClassLoader@43d02ee8
07-26 02:07:12.640: ERROR/AndroidRuntime(417): Caused by: java.lang.ClassNotFoundException: com.trainingcenter.maps.HelloGoogleMaps in loader dalvik.system.PathClassLoader@43d02ee8
你能告诉我有什么问题吗?谢谢您的帮助。
这是android清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.trainingcenter.maps" android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<uses-library android:name="com.google.android.maps" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".HelloGoogleMaps" 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>
</application>
这里是活动
package com.trainingcenter.maps;
import android.os.Bundle;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
public class HelloGoogleMaps 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() {
// TODO Auto-generated method stub
return false;
}
}
这是 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="I inserted the API key here, I got it from http://code.google.com/android/maps-api-signup.html" />
顺便说一句,我正在使用 Google API 级别 2.1 更新 1