我正在尝试在我的应用程序中使用Google地图,但它因奇怪的错误而崩溃。我从ActionBarActivity
扩展了我的班级,也许是因为这个原因?我怎么解决这个问题?
<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">
<fragment android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
</RelativeLayout>
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
public class MapActivity extends ActionBarActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setIcon(R.drawable.ic_map);
}
};
10-08 23:44:27.305: E/AndroidRuntime(8797): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.vavianlabs.spyur/com.vavianlabs.spyur.MapActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
10-08 23:44:27.305: E/AndroidRuntime(8797): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659)
10-08 23:44:27.305: E/AndroidRuntime(8797): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
10-08 23:44:27.305: E/AndroidRuntime(8797): at android.app.ActivityThread.access$1500(ActivityThread.java:121)
10-08 23:44:27.305: E/AndroidRuntime(8797): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
10-08 23:44:27.305: E/AndroidRuntime(8797): at android.os.Handler.dispatchMessage(Handler.java:99)
10-08 23:44:27.305: E/AndroidRuntime(8797): at android.os.Looper.loop(Looper.java:130)
10-08 23:44:27.305: E/AndroidRuntime(8797): at android.app.ActivityThread.main(ActivityThread.java:3701)
10-08 23:44:27.305: E/AndroidRuntime(8797): at java.lang.reflect.Method.invokeNative(Native Method)
10-08 23:44:27.305: E/AndroidRuntime(8797): at java.lang.reflect.Method.invoke(Method.java:507)
10-08 23:44:27.305: E/AndroidRuntime(8797): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
10-08 23:44:27.305: E/AndroidRuntime(8797): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
10-08 23:44:27.305: E/AndroidRuntime(8797): at dalvik.system.NativeStart.main(Native Method)
10-08 23:44:27.305: E/AndroidRuntime(8797): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
10-08 23:44:27.305: E/AndroidRuntime(8797): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
10-08 23:44:27.305: E/AndroidRuntime(8797): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
10-08 23:44:27.305: E/AndroidRuntime(8797): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
10-08 23:44:27.305: E/AndroidRuntime(8797): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
10-08 23:44:27.305: E/AndroidRuntime(8797): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
10-08 23:44:27.305: E/AndroidRuntime(8797): at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:128)
10-08 23:44:27.305: E/AndroidRuntime(8797): at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:77)
10-08 23:44:27.305: E/AndroidRuntime(8797): at com.vavianlabs.spyur.MapActivity.onCreate(MapActivity.java:14)
10-08 23:44:27.305: E/AndroidRuntime(8797): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-08 23:44:27.305: E/AndroidRuntime(8797): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623)
10-08 23:44:27.305: E/AndroidRuntime(8797): ... 11 more
10-08 23:44:27.305: E/AndroidRuntime(8797): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/com.vavianlabs.spyur-2.apk]
10-08 23:44:27.305: E/AndroidRuntime(8797): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
10-08 23:44:27.305: E/AndroidRuntime(8797): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
10-08 23:44:27.305: E/AndroidRuntime(8797): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
10-08 23:44:27.305: E/AndroidRuntime(8797): at android.view.LayoutInflater.createView(LayoutInflater.java:471)
10-08 23:44:27.305: E/AndroidRuntime(8797): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
10-08 23:44:27.305: E/AndroidRuntime(8797): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
10-08 23:44:27.305: E/AndroidRuntime(8797): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
10-08 23:44:27.305: E/AndroidRuntime(8797): ... 20 more
答案 0 :(得分:1)
使用称为支持地图片段的较新类型的片段来支持任何类型的设备,而不是使用旧类型的地图片段
<强>样品强>
<fragment
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
答案 1 :(得分:0)
让您的引用Google播放服务到您的applciation并在您的ManifestFiles中添加必要的权限和元数据值?因为例外情况说它无法在您的应用程序中找到Maps类。
看一下这个例子http://www.tutorialspoint.com/android/android_google_maps.htm