android - 自定义 MapView 抛出 NoSuchMethodException,但它就在那里!

标签 android android-mapview nosuchmethoderror

我正在尝试实现自定义 MapView。在我的 MapActivity(名为 mainmap)中,我有一个扩展 MapView 的内部类:

private class Lmapview extends MapView{

    public Lmapview(Context context, AttributeSet attrs) {
        super(context, attrs);
        gestures = new GestureDetector(mainmap.this, new GestureListener(this));
    }

    public boolean OnTouchEvent(MotionEvent event){
        return gestures.onTouchEvent(event);

    }
}

我将 main.xml 格式化为这样查找内部类:

<?xml version="1.0" encoding="utf-8"?>
<view
    xmlns:android="http://schemas.android.com/apk/res/android"
    class="com.mondo.tbuddy.mainmap$Lmapview"
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"
    android:apiKey=*****
/>

此外,在 Androidmanifest.xml 中,我有适当的 <uses-library android:name="com.google.android.maps"/>条目。

当我尝试运行我的应用程序时,我在 logcat 中得到(除其他外):

ERROR/AndroidRuntime(14999): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class com.mondo.tbuddy.mainmap$Lmapview

这是由我在 logcat 中找到的这个条目引起的:

ERROR/AndroidRuntime(14999): Caused by: java.lang.NoSuchMethodException: Lmapview(Context,AttributeSet)

如果我没理解错的话,我的应用程序崩溃是因为 Android 说它没有为我的自定义 MapView(Lmapview 类)找到合适的构造函数。但是,正如您在上面看到的那样,它已被定义并且与它正在寻找的签名相匹配。

谁能给我一些见解?

谢谢。

最佳答案

在拥有父类(super class)对象之前,您不能实例化内部非静态类。因此,您必须将内部类设为静态,或将其移至单独的类。

关于android - 自定义 MapView 抛出 NoSuchMethodException,但它就在那里!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3682139/

相关文章:

android - 如何摇动Genymotion创建的虚拟设备(安卓模拟器)

android - 在代码里面打开GPS

android - Android中两个ListView的同步滚动

iphone - MapView - 让注释一次出现一个

android - 这可以在 dialogBox android 上显示 mapView 吗?

android - 在 Android 中,如何捕获在 ListView 中单击的项目的文本值?

android - 如何从 Overlay onTap 方法将按下的位置返回到 MapActivity

java.lang.NoSuchMethodError : org. apache.poi.hssf.usermodel.HSSFWorkbook.createDataFormat()Lorg/apache/poi/hssf/usermodel/HSSFDataFormat;

java - 如果带有 getConstructor() 的内部类如何创建实例

web - 加载网页 Primefaces 时出现异常