问题描述
我采用了android API第2版地图视图中工作,我下面本教程一>,我按照他的解释教程,但还是我越来越严重异常。这里是我的xml code。与日志猫。
<的RelativeLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:工具=http://schemas.android.com/tools
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:paddingBottom会=@扪/ activity_vertical_margin
机器人:paddingLeft =@扪/ activity_horizontal_margin
机器人:paddingRight =@扪/ activity_horizontal_margin
机器人:paddingTop =@扪/ activity_vertical_margin
工具:上下文=MainActivity。> <片段
机器人:ID =@ + ID /图
机器人:layout_width =match_parent
机器人:layout_height =match_parent
类=com.google.android.gms.maps.MapFragment/>< / RelativeLayout的>
logcat的:
10月5日至8日:38:22.121:E / AndroidRuntime(954):致命异常:主要
十月五日至8日:38:22.121:E / AndroidRuntime(954):了java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.map / com.example.map.MainActivity}:android.view.InflateException:二进制XML文件行#11:错误充气类片段
十月五日至8日:38:22.121:E / AndroidRuntime(954):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
十月五日至8日:38:22.121:E / AndroidRuntime(954):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
十月五日至8日:38:22.121:E / AndroidRuntime(954):在android.app.ActivityThread.access $ 600(ActivityThread.java:141)
十月五日至8日:38:22.121:E / AndroidRuntime(954):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1234)
十月五日至8日:38:22.121:E / AndroidRuntime(954):在android.os.Handler.dispatchMessage(Handler.java:99)
十月五日至8日:38:22.121:E / AndroidRuntime(954):在android.os.Looper.loop(Looper.java:137)
十月五日至8日:38:22.121:E / AndroidRuntime(954):在android.app.ActivityThread.main(ActivityThread.java:5041)
十月五日至8日:38:22.121:E / AndroidRuntime(954):在java.lang.reflect.Method.invokeNative(本机方法)
十月五日至8日:38:22.121:E / AndroidRuntime(954):在java.lang.reflect.Method.invoke(Method.java:511)
十月五日至8日:38:22.121:E / AndroidRuntime(954):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:793)
十月五日至8日:38:22.121:E / AndroidRuntime(954):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
十月五日至8日:38:22.121:E / AndroidRuntime(954):在dalvik.system.NativeStart.main(本机方法)
十月五日至8日:38:22.121:E / AndroidRuntime(954):android.view.InflateException:二进制XML文件行#11:错误充气类片段产生的原因
十月五日至8日:38:22.121:E / AndroidRuntime(954):在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
十月五日至8日:38:22.121:E / AndroidRuntime(954):在android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
十月五日至8日:38:22.121:E / AndroidRuntime(954):在android.view.LayoutInflater.inflate(LayoutInflater.java:489)
十月五日至8日:38:22.121:E / AndroidRuntime(954):在android.view.LayoutInflater.inflate(LayoutInflater.java:396)
十月五日至8日:38:22.121:E / AndroidRuntime(954):在android.view.LayoutInflater.inflate(LayoutInflater.java:352)
十月五日至8日:38:22.121:E / AndroidRuntime(954):在com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
十月五日至8日:38:22.121:E / AndroidRuntime(954):在android.app.Activity.setContentView(Activity.java:1881)
十月五日至8日:38:22.121:E / AndroidRuntime(954):在com.example.map.MainActivity.onCreate(MainActivity.java:12)
十月五日至8日:38:22.121:E / AndroidRuntime(954):在android.app.Activity.performCreate(Activity.java:5104)
十月五日至8日:38:22.121:E / AndroidRuntime(954):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
十月五日至8日:38:22.121:E / AndroidRuntime(954):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
十月五日至8日:38:22.121:E / AndroidRuntime(954):11 ...更多
十月五日至8日:38:22.121:E / AndroidRuntime(954):$ android.app.Fragment InstantiationException:产生的原因无法实例片段com.google.android.gms.maps.MapFragment:确保类名称存在,是公众,并且有一个空的构造是公
十月五日至8日:38:22.121:E / AndroidRuntime(954):在android.app.Fragment.instantiate(Fragment.java:592)
十月五日至8日:38:22.121:E / AndroidRuntime(954):在android.app.Fragment.instantiate(Fragment.java:560)
十月五日至8日:38:22.121:E / AndroidRuntime(954):在android.app.Activity.onCreateView(Activity.java:4709)
十月五日至8日:38:22.121:E / AndroidRuntime(954):在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
十月五日至8日:38:22.121:E / AndroidRuntime(954):21 ...更多
十月五日至8日:38:22.121:E / AndroidRuntime(954):抛出java.lang.ClassNotFoundException:产生的原因没有在路径上找到的类com.google.android.gms.maps.MapFragment:/数据/应用/com.example.map-2.apk
十月五日至8日:38:22.121:E / AndroidRuntime(954):在dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
十月五日至8日:38:22.121:E / AndroidRuntime(954):在java.lang.ClassLoader.loadClass(ClassLoader.java:501)
十月五日至8日:38:22.121:E / AndroidRuntime(954):在java.lang.ClassLoader.loadClass(ClassLoader.java:461)
十月五日至8日:38:22.121:E / AndroidRuntime(954):在android.app.Fragment.instantiate(Fragment.java:582)
十月五日至8日:38:22.121:E / AndroidRuntime(954):24 ...更多
和我的清单是看起来像这样。
<?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=com.example.map
安卓版code =1
机器人:=的versionName1.0> <用途-SDK
安卓的minSdkVersion =8
机器人:targetSdkVersion =17/> <许可
机器人:名字=com.example.map.permission.MAPS_RECEIVE
安卓的ProtectionLevel =签名/> <用途特征
机器人:glEsVersion =0x00020000
机器人:要求=真/>
<使用许可权的android:NAME =com.example.map.permission.MAPS_RECEIVE/>
<使用许可权的android:NAME =android.permission.INTERNET对/>
<使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAGE/>
<使用许可权的android:NAME =com.google.android.providers.gsf.permission.READ_GSERVICES/>
<使用许可权的android:NAME =android.permission.ACCESS_COARSE_LOCATION/>
<使用许可权的android:NAME =android.permission.ACCESS_FINE_LOCATION/>
<应用
机器人:allowBackup =真
机器人:图标=@绘制/ ic_launcher
机器人:标签=@字符串/ APP_NAME
机器人:主题=@风格/ AppTheme>
<活动
机器人:名字=com.example.map.MainActivity
机器人:标签=@字符串/ APP_NAME>
&所述;意图滤光器>
<作用机器人:名字=android.intent.action.MAIN/> <类机器人:名字=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
< /活性GT;
&所述;元数据
机器人:名字=com.google.android.maps.v2.API_KEY
机器人:值=AIzaSyDSW0CfwDN0LyrF8PBeihEjrAkj25TDhUQ/>
< /用途>< /清单>
您正尝试导入现有的项目到库中。你应该使用下面的方法来导入库。
- 右键单击Package Explorer中。导入 - > Android的展开 - >现有
Android的code进入工作区。 - 选择谷歌播放服务库。并检查副本
工作区复选框。
一旦做到这一点。参考库项目
右键单击该项目。在左窗格中选择Android。在右窗格底部,你会看到标签库的框架。点击Add并添加导入的库。
要支持库添加到您的项目:
右键单击该项目机器人工具 - >添加支持库
如果您决定使用支持库,你将不得不更换code
<片段
机器人:ID =@ + ID /图
机器人:layout_width =match_parent
机器人:layout_height =match_parent
类=com.google.android.gms.maps.MapFragment/>
与
<片段
机器人:ID =@ + ID /图
机器人:layout_width =match_parent
机器人:layout_height =match_parent
类=com.google.android.gms.maps.SupportMapFragment/>
也是你的java文件,你将不得不使用SupportMapFragment。
MMAP =((SupportMapFragment)getSupportFragmentManager()
.findFragmentById(R.id.map))的GetMap()。
I am working on Map view using android API v2, I am following this tutorial, I have followed what he explained in tutorial, but still I am getting Fatal exception. here is my xml code with log cat.
<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
</RelativeLayout>
logcat:
05-08 10:38:22.121: E/AndroidRuntime(954): FATAL EXCEPTION: main
05-08 10:38:22.121: E/AndroidRuntime(954): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.map/com.example.map.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.os.Handler.dispatchMessage(Handler.java:99)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.os.Looper.loop(Looper.java:137)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.ActivityThread.main(ActivityThread.java:5041)
05-08 10:38:22.121: E/AndroidRuntime(954): at java.lang.reflect.Method.invokeNative(Native Method)
05-08 10:38:22.121: E/AndroidRuntime(954): at java.lang.reflect.Method.invoke(Method.java:511)
05-08 10:38:22.121: E/AndroidRuntime(954): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-08 10:38:22.121: E/AndroidRuntime(954): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-08 10:38:22.121: E/AndroidRuntime(954): at dalvik.system.NativeStart.main(Native Method)
05-08 10:38:22.121: E/AndroidRuntime(954): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
05-08 10:38:22.121: E/AndroidRuntime(954): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-08 10:38:22.121: E/AndroidRuntime(954): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.Activity.setContentView(Activity.java:1881)
05-08 10:38:22.121: E/AndroidRuntime(954): at com.example.map.MainActivity.onCreate(MainActivity.java:12)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.Activity.performCreate(Activity.java:5104)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
05-08 10:38:22.121: E/AndroidRuntime(954): ... 11 more
05-08 10:38:22.121: E/AndroidRuntime(954): Caused by: android.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
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.Fragment.instantiate(Fragment.java:592)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.Fragment.instantiate(Fragment.java:560)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.Activity.onCreateView(Activity.java:4709)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
05-08 10:38:22.121: E/AndroidRuntime(954): ... 21 more
05-08 10:38:22.121: E/AndroidRuntime(954): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.maps.MapFragment" on path: /data/app/com.example.map-2.apk
05-08 10:38:22.121: E/AndroidRuntime(954): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
05-08 10:38:22.121: E/AndroidRuntime(954): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
05-08 10:38:22.121: E/AndroidRuntime(954): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.Fragment.instantiate(Fragment.java:582)
05-08 10:38:22.121: E/AndroidRuntime(954): ... 24 more
And my manifest is looks like this.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.map"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission
android:name="com.example.map.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="com.example.map.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" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.map.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="AIzaSyDSW0CfwDN0LyrF8PBeihEjrAkj25TDhUQ" />
</application>
</manifest>
You are trying to import existing project into library. You should be importing the library using following method.
- Right click package explorer. Import -> Expand Android -> ExistingAndroid Code Into Workspace.
- Select the google-play-services library. And check the copy toworkspace checkbox.
Once this is done. Reference the library project
Right click on the project. Select Android in the left pane. In the right pane bottom you would see a frame with label Library. Click on add and add the imported library.
To add support library to your project:Right click on the project Androids Tools -> Add Support library.
If you decide to use support libraries you will have to replace the code
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
with
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
also in your java file you will have to use SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
这篇关于致命异常:主要了java.lang.RuntimeException:无法启动活动ComponentInfo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!