gpt4 book ai didi

java - 无法使用 map 启动 Activity

转载 作者:行者123 更新时间:2023-12-01 12:26:50 24 4
gpt4 key购买 nike

我尝试在我的应用程序中使用 Google map ,但它因奇怪的错误而崩溃。我从 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>

map Activity

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

最佳答案

不使用旧类型的 map fragment ,而是使用称为支持 map fragment 的新型 fragment 来支持任何类型的设备

示例

 <fragment
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

关于java - 无法使用 map 启动 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26265174/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com