携帯電話でアプリをテストしようとするたびに、「残念ながら、アプリは停止しました」というプロンプトが表示されます。
ビルド パスを確認済みで、Google Play Services ライブラリが追加されていることを確認しました。修正方法についてすでにいくつかのスレッドを検索しようとしましたが、どれも機能していません。そのため、誰かに手動で確認してもらうための最後の手段として、この投稿を作成しました。
マニフェスト:
<?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>
アクティビティの main.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);
}
}
LogCat:
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