2012-05-06 51 views
0

我有一個mapView的問題。這是代碼:MapView和錯誤

Android清單:

<uses-sdk android:minSdkVersion="8" /> 
<uses-permission android:name="android.permission.INTERNET"/> 
<application 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" > 
    <uses-library android:name="com.google.android.maps"/> 
    <activity 
     android:label="@string/app_name" 
     android:name=".TestjmkapActivity" > 
     <intent-filter > 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
</application> 

活動:

package test.pl.pl; 

import com.google.android.maps.MapActivity; 
import com.google.android.maps.MapView; 
import android.os.Bundle; 

public class TestjmkapActivity extends MapActivity { 

    MapView mapView; 
    /** Called when the activity is first created. */ 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     mapView = (MapView)findViewById(R.id.map); 

     mapView.setBuiltInZoomControls(true); 
     mapView.setTraffic(false); 
     mapView.setSatellite(true); 
     mapView.setStreetView(true); 
    } 

    @Override 
    protected boolean isRouteDisplayed() { 
     // TODO Auto-generated method stub 
     return false; 
    } 
} 

佈局:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

<com.google.maps.MapView 
    android:id="@+id/map" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="100dp" 
    android:layout_width="100dp" 
     android:enabled="true" 
    android:clickable="true" 
    android:apiKey="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 
    /> 

</LinearLayout> 

此是我在logcat中得到的,當我嘗試啓動它時:

05-06 11:27:23.043: E/AndroidRuntime(565): FATAL EXCEPTION: main 
05-06 11:27:23.043: E/AndroidRuntime(565): java.lang.RuntimeException: Unable to start activity ComponentInfo{test.pl.pl/test.pl.pl.TestjmkapActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class com.google.maps.MapView 
05-06 11:27:23.043: E/AndroidRuntime(565): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) 
05-06 11:27:23.043: E/AndroidRuntime(565): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 
05-06 11:27:23.043: E/AndroidRuntime(565): at android.app.ActivityThread.access$2300(ActivityThread.java:125) 
05-06 11:27:23.043: E/AndroidRuntime(565): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 
05-06 11:27:23.043: E/AndroidRuntime(565): at android.os.Handler.dispatchMessage(Handler.java:99) 
05-06 11:27:23.043: E/AndroidRuntime(565): at android.os.Looper.loop(Looper.java:123) 
05-06 11:27:23.043: E/AndroidRuntime(565): at android.app.ActivityThread.main(ActivityThread.java:4627) 
05-06 11:27:23.043: E/AndroidRuntime(565): at java.lang.reflect.Method.invokeNative(Native Method) 
05-06 11:27:23.043: E/AndroidRuntime(565): at java.lang.reflect.Method.invoke(Method.java:521) 
05-06 11:27:23.043: E/AndroidRuntime(565): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
05-06 11:27:23.043: E/AndroidRuntime(565): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
05-06 11:27:23.043: E/AndroidRuntime(565): at dalvik.system.NativeStart.main(Native Method) 
05-06 11:27:23.043: E/AndroidRuntime(565): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class com.google.maps.MapView 
05-06 11:27:23.043: E/AndroidRuntime(565): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576) 
05-06 11:27:23.043: E/AndroidRuntime(565): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618) 
05-06 11:27:23.043: E/AndroidRuntime(565): at android.view.LayoutInflater.inflate(LayoutInflater.java:407) 
05-06 11:27:23.043: E/AndroidRuntime(565): at android.view.LayoutInflater.inflate(LayoutInflater.java:320) 
05-06 11:27:23.043: E/AndroidRuntime(565): at android.view.LayoutInflater.inflate(LayoutInflater.java:276) 
05-06 11:27:23.043: E/AndroidRuntime(565): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198) 
05-06 11:27:23.043: E/AndroidRuntime(565): at android.app.Activity.setContentView(Activity.java:1647) 
05-06 11:27:23.043: E/AndroidRuntime(565): at test.pl.pl.TestjmkapActivity.onCreate(TestjmkapActivity.java:13) 
05-06 11:27:23.043: E/AndroidRuntime(565): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
05-06 11:27:23.043: E/AndroidRuntime(565): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) 
05-06 11:27:23.043: E/AndroidRuntime(565): ... 11 more 
05-06 11:27:23.043: E/AndroidRuntime(565): Caused by: java.lang.ClassNotFoundException: com.google.maps.MapView in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/test.pl.pl-2.apk] 
05-06 11:27:23.043: E/AndroidRuntime(565): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243) 
05-06 11:27:23.043: E/AndroidRuntime(565): at java.lang.ClassLoader.loadClass(ClassLoader.java:573) 
05-06 11:27:23.043: E/AndroidRuntime(565): at java.lang.ClassLoader.loadClass(ClassLoader.java:532) 
05-06 11:27:23.043: E/AndroidRuntime(565): at android.view.LayoutInflater.createView(LayoutInflater.java:466) 
05-06 11:27:23.043: E/AndroidRuntime(565): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565) 
05-06 11:27:23.043: E/AndroidRuntime(565): ... 20 more 

問題在哪裏?

+0

一切都看起來不錯,什麼模擬器?您是否在使用Google Map API 8的模擬器? – Habib

+0

是的。模擬器是與谷歌API Api8 – edi233

+0

你嘗試刪除並創建一個新的模擬器,然後嘗試? – Habib

回答

2

也許這條線在XML的MapView使它失敗:

xmlns:android="http://schemas.android.com/apk/res/android" 
+0

沒有這條線,我得到了同樣的錯誤 – edi233

+0

@ edi233仔細檢查您不使用谷歌API V8和不機器人V8。清理項目,修復項目,刪除bin,刷新項目。 – Warpzit

+1

哦,使用 Warpzit