views:

108

answers:

1

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.

A: 

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.

Key
its not only an inner class, its private, too
WarrenFaith
that too, of course :)
Key