我正在使用老板的手机来测试我们在iOS上开发的应用程序并转移到Android。
我已经按照this教程,在手机上运行时会出现标题中提到的错误。我已经读过10以下的SDK不支持地图是吗?很不确定从这里做什么。代码:
我有3个标签,我作为片段加载,有问题的片段是:
注意:所有导入都是正确的
public class EventFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View V = inflater.inflate(R.layout.event_layout, container, false);
return V;
}
}
在视图xml文件中:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/the_map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"
map:cameraTilt="45"
map:cameraZoom="14"
/>
一切都应该在清单中。当我删除它运行正常。这种事情有解决方法吗?
编辑:
Logcat错误:
06-28 11:25:51.230: E/AndroidRuntime(3405): FATAL EXCEPTION: main
06-28 11:25:51.230: E/AndroidRuntime(3405): android.view.InflateException: Binary XML file line #1: Error inflating class fragment
06-28 11:25:51.230: E/AndroidRuntime(3405): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:587)
06-28 11:25:51.230: E/AndroidRuntime(3405): at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
06-28 11:25:51.230: E/AndroidRuntime(3405): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
06-28 11:25:51.230: E/AndroidRuntime(3405): at co.uk.dwdks.kendalmintfest.KendalInfoFragment.onCreateView(KendalInfoFragment.java:16)
06-28 11:25:51.230: E/AndroidRuntime(3405): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
06-28 11:25:51.230: E/AndroidRuntime(3405): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911)
06-28 11:25:51.230: E/AndroidRuntime(3405): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
06-28 11:25:51.230: E/AndroidRuntime(3405): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
06-28 11:25:51.230: E/AndroidRuntime(3405): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
06-28 11:25:51.230: E/AndroidRuntime(3405): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:429)
06-28 11:25:51.230: E/AndroidRuntime(3405): at android.os.Handler.handleCallback(Handler.java:587)
06-28 11:25:51.230: E/AndroidRuntime(3405): at android.os.Handler.dispatchMessage(Handler.java:92)
06-28 11:25:51.230: E/AndroidRuntime(3405): at android.os.Looper.loop(Looper.java:143)
06-28 11:25:51.230: E/AndroidRuntime(3405): at android.app.ActivityThread.main(ActivityThread.java:4196)
06-28 11:25:51.230: E/AndroidRuntime(3405): at java.lang.reflect.Method.invokeNative(Native Method)
06-28 11:25:51.230: E/AndroidRuntime(3405): at java.lang.reflect.Method.invoke(Method.java:507)
06-28 11:25:51.230: E/AndroidRuntime(3405): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-28 11:25:51.230: E/AndroidRuntime(3405): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-28 11:25:51.230: E/AndroidRuntime(3405): at dalvik.system.NativeStart.main(Native Method)
06-28 11:25:51.230: E/AndroidRuntime(3405): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.MapFragment: make sure class name exists, is public, and has an empty constructor that is public
06-28 11:25:51.230: E/AndroidRuntime(3405): at android.support.v4.app.Fragment.instantiate(Fragment.java:401)
06-28 11:25:51.230: E/AndroidRuntime(3405): at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
06-28 11:25:51.230: E/AndroidRuntime(3405): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
06-28 11:25:51.230: E/AndroidRuntime(3405): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
06-28 11:25:51.230: E/AndroidRuntime(3405): ... 18 more
06-28 11:25:51.230: E/AndroidRuntime(3405): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment in loader dalvik.system.PathClassLoader[/data/app/co.uk.dwdks.kendalmintfest-2.apk]
06-28 11:25:51.230: E/AndroidRuntime(3405): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
06-28 11:25:51.230: E/AndroidRuntime(3405): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
06-28 11:25:51.230: E/AndroidRuntime(3405): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
06-28 11:25:51.230: E/AndroidRuntime(3405): at android.support.v4.app.Fragment.instantiate(Fragment.java:391)
06-28 11:25:51.230: E/AndroidRuntime(3405): ... 21 more
答案 0 :(得分:2)
我认为你需要实现SupportFragment,片段类需要是:class =“com.google.android.gms.maps.SupportMapFragment”
答案 1 :(得分:0)
地图工作(afair)从API8开始。但是您需要将您的应用与google-play-servces_lib
相关联,这很可能不是您的情况。还要确保您在Manifest中设置了所有权限。最后,查看官方文档:https://developers.google.com/maps/documentation/android/