私は Android の初心者です ... Google マップ v2 を読み込むアプリを作成していますが、読み込めず、「残念ながら閉じられました」というメッセージで毎回クラッシュし続けます。エラーの解決を手伝ってください..よろしくお願いします..私は通常のフォロワースタックオーバーフローです..
**my code**
**Main activity.java**
package com.mypack.test;
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();
}
}
テスト マニフェスト
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mypack.test"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.mypack.test.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.mypack.test.permission.MAPS_RECEIVE" />
<uses-sdk
android:minSdkVersion="12"
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"
android:theme="@style/AppTheme" >
<activity
android:name="com.mypack.test.MainActivity"
android:label="@string/app_name" >
<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="AIzaSyDnHxpS7Pb6YeKBmyWjV_Slj9mIjo6M1FM" />
</application>
</manifest>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
ログキャット
09-19 09:23:08.785: E/Trace(803): error opening trace file: No such file or directory (2)
09-19 09:23:09.515: W/dalvikvm(803): VFY: unable to resolve static field 1065 (MapAttrs) in Lcom/google/android/gms/R$styleable;
09-19 09:23:09.515: D/dalvikvm(803): VFY: replacing opcode 0x62 at 0x000e
09-19 09:23:09.525: D/AndroidRuntime(803): Shutting down VM
09-19 09:23:09.525: W/dalvikvm(803): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
09-19 09:23:09.535: E/AndroidRuntime(803): FATAL EXCEPTION: main
09-19 09:23:09.535: E/AndroidRuntime(803): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
09-19 09:23:09.535: E/AndroidRuntime(803): at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
09-19 09:23:09.535: E/AndroidRuntime(803): at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
09-19 09:23:09.535: E/AndroidRuntime(803): at android.app.Activity.onCreateView(Activity.java:4716)
09-19 09:23:09.535: E/AndroidRuntime(803): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
09-19 09:23:09.535: E/AndroidRuntime(803): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
09-19 09:23:09.535: E/AndroidRuntime(803): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
09-19 09:23:09.535: E/AndroidRuntime(803): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
09-19 09:23:09.535: E/AndroidRuntime(803): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
09-19 09:23:09.535: E/AndroidRuntime(803): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
09-19 09:23:09.535: E/AndroidRuntime(803): at android.app.Activity.setContentView(Activity.java:1881)
09-19 09:23:09.535: E/AndroidRuntime(803): at com.mypack.test.MainActivity.onCreate(MainActivity.java:17)
09-19 09:23:09.535: E/AndroidRuntime(803): at android.app.Activity.performCreate(Activity.java:5104)
09-19 09:23:09.535: E/AndroidRuntime(803): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
09-19 09:23:09.535: E/AndroidRuntime(803): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
09-19 09:23:09.535: E/AndroidRuntime(803): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
09-19 09:23:09.535: E/AndroidRuntime(803): at android.app.ActivityThread.access$600(ActivityThread.java:141)
09-19 09:23:09.535: E/AndroidRuntime(803): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
09-19 09:23:09.535: E/AndroidRuntime(803): at android.os.Handler.dispatchMessage(Handler.java:99)
09-19 09:23:09.535: E/AndroidRuntime(803): at android.os.Looper.loop(Looper.java:137)
09-19 09:23:09.535: E/AndroidRuntime(803): at android.app.ActivityThread.main(ActivityThread.java:5041)
09-19 09:23:09.535: E/AndroidRuntime(803): at java.lang.reflect.Method.invokeNative(Native Method)
09-19 09:23:09.535: E/AndroidRuntime(803): at java.lang.reflect.Method.invoke(Method.java:511)
09-19 09:23:09.535: E/AndroidRuntime(803): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
09-19 09:23:09.535: E/AndroidRuntime(803): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
09-19 09:23:09.535: E/AndroidRuntime(803): at dalvik.system.NativeStart.main(Native Method)
前のコードを編集し、playservice と v4.jar をロードした後の新しい logcat
09-19 14:04:10.644: D/dalvikvm(1930): GC_CONCURRENT freed 1650K, 22% free 6514K/8284K, paused 76ms+19ms, total 279ms
09-19 14:04:10.644: D/dalvikvm(1930): WAIT_FOR_CONCURRENT_GC blocked 51ms
09-19 14:04:11.121: I/Choreographer(1930): Skipped 51 frames! The application may be doing too much work on its main thread.
09-19 14:04:13.281: I/Choreographer(1930): Skipped 170 frames! The application may be doing too much work on its main thread.
09-19 14:05:14.910: D/dalvikvm(1930): GC_CONCURRENT freed 85K, 7% free 7779K/8284K, paused 71ms+5ms, total 151ms
09-19 14:05:14.910: D/dalvikvm(1930): WAIT_FOR_CONCURRENT_GC blocked 64ms
09-19 14:05:15.040: E/MediaPlayer(1930): prepareAsync called in state 8
09-19 14:05:15.040: W/System.err(1930): java.lang.IllegalStateException
09-19 14:05:15.040: W/System.err(1930): at android.media.MediaPlayer.prepare(Native Method)
09-19 14:05:15.050: W/System.err(1930): at androassist.mypack.splash.onCreate(splash.java:38)
09-19 14:05:15.050: W/System.err(1930): at android.app.Activity.performCreate(Activity.java:5104)
09-19 14:05:15.060: W/System.err(1930): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
09-19 14:05:15.060: W/System.err(1930): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
09-19 14:05:15.060: W/System.err(1930): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
09-19 14:05:15.060: W/System.err(1930): at android.app.ActivityThread.access$600(ActivityThread.java:141)
09-19 14:05:15.060: W/System.err(1930): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
09-19 14:05:15.060: W/System.err(1930): at android.os.Handler.dispatchMessage(Handler.java:99)
09-19 14:05:15.060: W/System.err(1930): at android.os.Looper.loop(Looper.java:137)
09-19 14:05:15.060: W/System.err(1930): at android.app.ActivityThread.main(ActivityThread.java:5041)
09-19 14:05:15.071: W/System.err(1930): at java.lang.reflect.Method.invokeNative(Native Method)
09-19 14:05:15.071: W/System.err(1930): at java.lang.reflect.Method.invoke(Method.java:511)
09-19 14:05:15.071: W/System.err(1930): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
09-19 14:05:15.080: W/System.err(1930): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
09-19 14:05:15.080: W/System.err(1930): at dalvik.system.NativeStart.main(Native Method)
09-19 14:05:20.561: I/Choreographer(1930): Skipped 39 frames! The application may be doing too much work on its main thread.
09-19 14:05:21.551: I/Choreographer(1930): Skipped 222 frames! The application may be doing too much work on its main thread.
09-19 14:05:22.491: I/Choreographer(1930): Skipped 225 frames! The application may be doing too much work on its main thread.
09-19 14:05:26.330: W/IInputConnectionWrapper(1930): showStatusIcon on inactive InputConnection
09-19 14:05:28.770: D/Notice(1930): Entering log
09-19 14:05:28.920: D/Key(1930): key matched
09-19 14:05:32.620: I/Choreographer(1930): Skipped 783 frames! The application may be doing too much work on its main thread.
09-19 14:05:33.422: I/Choreographer(1930): Skipped 174 frames! The application may be doing too much work on its main thread.
09-19 14:05:35.290: I/Choreographer(1930): Skipped 55 frames! The application may be doing too much work on its main thread.
09-19 14:05:59.101: D/Notice(1930): Entering log
09-19 14:05:59.831: I/Choreographer(1930): Skipped 48 frames! The application may be doing too much work on its main thread.
09-19 14:06:00.600: I/MyApp(1930): Silent mode
09-19 14:06:00.710: I/Choreographer(1930): Skipped 115 frames! The application may be doing too much work on its main thread.
09-19 14:06:01.280: I/Choreographer(1930): Skipped 48 frames! The application may be doing too much work on its main thread.
09-19 14:06:15.223: D/Notice(1930): Entering log
09-19 14:06:15.900: I/Choreographer(1930): Skipped 54 frames! The application may be doing too much work on its main thread.
09-19 14:06:16.712: I/MyApp(1930): Silent mode
09-19 14:06:16.930: I/Choreographer(1930): Skipped 187 frames! The application may be doing too much work on its main thread.
09-19 14:06:17.620: I/Choreographer(1930): Skipped 92 frames! The application may be doing too much work on its main thread.
09-19 14:06:26.514: D/Notice(1930): Entering log
09-19 14:06:27.103: I/Choreographer(1930): Skipped 50 frames! The application may be doing too much work on its main thread.
09-19 14:06:28.241: D/GPS(1930): GPS Enabled
09-19 14:06:28.265: D/loc message:(1930): fmygpslo(0.00.0)
09-19 14:06:28.731: I/Choreographer(1930): Skipped 381 frames! The application may be doing too much work on its main thread.
09-19 14:06:34.700: I/Choreographer(1930): Skipped 177 frames! The application may be doing too much work on its main thread.
貴重な時間を割いていただきありがとうございます。解決策を得ました...それは私の間違いでした... Reghunandan と Patrik が言ったように.Google Playstore サービスの参照に問題があります..私のアプリは、SDK ディレクトリからではなく、SDK ディレクトリから Google Playstore サービスを参照しています。私のワークスペースに読み込まれたバージョンのGoogle Playstore.So上記のエラーはクリアされます..アプリの実行中にマップが読み込まれません..次のコードで確認しました
package myapp.mypack;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.widget.Toast;
public class MapActivity extends FragmentActivity {
String msgtype,sendernum;
// Google Map
private GoogleMap googleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(check())
{
setContentView(R.layout.app_main);
Toast.makeText(this, "In Google play service.", Toast.LENGTH_LONG).show();
initFun();
}
else
{
Toast.makeText(this, "Google play service not available.", Toast.LENGTH_LONG).show();
}
}
private Boolean check()
{
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if(status==ConnectionResult.SUCCESS)
{
return true;
}
return false;
}
public void initFun()
{
SupportMapFragment sp = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
googleMap = sp.getMap();
googleMap.setMyLocationEnabled(true);
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.map, menu);
return true;
}
}
Android マニフェスト
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="myapp.mypack"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="myapp.mypack.googlemapsv2.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="myapp.mypack.googlemapsv2.permission.MAPS_RECEIVE"/>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" >
</uses-permission>
<!-- Required to show current location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!-- 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"
android:theme="@style/AppTheme" >
<activity
android:name="myapp.mypack.MapActivity"
android:label="@string/app_name" >
<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="AIzaSyDnHxpS7Pb6YeKBmyWjV_Slj9mIjo6M1FM" />
</application>
</manifest>
しかし、地図を読み込んでいます...代わりにしばらく画面が表示され、「Google Play サービスが利用できません」と表示されます。コードで指定されているように..しかし、プロジェクト>プロパティ>アンドロイドをチェックしました。google playstore ライブラリには、緑色のチェック マークが付いています。だから、それは私のプレイストアのバージョンの問題だと思います..*私はギャラクシーs3ミニでアプリを実行します.しかし、同じ白い画面も表示されます..電話での私のプレイストアのビルドバージョンは:4.3.11です.私が持っている唯一の解決策プレイストアを更新してアプリを再実行する必要があります。logcat には、携帯電話のプレイストアのバージョンを更新する必要があることも示されています。皆さん、私のクエリをご覧ください。携帯電話のプレイストアのバージョンに問題があるのでしょうか.. *
ログキャット
09-20 01:19:51.980: E/Trace(26515): error opening trace file: No such file or directory (2)
09-20 01:19:52.020: W/GooglePlayServicesUtil(26515): Google Play services out of date. Requires 3264100 but found 3225134
09-20 01:19:52.190: D/libEGL(26515): loaded /system/lib/egl/libEGL_mali.so
09-20 01:19:52.210: D/libEGL(26515): loaded /system/lib/egl/libGLESv1_CM_mali.so
09-20 01:19:52.210: D/libEGL(26515): loaded /system/lib/egl/libGLESv2_mali.so
09-20 01:19:52.240: D/OpenGLRenderer(26515): Enabling debug mode 0
**Please help me to find a solution?**