开发者

MapActivity error: force close

开发者 https://www.devze.com 2023-01-13 15:25 出处:网络
I created a new M开发者_如何学PythonapActivity class MapProba. From main Activity I want to show MapActivity: on button click event I put this code:

I created a new M开发者_如何学PythonapActivity class MapProba.

From main Activity I want to show MapActivity: on button click event I put this code:

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

But I receive force close error.

In my xml file I use this code:

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

In log I receive this error :

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

Line 7 is: com.google.android.maps.MapView

When I remove this code form xml file:

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

Blank black screen appears (there is no error)

In manifest file I have:

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

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

Any idea?

Thanks


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


I had the same problem, you have to put this tag in your AndroidManifest.xml

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

It should be inside:

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

!!!!never, never outside

and use this on yous activity

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


Can you send more of the error log, what comes right after

XML file line #7: Error inflating class com.google.android.maps.MapView ...

It will probably tell why it was not able to inflate this class, whether it is not present, or it is missing libraries...etc...

-- After your update --

What kind of device are you running this on ?

If you use the emulator, you need to use the Google API as your build target.

If you use a real device, it should just work fine on a G1, but if it is a device where you ported Android from AOSP, you most likely do not have the right libraries installed.

Specifically, you should have files like com.google.android.maps.jar and com.google.android.maps.xml There is a good tutorial there to use the mapview : http://developer.android.com/resources/tutorials/views/hello-mapview.html


If you are using an external device for debugging most probably it does not have the right libraries installed.

Especially for archos users check this out http://code.google.com/p/archos-apps-installer/downloads/detail?name=gAppsInstaller_v5-final.apk


On your Maps form class, did you use extends MapActivity instead of extends Activity? That screw me for awhile before I realized that I was using the wrong extended class. :P

0

精彩评论

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