Google Maps API V2 を使用していますが、問題なく動作しています。アプリのデバッグに使用する2.2.2 Androidデバイスがあります。
今、Galaxy Note 2を手に入れました。そのデバイスでデバッグしようとすると、アプリがすぐにクラッシュし、「プロジェクトが機能しなくなりました」。
だから私はちょうどテストするための小さな例を作った. また、2.2.2 では問題なく動作しますが、4.1.1 では動作しません。
これは、小さな例の演習用に私が持っているコードです
どんな提案でも大歓迎です
マイレイアウト
<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" >
<TextView
android:id="@+id/tv_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/tv_location"
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
私のマニフェスト
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ss"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission
android:name="com.example.ss.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.ss.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<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" >
<uses-library android:name="com.google.android.maps" />
<activity
android:name="com.example.ss.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>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="my key"/>
</application>
</manifest>
そして私のテストコード
public class MainActivity extends FragmentActivity implements LocationListener{
private GoogleMap googleMap;
private LatLng source;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());
if(status!=ConnectionResult.SUCCESS){
int requestCode = 10;
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
dialog.show();
}else{
SupportMapFragment fm = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
googleMap = fm.getMap();
googleMap.setMyLocationEnabled(false);
LocationManager locManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locManager.getBestProvider(criteria, true);
Location loc = locManager.getLastKnownLocation(provider);
if(loc!=null){
onLocationChanged(loc);
}
source = new LatLng(loc.getLatitude(), loc.getLongitude());
//makeUrl = new MakeUrl(source, destination);
//String url = makeUrl.makeLocationUrl();
googleMap.moveCamera(CameraUpdateFactory.newLatLng(source));
googleMap.animateCamera(CameraUpdateFactory.zoomTo(15));
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
@Override
public void onLocationChanged(Location arg0) {
// TODO Auto-generated method stub
}
@Override
public void onProviderDisabled(String arg0) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String arg0) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
// TODO Auto-generated method stub
}
}
NOTE 2で取得したスタックトレース
02-17 13:03:23.135: D/dalvikvm(9527): Late-enabling CheckJNI
02-17 13:03:23.170: E/Trace(9527): error opening trace file: No such file or directory (2)
02-17 13:03:23.345: D/dalvikvm(9527): GC_CONCURRENT freed 179K, 6% free 12453K/13191K, paused 2ms+1ms, total 33ms
02-17 13:03:23.345: D/dalvikvm(9527): WAIT_FOR_CONCURRENT_GC blocked 26ms
02-17 13:03:23.575: D/dalvikvm(9527): GC_CONCURRENT freed 279K, 7% free 12634K/13511K, paused 12ms+1ms, total 24ms
02-17 13:03:23.665: D/dalvikvm(9527): GC_CONCURRENT freed 276K, 7% free 12862K/13703K, paused 2ms+12ms, total 29ms
02-17 13:03:23.705: D/AbsListView(9527): Get MotionRecognitionManager
02-17 13:03:23.740: D/dalvikvm(9527): GC_CONCURRENT freed 194K, 6% free 13206K/13959K, paused 2ms+2ms, total 20ms
02-17 13:03:23.740: D/dalvikvm(9527): WAIT_FOR_CONCURRENT_GC blocked 9ms
02-17 13:03:23.745: D/dalvikvm(9527): WAIT_FOR_CONCURRENT_GC blocked 9ms
02-17 13:03:23.760: D/AndroidRuntime(9527): Shutting down VM
02-17 13:03:23.760: W/dalvikvm(9527): threadid=1: thread exiting with uncaught exception (group=0x41c802a0)
02-17 13:03:23.760: E/AndroidRuntime(9527): FATAL EXCEPTION: main
02-17 13:03:23.760: E/AndroidRuntime(9527): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mm/com.example.mm.MainActivity}: java.lang.NullPointerException
02-17 13:03:23.760: E/AndroidRuntime(9527): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
02-17 13:03:23.760: E/AndroidRuntime(9527): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
02-17 13:03:23.760: E/AndroidRuntime(9527): at android.app.ActivityThread.access$600(ActivityThread.java:140)
02-17 13:03:23.760: E/AndroidRuntime(9527): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
02-17 13:03:23.760: E/AndroidRuntime(9527): at android.os.Handler.dispatchMessage(Handler.java:99)
02-17 13:03:23.760: E/AndroidRuntime(9527): at android.os.Looper.loop(Looper.java:137)
02-17 13:03:23.760: E/AndroidRuntime(9527): at android.app.ActivityThread.main(ActivityThread.java:4898)
02-17 13:03:23.760: E/AndroidRuntime(9527): at java.lang.reflect.Method.invokeNative(Native Method)
02-17 13:03:23.760: E/AndroidRuntime(9527): at java.lang.reflect.Method.invoke(Method.java:511)
02-17 13:03:23.760: E/AndroidRuntime(9527): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
02-17 13:03:23.760: E/AndroidRuntime(9527): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
02-17 13:03:23.760: E/AndroidRuntime(9527): at dalvik.system.NativeStart.main(Native Method)
02-17 13:03:23.760: E/AndroidRuntime(9527): Caused by: java.lang.NullPointerException
02-17 13:03:23.760: E/AndroidRuntime(9527): at com.example.mm.MainActivity.onCreate(MainActivity.java:82)
02-17 13:03:23.760: E/AndroidRuntime(9527): at android.app.Activity.performCreate(Activity.java:5191)
02-17 13:03:23.760: E/AndroidRuntime(9527): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
02-17 13:03:23.760: E/AndroidRuntime(9527): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
02-17 13:03:23.760: E/AndroidRuntime(9527): ... 11 more
02-17 13:03:23.955: D/dalvikvm(9527): GC_CONCURRENT freed 233K, 6% free 13394K/14215K, paused 14ms+1ms, total 44ms