A custom MapView throws a NoSuchMethodException, but it is!

I am trying to implement a custom MapView. Inside my MapActivity (named mainmap) I have an inner class that 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 as follows:

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

In addition, in Androidmanifest.xml I have a corresponding entry <uses-library android:name="com.google.android.maps"/> .

When I try to run my application, I get (among other things) in logcat:

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

This is caused by this entry I found in logcat:

ERROR / AndroidRuntime (14999): Reasons for: java.lang.NoSuchMethodException: Lmapview (context, AttributeSet)

If I understand correctly, my application crashes because Android says it does not find the appropriate constructor for my custom MapView (Lmapview class). As you can see above, however, it is defined and matches the signature it is looking for.

Can someone give me some idea?

Thanks.

+4
source share
1 answer

You cannot create an instance of an internal non-static class before you have a superclass object. Because of this, you must make the inner class static or move it to a separate class.

+5
source