2011-03-10 54 views
0

我正在開發我的第一個Android項目。我正在做一個基於maos的應用程序。丁基當我啓動我收到以下錯誤「應用程序停止由於意外的錯誤。Android地圖應用程序未加載(意外停止的錯誤)

這裏是我的代碼。如果有什麼更多的是需要PLZ不要讓我知道我西港島線後他們

import com.google.android.maps.MapView; 

import android.app.Activity; 
import android.os.Bundle; 
import android.widget.LinearLayout; 

public class map extends Activity { 
    /** Called when the activity is first created. */ 
    LinearLayout linearLayout; 
    MapView mapView; 


    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     mapView = (MapView)findViewById(R.id.mapview); 
     mapView.setBuiltInZoomControls(true); 
    } 
} 

這是我的佈局XML。我已經給了apikey了。

<?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:apiKey="Api key" 
    /> 
</RelativeLayout> 

這是我的清單文件。

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
     package="rrj.map" 
     android:versionCode="1"  
     android:versionName="1.0"> 

    <uses-sdk android:minSdkVersion="7" /> 

    <application android:icon="@drawable/icon" android:label="@string/app_name"> 
     <uses-library android:name="com.google.android.maps" /> 
     <activity android:name=".map" 
        android:label="@string/app_name"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 

    </application> 
<uses-permission 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:name="android.permission.INTERNET"> 
    </uses-permission> 
    <uses-permission 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:name="android.permission.ACCESS_FINE_LOCATION"> 
    </uses-permission> 
</manifest> 

logcat停機請幫我指出錯誤。我不知道如何讀的logcat

03-11 00:47:32.856: DEBUG/AndroidRuntime(3209): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<< 
    03-11 00:47:32.856: INFO/AndroidRuntime(3209): Heap size: -Xmx18m 
    03-11 00:47:32.856: DEBUG/AndroidRuntime(3209): CheckJNI is OFF 
    03-11 00:47:32.861: DEBUG/AndroidRuntime(3209): pLocation:english, pLang: en, pRegn: GB 
    03-11 00:47:32.866: DEBUG/AndroidRuntime(3209): setted country_code = India 
    03-11 00:47:32.866: ERROR/AndroidRuntime(3209): /system/csc/sales_code.dat ==> cannot open file 
    03-11 00:47:32.981: DEBUG/AndroidRuntime(3209): --- registering native functions --- 
    03-11 00:47:33.206: DEBUG/ddm-heap(3209): Got feature list request 
    03-11 00:47:33.256: INFO/WynexActivity(1981): WindowOrientationChanged: 0 
    03-11 00:47:33.371: DEBUG/AndroidRuntime(3209): Shutting down VM 
    03-11 00:47:33.371: DEBUG/dalvikvm(3209): DestroyJavaVM waiting for non-daemon threads to exit 
    03-11 00:47:33.371: DEBUG/dalvikvm(3209): DestroyJavaVM shutting VM down 
    03-11 00:47:33.371: DEBUG/dalvikvm(3209): HeapWorker thread shutting down 
    03-11 00:47:33.371: DEBUG/dalvikvm(3209): HeapWorker thread has shut down 
    03-11 00:47:33.376: DEBUG/jdwp(3209): JDWP shutting down net... 
    03-11 00:47:33.376: INFO/dalvikvm(3209): Debugger has detached; object registry had 1 entries 
    03-11 00:47:33.381: DEBUG/dalvikvm(3209): VM cleaning up 
    03-11 00:47:33.391: ERROR/AndroidRuntime(3209): ERROR: thread attach failed 
    03-11 00:47:33.391: DEBUG/dalvikvm(3209): LinearAlloc 0x0 used 663292 of 5242880 (12%) 
    03-11 00:47:33.716: DEBUG/AndroidRuntime(3217): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<< 
    03-11 00:47:33.716: INFO/AndroidRuntime(3217): Heap size: -Xmx18m 
    03-11 00:47:33.716: DEBUG/AndroidRuntime(3217): CheckJNI is OFF 
    03-11 00:47:33.721: DEBUG/AndroidRuntime(3217): pLocation:english, pLang: en, pRegn: GB 
    03-11 00:47:33.726: DEBUG/AndroidRuntime(3217): setted country_code = India 
    03-11 00:47:33.726: ERROR/AndroidRuntime(3217): /system/csc/sales_code.dat ==> cannot open file 
    03-11 00:47:33.886: DEBUG/AndroidRuntime(3217): --- registering native functions --- 
    03-11 00:47:34.111: DEBUG/ddm-heap(3217): Got feature list request 
    03-11 00:47:34.281: INFO/ActivityManager(1905): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=rrj.map/.map } 
    03-11 00:47:34.286: DEBUG/WynexActivity(1981): ----> onSaveInstanceState()false 
    03-11 00:47:34.286: DEBUG/WynexActivity(1981): ----> OnPause()false 
    03-11 00:47:34.286: DEBUG/Wynex(1981): ----> OnPauseActivity() 
    03-11 00:47:34.301: INFO/ActivityManager(1905): Start proc rrj.map for activity rrj.map/.map: pid=3224 uid=10058 gids={3003} 
    03-11 00:47:34.326: DEBUG/AndroidRuntime(3217): Shutting down VM 
    03-11 00:47:34.326: DEBUG/dalvikvm(3217): DestroyJavaVM waiting for non-daemon threads to exit 
    03-11 00:47:34.326: DEBUG/dalvikvm(3217): DestroyJavaVM shutting VM down 
    03-11 00:47:34.326: DEBUG/dalvikvm(3217): HeapWorker thread shutting down 
    03-11 00:47:34.331: DEBUG/dalvikvm(3217): HeapWorker thread has shut down 
    03-11 00:47:34.331: DEBUG/jdwp(3217): JDWP shutting down net... 
    03-11 00:47:34.331: INFO/dalvikvm(3217): Debugger has detached; object registry had 1 entries 
    03-11 00:47:34.336: DEBUG/dalvikvm(3217): VM cleaning up 
    03-11 00:47:34.351: ERROR/AndroidRuntime(3217): ERROR: thread attach failed 
    03-11 00:47:34.356: DEBUG/dalvikvm(3217): LinearAlloc 0x0 used 673260 of 5242880 (12%) 
    03-11 00:47:34.421: DEBUG/ddm-heap(3224): Got feature list request 
    03-11 00:47:34.461: DEBUG/WynexView(1981): (^^) SURFACE DESTROYED 
    03-11 00:47:34.461: DEBUG/WynexView(1981): (^^) <CONSUMER>: AWKE COMSUMER THREAD TO STOP WORKING 
    03-11 00:47:34.461: ERROR/WynexView(1981): (^^) <CONSUMER>: THREAD STOP 
    03-11 00:47:34.471: DEBUG/WynexActivity(1981): ----> onWindowFocusChanged(false) 
    03-11 00:47:34.471: DEBUG/Wynex(1981): ----> OnWindowFocusChanged() 
    03-11 00:47:34.596: DEBUG/AndroidRuntime(3224): Shutting down VM 
    03-11 00:47:34.601: WARN/dalvikvm(3224): threadid=3: thread exiting with uncaught exception (group=0x4001b180) 
    03-11 00:47:34.601: ERROR/AndroidRuntime(3224): Uncaught handler: thread main exiting due to uncaught exception 
    03-11 00:47:34.626: ERROR/AndroidRuntime(3224): java.lang.RuntimeException: Unable to start activity ComponentInfo{rrj.map/rrj.map.map}: android.view.InflateException: Binary XML file line #8: Error inflating class com.google.android.maps.MapView 
    03-11 00:47:34.626: ERROR/AndroidRuntime(3224):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496) 
    03-11 00:47:34.626: ERROR/AndroidRuntime(3224):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512) 
    03-11 00:47:34.626: ERROR/AndroidRuntime(3224):  at android.app.ActivityThread.access$2200(ActivityThread.java:119) 
    03-11 00:47:34.626: ERROR/AndroidRuntime(3224):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863) 
    03-11 00:47:34.626: ERROR/AndroidRuntime(3224):  at android.os.Handler.dispatchMessage(Handler.java:99) 
    03-11 00:47:34.626: ERROR/AndroidRuntime(3224):  at android.os.Looper.loop(Looper.java:123) 
    03-11 00:47:34.626: ERROR/AndroidRuntime(3224):  at android.app.ActivityThread.main(ActivityThread.java:4367) 
    03-11 00:47:34.626: ERROR/AndroidRuntime(3224):  at java.lang.reflect.Method.invokeNative(Native Method) 
    03-11 00:47:34.626: ERROR/AndroidRuntime(3224):  at java.lang.reflect.Method.invoke(Method.java:521) 
    03-11 00:47:34.626: ERROR/AndroidRuntime(3224):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 
    03-11 00:47:34.626: ERROR/AndroidRuntime(3224):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
    03-11 00:47:34.626: ERROR/AndroidRuntime(3224):  at dalvik.system.NativeStart.main(Native Method) 
    03-11 00:47:34.626: ERROR/AndroidRuntime(3224): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class com.google.android.maps.MapView 
    03-11 00:47:34.626: ERROR/AndroidRuntime(3224):  at android.view.LayoutInflater.createView(LayoutInflater.java:513) 
    03-11 00:47:34.626: ERROR/AndroidRuntime(3224):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565) 
    03-11 00:47:34.626: ERROR/AndroidRuntime(3224):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:618) 
    03-11 00:47:34.626: ERROR/AndroidRuntime(3224):  at android.view.LayoutInflater.inflate(LayoutInflater.java:407) 
    03-11 00:47:34.626: ERROR/AndroidRuntime(3224):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320) 
    03-11 00:47:34.626: ERROR/AndroidRuntime(3224):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276) 
    03-11 00:47:34.626: ERROR/AndroidRuntime(3224):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198) 
    03-11 00:47:34.626: ERROR/AndroidRuntime(3224):  at android.app.Activity.setContentView(Activity.java:1622) 
    03-11 00:47:34.626: ERROR/AndroidRuntime(3224):  at rrj.map.map.onCreate(map.java:18) 
    03-11 00:47:34.626: ERROR/AndroidRuntime(3224):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
    03-11 00:47:34.626: ERROR/AndroidRuntime(3224):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459) 
    03-11 00:47:34.626: ERROR/AndroidRuntime(3224):  ... 11 more 
    03-11 00:47:34.626: ERROR/AndroidRuntime(3224): Caused by: java.lang.reflect.InvocationTargetException 
    03-11 00:47:34.626: ERROR/AndroidRuntime(3224):  at com.google.android.maps.MapView.<init>(MapView.java:238) 
    03-11 00:47:34.626: ERROR/AndroidRuntime(3224):  at java.lang.reflect.Constructor.constructNative(Native Method) 
    03-11 00:47:34.626: ERROR/AndroidRuntime(3224):  at java.lang.reflect.Constructor.newInstance(Constructor.java:446) 
    03-11 00:47:34.626: ERROR/AndroidRuntime(3224):  at android.view.LayoutInflater.createView(LayoutInflater.java:500) 
    03-11 00:47:34.626: ERROR/AndroidRuntime(3224):  ... 21 more 
    03-11 00:47:34.626: ERROR/AndroidRuntime(3224): Caused by: java.lang.IllegalArgumentException: MapViews can only be created inside instances of MapActivity. 
    03-11 00:47:34.626: ERROR/AndroidRuntime(3224):  at com.google.android.maps.MapView.<init>(MapView.java:282) 
    03-11 00:47:34.626: ERROR/AndroidRuntime(3224):  at com.google.android.maps.MapView.<init>(MapView.java:255) 
    03-11 00:47:34.626: ERROR/AndroidRuntime(3224):  ... 25 more 

回答

1

什麼我第一個跳出來的是地圖的活動應擴大MapActivity

+0

仔細檢查來自logcat的錯誤日誌,看起來確實是你當前的問題 – Kurru 2011-03-10 19:32:06

+0

所以你應該使用'public class map extends MapActivity',但是我必須指出Java約定的類名以大寫字母開頭 – Kurru 2011-03-10 19:33:27

+1

+1,這裏是你最大的提示'03-11 00:47:34.626:ERROR/AndroidRuntime(3224):引起:java.lang.IllegalArgumentException:MapViews只能在MapActivity的實例內部創建.' – 2011-03-10 19:35:14

1

您的活動必須擴展MapActivity和你缺少你的MapView定義的地圖API密鑰。你可以得到它here

+0

我已經把api鍵了。當我發佈這個問題時,我把它拿出來 – Droidme 2011-03-10 19:50:12

+0

@Droidme然後你需要使用像我這樣的MapActivity和其他答案。 – 2011-03-10 19:52:21

+0

池塘。日Thnx。現在它的工作。 – Droidme 2011-03-11 05:03:54