[英]Android Maps V2 Application Crashes on Phone
I've used my app on my phone(Samsung Galaxy S3, 4.1.2) as people adviced me to when it comes to android map v2 apps but I still get the same error where it says that my app has unfortuntely stopped. 我已经在手机上使用了我的应用程序(三星Galaxy S3,4.1.2),因为有人建议我使用android map v2应用程序,但仍然收到相同的错误消息,提示我的应用程序已不幸停止。
MainActivity.java MainActivity.java
package com.example.name;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.SupportMapFragment;
public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SupportMapFragment fragment = new SupportMapFragment();
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, fragment).commit();
}
}
Manifest.xml Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.name"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<permission
android:name="com.example.name.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.name.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:debuggable="true" >
<activity
android:name="com.example.name.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="**api_key**" />
</application>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
</manifest>
activity_main.xml activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="wrap_content"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
Logcat Logcat
03-04 00:26:51.274: E/dalvikvm(14369): Could not find class 'com.google.android.maps.MapView', referenced from method com.cornboyzmaps.googlemapsA.MainActivity.onCreate
03-04 00:26:51.279: W/dalvikvm(14369): VFY: unable to resolve check-cast 465 (Lcom/google/android/maps/MapView;) in Lcom/cornboyzmaps/googlemapsA/MainActivity;
03-04 00:26:51.279: D/dalvikvm(14369): VFY: replacing opcode 0x1f at 0x0014
03-04 00:26:51.279: D/dalvikvm(14369): DexOpt: unable to opt direct call 0x0cdf at 0x34 in Lcom/cornboyzmaps/googlemapsA/MainActivity;.onCreate
03-04 00:26:51.344: D/AndroidRuntime(14369): Shutting down VM
03-04 00:26:51.344: W/dalvikvm(14369): threadid=1: thread exiting with uncaught exception (group=0x413832a0)
03-04 00:26:51.354: E/AndroidRuntime(14369): FATAL EXCEPTION: main
03-04 00:26:51.354: E/AndroidRuntime(14369): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cornboyzmaps.googlemapsA/com.cornboyzmaps.googlemapsA.MainActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class fragment
03-04 00:26:51.354: E/AndroidRuntime(14369): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
03-04 00:26:51.354: E/AndroidRuntime(14369): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
03-04 00:26:51.354: E/AndroidRuntime(14369): at android.app.ActivityThread.access$600(ActivityThread.java:140)
03-04 00:26:51.354: E/AndroidRuntime(14369): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
03-04 00:26:51.354: E/AndroidRuntime(14369): at android.os.Handler.dispatchMessage(Handler.java:99)
03-04 00:26:51.354: E/AndroidRuntime(14369): at android.os.Looper.loop(Looper.java:137)
03-04 00:26:51.354: E/AndroidRuntime(14369): at android.app.ActivityThread.main(ActivityThread.java:4898)
03-04 00:26:51.354: E/AndroidRuntime(14369): at java.lang.reflect.Method.invokeNative(Native Method)
03-04 00:26:51.354: E/AndroidRuntime(14369): at java.lang.reflect.Method.invoke(Method.java:511)
03-04 00:26:51.354: E/AndroidRuntime(14369): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
03-04 00:26:51.354: E/AndroidRuntime(14369): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
03-04 00:26:51.354: E/AndroidRuntime(14369): at dalvik.system.NativeStart.main(Native Method)
03-04 00:26:51.354: E/AndroidRuntime(14369): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class fragment
03-04 00:26:51.354: E/AndroidRuntime(14369): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
03-04 00:26:51.354: E/AndroidRuntime(14369): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
03-04 00:26:51.354: E/AndroidRuntime(14369): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-04 00:26:51.354: E/AndroidRuntime(14369): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-04 00:26:51.354: E/AndroidRuntime(14369): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
03-04 00:26:51.354: E/AndroidRuntime(14369): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:308)
03-04 00:26:51.354: E/AndroidRuntime(14369): at android.app.Activity.setContentView(Activity.java:1924)
03-04 00:26:51.354: E/AndroidRuntime(14369): at com.cornboyzmaps.googlemapsA.MainActivity.onCreate(MainActivity.java:21)
03-04 00:26:51.354: E/AndroidRuntime(14369): at android.app.Activity.performCreate(Activity.java:5206)
03-04 00:26:51.354: E/AndroidRuntime(14369): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
03-04 00:26:51.354: E/AndroidRuntime(14369): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
03-04 00:26:51.354: E/AndroidRuntime(14369): ... 11 more
03-04 00:26:51.354: E/AndroidRuntime(14369): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
03-04 00:26:51.354: E/AndroidRuntime(14369): at android.app.Fragment.instantiate(Fragment.java:584)
03-04 00:26:51.354: E/AndroidRuntime(14369): at android.app.Fragment.instantiate(Fragment.java:552)
03-04 00:26:51.354: E/AndroidRuntime(14369): at android.app.Activity.onCreateView(Activity.java:4849)
03-04 00:26:51.354: E/AndroidRuntime(14369): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
03-04 00:26:51.354: E/AndroidRuntime(14369): ... 21 more
03-04 00:26:51.354: E/AndroidRuntime(14369): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.SupportMapFragment
03-04 00:26:51.354: E/AndroidRuntime(14369): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
03-04 00:26:51.354: E/AndroidRuntime(14369): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
03-04 00:26:51.354: E/AndroidRuntime(14369): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
03-04 00:26:51.354: E/AndroidRuntime(14369): at android.app.Fragment.instantiate(Fragment.java:574)
03-04 00:26:51.354: E/AndroidRuntime(14369): ... 24 more
Somehow, you are missing the code for the Maps V2 library in your project. 不知何故,您的项目中缺少Maps V2库的代码。 You need to correctly attach to the Android library project representing the Play Services SDK.
您需要正确附加到代表Play Services SDK的Android库项目。 See the Play Services documentation , specifically the part beginning with "To set up a project to use the Google Play services SDK".
请参阅Play服务文档 ,尤其是以“设置项目以使用Google Play服务SDK”开头的部分。
If you're on the SDK tools v17 that came out after Google I/O, check if any of these help here: 如果您使用的是Google I / O之后推出的SDK工具v17,请在此处检查是否有以下帮助:
http://xrigau.wordpress.com/2012/03/22/fix-some-problems-with-libraries-in-the-adt-17-plugin-10/ http://xrigau.wordpress.com/2012/03/22/fix-some-problems-with-libraries-in-the-adt-17-plugin-10/
http://android.foxykeep.com/dev/how-to-fix-the-classdefnotfounderror-with-adt-17 http://android.foxykeep.com/dev/how-to-fix-the-classdefnotfounderror-with-adt-17
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.