我有这个xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainlayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.google.android.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="AIzaSyBc5VI2J_l9cLb1J4pfCXoWxg74xorbpS0"
/>
</RelativeLayout>
当我运行我的应用程序时,我得到了例外:
03-29 12:20:12.555: E/AndroidRuntime(279): FATAL EXCEPTION: main
03-29 12:20:12.555: E/AndroidRuntime(279): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.williamroma.example/com.williamroma.example.GoogleMapActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class com.google.android.maps.MapView
03-29 12:20:12.555: E/AndroidRuntime(279): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
03-29 12:20:12.555: E/AndroidRuntime(279): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
03-29 12:20:12.555: E/AndroidRuntime(279): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
03-29 12:20:12.555: E/AndroidRuntime(279): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
03-29 12:20:12.555: E/AndroidRuntime(279): at android.os.Handler.dispatchMessage(Handler.java:99)
03-29 12:20:12.555: E/AndroidRuntime(279): at android.os.Looper.loop(Looper.java:123)
03-29 12:20:12.555: E/AndroidRuntime(279): at android.app.ActivityThread.main(ActivityThread.java:4627)
03-29 12:20:12.555: E/AndroidRuntime(279): at java.lang.reflect.Method.invokeNative(Native Method)
03-29 12:20:12.555: E/AndroidRuntime(279): at java.lang.reflect.Method.invoke(Method.java:521)
03-29 12:20:12.555: E/AndroidRuntime(279): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-29 12:20:12.555: E/AndroidRuntime(279): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-29 12:20:12.555: E/AndroidRuntime(279): at dalvik.system.NativeStart.main(Native Method)
03-29 12:20:12.555: E/AndroidRuntime(279): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class com.google.android.maps.MapView
03-29 12:20:12.555: E/AndroidRuntime(279): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
03-29 12:20:12.555: E/AndroidRuntime(279): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
03-29 12:20:12.555: E/AndroidRuntime(279): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
03-29 12:20:12.555: E/AndroidRuntime(279): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
03-29 12:20:12.555: E/AndroidRuntime(279): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
03-29 12:20:12.555: E/AndroidRuntime(279): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
03-29 12:20:12.555: E/AndroidRuntime(279): at android.app.Activity.setContentView(Activity.java:1647)
03-29 12:20:12.555: E/AndroidRuntime(279): at com.williamroma.example.GoogleMapActivity.onCreate(GoogleMapActivity.java:11)
03-29 12:20:12.555: E/AndroidRuntime(279): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-29 12:20:12.555: E/AndroidRuntime(279): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
03-29 12:20:12.555: E/AndroidRuntime(279): ... 11 more
03-29 12:20:12.555: E/AndroidRuntime(279): Caused by: java.lang.ClassNotFoundException: com.google.android.maps.MapView in loader dalvik.system.PathClassLoader[/data/app/com.williamroma.example-1.apk]
03-29 12:20:12.555: E/AndroidRuntime(279): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
03-29 12:20:12.555: E/AndroidRuntime(279): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
03-29 12:20:12.555: E/AndroidRuntime(279): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
03-29 12:20:12.555: E/AndroidRuntime(279): at android.view.LayoutInflater.createView(LayoutInflater.java:466)
03-29 12:20:12.555: E/AndroidRuntime(279): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
03-29 12:20:12.555: E/AndroidRuntime(279): ... 20 more
03-29 12:20:14.754: I/Process(279): Sending signal. PID: 279 SIG: 9
我不知道那把钥匙是不是正确的钥匙,也许你知道它是否好看, 那是什么?如何解决呢?,提前谢谢。也许错误是在另一个代码中,我可以给你任何你想要的代码,我的应用程序只是在活动,
package com.williamroma.example;
import android.app.Activity;
import android.os.Bundle;
public class GoogleMapActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.williamroma.example"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<permission
android:name="com.williamroma.example.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.williamroma.example.permission.MAPS_RECEIVE" />
<uses-permission android:name="permission_name" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".GoogleMapActivity"
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="AIzaSyBc5VI2J_l9cLb1J4pfCXoWxg74xorbpS0" />
</application>
</manifest>
<uses-library android:name="com.google.android.maps" />
我在控制台中遇到此异常,应用程序甚至没有启动:(
[2013-03-29 05:38:40 - GoogleMap] Installation error: INSTALL_FAILED_MISSING_SHARED_LIBRARY
[2013-03-29 05:38:40 - GoogleMap] Please check logcat output for more details.
[2013-03-29 05:38:40 - GoogleMap] Launch canceled!
答案 0 :(得分:0)
使用google 2.2 sdk创建AVD并运行您的应用并确保您使用的是MapActvity。
因为正常活动,不适用于mapview。