我是一名Android初学者,我已经按照教程创建了一个地图应用程序。我已经下载了该应用所需的所有内容。
但是,当我运行我的应用程序时,它会出现一个错误,其中显示"不幸的是,GoogleMapsV2已停止"。我在这里研究了很多博客,并尝试了专业人士建议的每一件事,但遗憾的是他们的答案让我无处可去。问题仍然存在。
P.S:我在三星Galaxy Grand上运行这个应用程序。
这是logcat。
03-17 14:36:29.468: D/jdwp(15645): sendBufferedRequest : len=0x3D
03-17 14:36:29.484: D/jdwp(15645): processIncoming
03-17 14:36:29.484: D/jdwp(15645): handlePacket : cmd=0x1, cmdSet=0xC7, len=0x13,
id=0x4000028F, flags=0x0, dataLen=0x8
03-17 14:36:29.485: D/jdwp(15645): processIncoming
03-17 14:36:29.485: D/jdwp(15645): handlePacket : cmd=0x1, cmdSet=0xC7, len=0x17, id=0x40000290,flags=0x0, dataLen=0xC
03-17 14:36:29.486: D/jdwp(15645): processIncoming
03-17 14:36:29.487: D/jdwp(15645): handlePacket : cmd=0x1, cmdSet=0xC7, len=0x13, id=0x40000291, flags=0x0, dataLen=0x8 03-17 14:36:29.487: D/jdwp(15645): processIncoming
03-17 14:36:29.488: D/jdwp(15645): handlePacket : cmd=0x1, cmdSet=0xC7, len=0x13,id=0x40000292, flags=0x0, dataLen=0x8
03-17 14:36:29.491: D/jdwp(15645): sendBufferedRequest : len=0x45
03-17 14:36:29.493: W/asset(15645): AssetManager-->addDefaultAssets CIP path not exsit!
03-17 14:36:29.523: D/AndroidRuntime(15645): Shutting down VM
03-17 14:36:29.523: W/dalvikvm(15645): threadid=1: thread exiting with uncaught exception (group=0x419759a8)
03-17 14:36:29.526: E/AndroidRuntime(15645): FATAL EXCEPTION: main
03-17 14:36:29.526: E/AndroidRuntime(15645): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{info.androidhive.info/info.androidhive.googlemapsv2.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "info.androidhive.googlemapsv2.MainActivity" on path: DexPathList[[zip file "/data/app/info.androidhive.info-2.apk"],nativeLibraryDirectories=[/data/app-lib/info.androidhive.info-2, /vendor/lib, /system/lib]]
03-17 14:36:29.526: E/AndroidRuntime(15645): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269) 03-17 14:36:29.526: E/AndroidRuntime(15645): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395) 03-17 14:36:29.526: E/AndroidRuntime(15645): at android.app.ActivityThread.access$600(ActivityThread.java:162) 03-17 14:36:29.526: E/AndroidRuntime(15645): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364) 03-17 14:36:29.526: E/AndroidRuntime(15645): at android.os.Handler.dispatchMessage(Handler.java:107) 03-17 14:36:29.526: E/AndroidRuntime(15645): at android.os.Looper.loop(Looper.java:194)
03-17 14:36:29.526: E/AndroidRuntime(15645): at android.app.ActivityThread.main(ActivityThread.java:5371)
03-17 14:36:29.526: E/AndroidRuntime(15645): at java.lang.reflect.Method.invokeNative(Native Method)
03-17 14:36:29.526: E/AndroidRuntime(15645): at java.lang.reflect.Method.invoke(Method.java:525)
03-17 14:36:29.526: E/AndroidRuntime(15645): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
03-17 14:36:29.526: E/AndroidRuntime(15645): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
03-17 14:36:29.526: E/AndroidRuntime(15645): at dalvik.system.NativeStart.main(Native Method)
03-17 14:36:29.526: E/AndroidRuntime(15645): Caused by: java.lang.ClassNotFoundException: Didn't find class "info.androidhive.googlemapsv2.MainActivity" on path: DexPathList[[zip file "/data/app/info.androidhive.info-2.apk"],nativeLibraryDirectories=[/data/app-lib/info.androidhive.info-2, /vendor/lib, /system/lib]]
03-17 14:36:29.526: E/AndroidRuntime(15645): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
03-17 14:36:29.526: E/AndroidRuntime(15645): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
03-17 14:36:29.526: E/AndroidRuntime(15645): atjava.lang.ClassLoader.loadClass(ClassLoader.java:461)
03-17 14:36:29.526: E/AndroidRuntime(15645): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
03-17 14:36:29.526: E/AndroidRuntime(15645): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2260)
03-17 14:36:29.526: E/AndroidRuntime(15645): ... 11 more
这是清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="info.androidhive.info"
android:versionCode="1"
android:versionName="1.0"
>
<permission
android:name="info.androidhive.googlemapsv2.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="info.androidhive.googlemapsv2.permission.MAPS_RECEIVE" />
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Required to show current location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Required OpenGL ES 2.0. for Maps V2 -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name">
<activity
android:name="info.androidhive.googlemapsv2.MainActivity"
android:label="@string/app_name"
android:theme="@style/AppBaseTheme">
<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="my key" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
</application>
</manifest>
这是.xml文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
这里是主要的java文件。
package info.androidhive.info;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import android.os.Bundle;
import android.app.Activity;
import android.widget.Toast;
public class MainActivity extends Activity {
// Google Map
private GoogleMap googleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
// Loading map
initilizeMap();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* function to load map. If map is not created it will create it for you
* */
private void initilizeMap() {
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap();
// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}
@Override
protected void onResume() {
super.onResume();
initilizeMap();
}
}
答案 0 :(得分:0)
更改此行代码,
android:name="info.androidhive.googlemapsv2.MainActivity"
为:
android:name="info.androidhive.info.MainActivity"
因为包名是
package info.androidhive.info;
卸下:
class="com.google.android.gms.maps.SupportMapFragment"