开发者

Exception when using MapView - java.lang.RuntimeException: stub

Does the following exception make sense to you? I'm struggling to identify the cause. It occurs when I open a an activity (ActivityMap) subclassed from MapActivity, even if the MapActivity's layout doesn't contain a mapview element.

I suspect it's a project issue. I'm using IntelliJ IDEA. I've set the project up to build against the level 8 Maps API. The IDE is not highlighting any issues with my use of MapActivity in the source, and it builds without error - but then this exception at runtime.

<?xml version="1.0" encoding="utf-8"?>
<Line开发者_Python百科arLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<com.google.android.maps.MapView
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:apiKey="<maps api key is here>"
 />
</LinearLayout>

And then the activity:

public class ActivityMap extends MapActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activitymap);
}

@Override
protected boolean isRouteDisplayed() {
    return false;
}

@Override
protected boolean isLocationDisplayed() {
    return super.isLocationDisplayed();
}

}

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.someapp.myapp/com.someapp.myapp.ActivityMap}: java.lang.RuntimeException: stub
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
        at android.app.ActivityThread.access$1500(ActivityThread.java:117)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:130)
        at android.app.ActivityThread.main(ActivityThread.java:3683)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:507)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
        at dalvik.system.NativeStart.main(Native Method)
        Caused by: java.lang.RuntimeException: stub
        at com.google.android.maps.MapActivity.<init>(Unknown Source)
        at com.someapp.myapp.ActivityMap.<init>(ActivityMap.java:7)
        at java.lang.Class.newInstanceImpl(Native Method)
        at java.lang.Class.newInstance(Class.java:1409)
        at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)


This error usually occurs when running unit tests where the classpath also includes the Android JAR file (Android jar also contains junit test packages, junit.framework and junit.runner).

However, as you're not running any unit tests, the problem lmust be somewhere else.

A while back, I've written an article on how to integrate maps : http://blog.doityourselfandroid.com/2011/01/18/using-google-maps-in-your-android-app/

It covers all the steps required in detail, and some common errors people are having when integrating maps.


I had the same problem, it turned out it was caused by using the Android 3.0 libraries instead of the Google 3.0 APIs.

To change the library I simply right clicked on the project in Eclipse, selected Properties, under the Android option I selected the Google APIs (for 3.0) instead of the Android 3.0 library.


You shoul have an api key in xml file of your map activity http://code.google.com/android/add-ons/google-apis/mapkey.html


The code looks ok. I think you are having other problems. Maybe the Android Google Maps API. Try creating a new project. Have you done a map view before, and did it worked?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜