自定义图形页面抛出NoSuchMethodException,但它的存在! [英] Custom MapView throwing NoSuchMethodException, but it's there!

查看:209
本文介绍了自定义图形页面抛出NoSuchMethodException,但它的存在!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现一个自定义图形页面。我的内部MapActivity(名为mainmap)我有延伸图形页面的内部类:

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

    }
}

我有我的main.xml格式化找到像这样的内部类:

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

此外,在AndroidManifest.xml中,我有适当的&LT;使用库机器人:名字=com.google.android.maps/&GT; 项。

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

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

ERROR / AndroidRuntime(14999):因
  由:android.view.InflateException:
  二进制XML文件行#2:错误
  充气类
  com.mondo.tbuddy.mainmap $ Lmapview

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

这是由该条目引起的,我觉得在logcat中:

This is caused by this entry I find in logcat:

ERROR / AndroidRuntime(14999):因
  由:java.lang.NoSuchMethodException:
  Lmapview(上下文,AttributeSet中)

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

如果我理解正确的,我的应用程序崩溃,因为Android是说它没有找到我的自定义图形页面(在Lmapview类)适当的构造。你可以看到上面,然而,它被定义,它是寻找签名匹配

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.

谁能给我一些见解?

感谢。

推荐答案

你有一个超类对象之前无法实例内的非静态类。正因为如此,你必须使内部类的静态,或将其移动到一个单独的类。

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.

这篇关于自定义图形页面抛出NoSuchMethodException,但它的存在!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆