每次我尝试在我的手机上测试我的应用程序时,它都会显示一条提示“不幸的是,该应用程序已停止”。
我已经检查了构建路径,并确保添加了 Google Play 服务库。我已经尝试搜索几个关于如何修复的线程,但它们都没有工作。所以我把这篇文章作为最后的手段让别人手动检查。
显现:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="info.androidhive.googlemapsv2"
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="8"
android:targetSdkVersion="17" />
<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"
>
<uses-library android:name="com.google.android.maps"/>
<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>
<!-- Goolge API Key -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="My KEY" />
</application>
</manifest>
活动主.xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</FrameLayout>
主要活动.java:
package info.androidhive.info;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import info.androidhive.googlemapsv2.R;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
public class MainActivity extends FragmentActivity {
private SupportMapFragment mapFragment;
private GoogleMap googleMap;
@Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
setContentView(R.layout.activity_main);
/*A noter que dans le cas où nous sommes sur un device< 3.0 nous devrions utiliser les librairies de compatibilités (FragmentActivity, SupportMapfragment).*/
mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
googleMap = mapFragment.getMap();
googleMap.setMyLocationEnabled(true);
}
}
日志猫:
10-31 18:26:51.220: E/AndroidRuntime(869): FATAL EXCEPTION: main
10-31 18:26:51.220: E/AndroidRuntime(869): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{info.androidhive.googlemapsv2/info.androidhive.googlemapsv2.MainActivity}: java.lang.ClassNotFoundException: info.androidhive.googlemapsv2.MainActivity in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/info.androidhive.googlemapsv2-2.apk]
10-31 18:26:51.220: E/AndroidRuntime(869): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2703)
10-31 18:26:51.220: E/AndroidRuntime(869): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2797)
10-31 18:26:51.220: E/AndroidRuntime(869): at android.app.ActivityThread.access$2300(ActivityThread.java:135)
10-31 18:26:51.220: E/AndroidRuntime(869): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2132)
10-31 18:26:51.220: E/AndroidRuntime(869): at android.os.Handler.dispatchMessage(Handler.java:99)
10-31 18:26:51.220: E/AndroidRuntime(869): at android.os.Looper.loop(Looper.java:143)
10-31 18:26:51.220: E/AndroidRuntime(869): at android.app.ActivityThread.main(ActivityThread.java:4914)
10-31 18:26:51.220: E/AndroidRuntime(869): at java.lang.reflect.Method.invokeNative(Native Method)
10-31 18:26:51.220: E/AndroidRuntime(869): at java.lang.reflect.Method.invoke(Method.java:521)
10-31 18:26:51.220: E/AndroidRuntime(869): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
10-31 18:26:51.220: E/AndroidRuntime(869): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
10-31 18:26:51.220: E/AndroidRuntime(869): at dalvik.system.NativeStart.main(Native Method)
10-31 18:26:51.220: E/AndroidRuntime(869): Caused by: java.lang.ClassNotFoundException: info.androidhive.googlemapsv2.MainActivity in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/info.androidhive.googlemapsv2-2.apk]
10-31 18:26:51.220: E/AndroidRuntime(869): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
10-31 18:26:51.220: E/AndroidRuntime(869): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
10-31 18:26:51.220: E/AndroidRuntime(869): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
10-31 18:26:51.220: E/AndroidRuntime(869): at android.app.Instrumentation.newActivity(Instrumentation.java:1033)
10-31 18:26:51.220: E/AndroidRuntime(869): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2695)
10-31 18:26:51.220: E/AndroidRuntime(869): ... 11 more