2010-08-31 66 views
1

我創建了一個新的MapActivityMapProbaMapActivity錯誤:強制關閉

從主Activity我想告訴MapActivity:按鈕單擊事件,我把這個代碼:

Intent myIntent = new Intent(this, com.art.mode.MapProba.class);   
    startActivity(myIntent); 

但我收到強制關閉錯誤。

在我的XML文件,我用這個代碼:

<LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 

     <com.google.android.maps.MapView 
     android:id="@+id/map_view" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:apiKey="SomeGoogleMapAPIKeyHere" /> 
</LinearLayout> 

在日誌中我收到此錯誤:

08-31 04:47:10.218: ERROR/AndroidRuntime(593): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.art.mode/com.art.mode.MapProba}: 
android.view.InflateException: Binary XML file line #7: Error inflating class com.google.android.maps.MapView 

7號線是:com.google.android.maps.MapView

當我刪除此代碼形式的XML文件:

<com.google.android.maps.MapView 
    android:id="@+id/map_view" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:apiKey="SomeGoogleMapAPIKeyHere" /> 

黑屏出現(沒有錯誤)

清單文件我有:

uses-permission android:name="android.permission.INTERNET" 
uses-permission android:name="android.permission.ACCESS_LOCATION" 

<uses-library android:name="com.google.android.maps" /> 

任何想法?

感謝


UPDATE

08-31 12:22:00.648: ERROR/AndroidRuntime(656): FATAL EXCEPTION: main 
08-31 12:22:00.648: ERROR/AndroidRuntime(656): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.art.mode/com.art.mode.MapProba}: android.view.InflateException: Binary XML file line #7: Error inflating class com.google.android.maps.MapView 
08-31 12:22:00.648: ERROR/AndroidRuntime(656):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) 
08-31 12:22:00.648: ERROR/AndroidRuntime(656):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 
08-31 12:22:00.648: ERROR/AndroidRuntime(656):  at android.app.ActivityThread.access$2300(ActivityThread.java:125) 
08-31 12:22:00.648: ERROR/AndroidRuntime(656):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 
08-31 12:22:00.648: ERROR/AndroidRuntime(656):  at android.os.Handler.dispatchMessage(Handler.java:99) 
08-31 12:22:00.648: ERROR/AndroidRuntime(656):  at android.os.Looper.loop(Looper.java:123) 
08-31 12:22:00.648: ERROR/AndroidRuntime(656):  at android.app.ActivityThread.main(ActivityThread.java:4627) 
08-31 12:22:00.648: ERROR/AndroidRuntime(656):  at java.lang.reflect.Method.invokeNative(Native Method) 
08-31 12:22:00.648: ERROR/AndroidRuntime(656):  at java.lang.reflect.Method.invoke(Method.java:521) 
08-31 12:22:00.648: ERROR/AndroidRuntime(656):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
08-31 12:22:00.648: ERROR/AndroidRuntime(656):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
08-31 12:22:00.648: ERROR/AndroidRuntime(656):  at dalvik.system.NativeStart.main(Native Method) 
08-31 12:22:00.648: ERROR/AndroidRuntime(656): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class com.google.android.maps.MapView 
08-31 12:22:00.648: ERROR/AndroidRuntime(656):  at android.view.LayoutInflater.createView(LayoutInflater.java:513) 
08-31 12:22:00.648: ERROR/AndroidRuntime(656):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565) 
08-31 12:22:00.648: ERROR/AndroidRuntime(656):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:618) 
08-31 12:22:00.648: ERROR/AndroidRuntime(656):  at android.view.LayoutInflater.inflate(LayoutInflater.java:407) 
08-31 12:22:00.648: ERROR/AndroidRuntime(656):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320) 
08-31 12:22:00.648: ERROR/AndroidRuntime(656):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276) 
08-31 12:22:00.648: ERROR/AndroidRuntime(656):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198) 
08-31 12:22:00.648: ERROR/AndroidRuntime(656):  at android.app.Activity.setContentView(Activity.java:1647) 
08-31 12:22:00.648: ERROR/AndroidRuntime(656):  at com.art.mode.MapProba.onCreate(MapProba.java:12) 
08-31 12:22:00.648: ERROR/AndroidRuntime(656):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
08-31 12:22:00.648: ERROR/AndroidRuntime(656):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) 
08-31 12:22:00.648: ERROR/AndroidRuntime(656):  ... 11 more 
08-31 12:22:00.648: ERROR/AndroidRuntime(656): Caused by: java.lang.reflect.InvocationTargetException 
08-31 12:22:00.648: ERROR/AndroidRuntime(656):  at com.google.android.maps.MapView.<init>(MapView.java:238) 
08-31 12:22:00.648: ERROR/AndroidRuntime(656):  at java.lang.reflect.Constructor.constructNative(Native Method) 
08-31 12:22:00.648: ERROR/AndroidRuntime(656):  at java.lang.reflect.Constructor.newInstance(Constructor.java:446) 
08-31 12:22:00.648: ERROR/AndroidRuntime(656):  at android.view.LayoutInflater.createView(LayoutInflater.java:500) 
08-31 12:22:00.648: ERROR/AndroidRuntime(656):  ... 21 more 
08-31 12:22:00.648: ERROR/AndroidRuntime(656): Caused by: java.lang.NullPointerException 
08-31 12:22:00.648: ERROR/AndroidRuntime(656):  at com.google.android.maps.MapActivity.setupMapView(MapActivity.java:382) 
08-31 12:22:00.648: ERROR/AndroidRuntime(656):  at com.google.android.maps.MapView.<init>(MapView.java:280) 
08-31 12:22:00.648: ERROR/AndroidRuntime(656):  at com.google.android.maps.MapView.<init>(MapView.java:255) 
08-31 12:22:00.648: ERROR/AndroidRuntime(656):  ... 25 more 
+0

檢查該解決方案http://stackoverflow.com/a/7644635/779408 – breceivemail 2012-10-27 07:38:16

回答

3

我有同樣的問題,你必須把這個標籤放在你的AndroidManifest中。XML

<uses-library android:name="com.google.android.maps"/> 

它應該是裏面:

<application> 
    <uses-library android:name="com.google.android.maps"/> 
</application> 

!!!!永遠,永遠外

,並使用此對你要跟活動

Intent myIntent = new Intent(getBaseContext(), MapProba.class);    
startActivity(myIntent); 
0

你能發送更多的錯誤日誌的,隨之而來右後

XML文件行#7:錯誤充氣類融爲一體。 google.android.maps.MapView ...

它可能會知道爲什麼它不能誇大這個類,不管是不存在的,或者它缺少庫...等等...

- 你更新後 -

什麼樣的設備你在運行這個?

如果您使用模擬器,則需要使用Google API作爲構建目標。

如果您使用的是真實設備,它應該可以在G1上正常工作,但如果它是從AOSP移植Android的設備,則很可能沒有安裝正確的庫。

具體來說,你應該有一個像com.google.android.maps.jar和com.google.android.maps.xml 文件有一個很好的教程中使用的MapView: http://developer.android.com/resources/tutorials/views/hello-mapview.html

+0

我有所有日誌消息的編輯問題。 感謝您的回覆 – Jovan 2010-08-31 10:22:28

0

在您地圖形式類,你使用extends MapActivity而不是extends Activity?在我意識到我在使用錯誤的擴展類之前,這讓我感到困惑了一段時間。 :P