开发者

Android maps application not loading (Unexpectedly stopped error)

开发者 https://www.devze.com 2023-02-16 06:10 出处:网络
I am working on my first android project. i am doing a maos based application. Buty when I launch I am getting the following error \"application stopped due unexpected error.

I am working on my first android project. i am doing a maos based application. Buty when I launch I am getting the following error "application stopped due unexpected error.

here is my code. if anything more is required plz do let me know I wil post them

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);
    }
}

this is my layout xml. I have given the apikey too.

<?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>

this is my manifest file.

<?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>

the logcat is down please do help me in pointing out the mistake. I don know how to read the 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.inte开发者_JAVA技巧nt.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


What jumps out at me 1st is that map activities should extend MapActivity


Your activity must extend MapActivity and you are missing the Maps Api key in your MapView definition. You can get it here.

0

精彩评论

暂无评论...
验证码 换一张
取 消