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

发布于 2024-09-18 16:41:31 字数 1454 浏览 2 评论 0原文

我正在尝试实现自定义 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 中,我有适当的 条目。

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

错误/AndroidRuntime(14999):引起 通过: android.view.InflateException: 二进制 XML 文件第 2 行:错误 膨胀类 com.mondo.tbuddy.mainmap$Lmapview

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

错误/AndroidRuntime(14999):引起 通过:java.lang.NoSuchMethodException: Lmapview(上下文,属性集)

如果我理解正确,我的应用程序正在崩溃,因为 Android 说它找不到我的自定义 MapView(Lmapview 类)的适当构造函数。然而,正如您在上面所看到的,它已被定义并且与它正在寻找的签名相匹配。

谁能给我一些见解吗?

谢谢。

I'm trying to implement a custom MapView. Inside my MapActivity (named mainmap) I have an inner class which extends 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);

    }
}

I have my main.xml formatted to find the inner class like so:

<?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=*****
/>

Also, in Androidmanifest.xml, I have the appropriate <uses-library android:name="com.google.android.maps"/> entry.

When I try to run my app, I get (amongst other things) in logcat:

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

This is caused by this entry I find in logcat:

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

If I understand correctly, my app is crashing because Android is saying it doesn't find the appropriate constructor for my custom MapView (the Lmapview class). As you can see above, however, it is defined and it matches the signature it is looking for.

Can anyone give me some insight?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

长不大的小祸害 2024-09-25 16:41:31

在拥有超类对象之前,无法实例化内部非静态类。因此,您必须使内部类静态,或将其移至单独的类。

You cannot instantiate an inner non-static class before you have a super class object. Because of this you have to make the inner class static, or move it to a separate class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文