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

て烟熏妆下的殇ゞ 提交于 2019-12-10 15:46:17

问题


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"?>
<LinearLayout 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)

回答1:


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.




回答2:


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.




回答3:


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




回答4:


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?



来源:https://stackoverflow.com/questions/6912453/exception-when-using-mapview-java-lang-runtimeexception-stub

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!