开发者

Android NoSuchMethodError being thrown on ArrayAdapter Constructor

开发者 https://www.devze.com 2023-03-13 05:01 出处:网络
I\'m attempting to extend the generic ArrayAdapter in order to customize a ListView and am getting an NoSuchMethodError being thrown when I hit the TpAdapter (my extended Adapter) constructor

I'm attempting to extend the generic ArrayAdapter in order to customize a ListView and am getting an NoSuchMethodError being thrown when I hit the TpAdapter (my extended Adapter) constructor

Here is the exteded ArrayAdapter TpAdapter

    private class TpAdapter : ArrayAdapter<MobileTalkingPoint>
    {
        private MobileTalkingPoint[] items;
        private Context outer_context;

        public TpAdapter(Context context, int textViewResourceId, MobileTalkingPoint[] items)
            : base(context, textViewResourceId, items)
        {
            this.items = items;
            this.outer_context = context;
        }

        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            View v = convertView;

            if (v == null)
            {
                LayoutInflater vi = (LayoutInflater)outer_context.GetSystemService(Context.LayoutInflaterService);
                v = vi.Inflate(Resource.Layout.ItemTalkingPoint, null);
            }
            MobileTalkingPoint tp = items[position];
            if (tp != null)
            {
                TextView tpDate = v.FindViewById<TextView>(Resource.Id.tpDate);
                TextView tpTitle = v.FindViewById<TextView>(Resource.Id.tpTitle);
                TextView tpType = v.FindViewById<TextView>(Resource.Id.tpType);
                TextView tpBody = v.FindViewById<TextView>(Resource.Id.tpBody);

                tpDate.Text = String.Format("{0:MM/dd/yy}", tp.TPDate);
                tpTitle.Text = tp.Title;
                tpType.Text = tp.Type;
                tpBody.Text = tp.Descr;
            }

            return v;
        }
    }

I am instantiating them as follows in the activity:

        MobileTalkingPoint[] weaknesses = talkingPoints;

        TpAdapter adapStrength = new TpAdapter(this, Resource.Layout.ItemTalkingPoint, strengths);

And the stacktrace for the exception is as follows

I/ActivityManager( 1283): Starting: Intent { cmp=MapDroid.MapDroid/mapdroid.TabbedView (has extras) } from pid 22409
I/ActivityManager( 1283): Displayed MapDroid.MapDroid/mapdroid.TabbedView: +573ms
D/dalvikvm(22409): GetMethodID: method not found: Lmapdroid/TabTalkingPoints_TpAdapter;.<init>:(Landroid/content/Context;I[Ljava/lang/Object;)V
I/MonoDroid(22409): UNHANDLED EXCEPTION: Java.Lang.NoSuchMethodError: Exception of type 'Java.Lang.NoSuchMethodError' was thrown.
I/MonoDroid(22409): at Android.Runtime.JNIEnv.GetMethodID (intptr,string,string) <0x0007c>
I/MonoDroid(22409): at Android.Widget.ArrayAdapter`1<MonoMap.wsMobile.MobileTalkingPoint>..ctor (Android.Content.Context,int,MonoMap.wsMobile.MobileTalkingPoint[]) <0x0027b>
I/MonoDroid(22409): at MapDroid.TabTalkingPoints/TpAdapter..ctor (Android.Content.Context,int,MonoMap.wsMobile.MobileTalkingPoint[]) <0x0002b>
I/MonoDroid(22409): at MapDroid.TabTalkingPoints.ShowList () <0x00077>
I/MonoDroid(22409): at MapDroid.TabTalkingPoints.OnCreate (Android.OS.Bundle) <0x001df>
I/MonoDroid(22409): at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) <0x00057>
I/MonoDroid(22409): at (wrapper dynamic-method) object.b1cd4072-05f5-4443-8835-b4102b462c1e (intptr,intptr,intptr) <0x00033>
I/MonoDroid(22409):
I/MonoDroid(22409):   --- End of managed exception stack trace ---
I/MonoDroid(22409): java.lang.NoSuchMethodError: <init>
I/MonoDroid(22409):     at mapdroid.TabTalkingPoints.n_onCreate(Native Method)
I/MonoDroid(22409):     at mapdroid.TabTalkingPoints.onCreate(TabTalkingPoints.java:25)
I/MonoDroid(22409):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
I/MonoDroid(22409):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
I/MonoDroid(22409):     at android.app.ActivityThread.startActivityNow(ActivityThread.java:1598)
I/MonoDroid(22409):     at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
I/MonoDroid(22409):     at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
I/MonoDroid(22409):     at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:654)
I/MonoDroid(22409):     at android.widget.TabHost.setCurrentTab(TabHost.java:326)
I/MonoDroid(22409):     at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:132)
I/MonoDroid(22409):     at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:455)
I/MonoDroid(22409):     at android.view.View.performClick(View.java:2501)
I/MonoDroid(22409):     at android.view.View$PerformClick.run(View.java:9107)
I/MonoDroid(22409):     at android.os.Handler.handleCallback(Handler.java:587)
I/MonoDroid(22409):     at android.os.Handler.dispatchMessage(Handler.java:92)
I/MonoDroid(22409):     at android.os.Looper.loop(Looper.java:123)
I/MonoDroid(22409):     at android.app.ActivityThread.main(ActivityThread.java:3835)
I/MonoDroid(22409):     at java.lang.reflect.Method.invoke开发者_运维知识库Native(Native Method)
I/MonoDroid(22409):     at java.lang.reflect.Method.invoke(Method.java:507)
I/MonoDroid(22409):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
I/MonoDroid(22409):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
I/MonoDroid(22409):     at dalvik.system.NativeStart.main(Native Method)
E/mono    (22409):
E/mono    (22409): Unhandled Exception: Java.Lang.NoSuchMethodError: Exception of type 'Java.Lang.NoSuchMethodError' was thrown.
E/mono    (22409):   at Android.Runtime.JNIEnv.GetMethodID (IntPtr kls, System.String name, System.String signature) [0x00000] in <filename unknown>:0
E/mono    (22409):   at Android.Widget.ArrayAdapter`1[MonoMap.wsMobile.MobileTalkingPoint]..ctor (Android.Content.Context context, Int32 textViewResourceId, MonoMap.wsMobile.MobileTalkingPoint[] objects) [0x00000] in <filename unknown>:0
E/mono    (22409):   at MapDroid.TabTalkingPoints+TpAdapter..ctor (Android.Content.Context context, Int32 textViewResourceId, MonoMap.wsMobile.MobileTalkingPoint[] items) [0x00000] in <filename unknown>:0
E/mono    (22409):   at MapDroid.TabTalkingPoints.ShowList () [0x00000] in <filename unknown>:0
E/mono    (22409):   at MapDroid.TabTalkingPoints.OnCreate (Android.OS.Bundle bundle) [0x00000] in <filename unknown>:0
E/mono    (22409):   at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (IntPtr jnienv, IntPtr native__this, IntPtr native_savedInstanceState) [0x00000] in <filename unknown>:0
E/mono    (22409):   at (wrapper dynamic-method)
I/ActivityManager( 1283): Process MapDroid.MapDroid (pid 22409) has died.

NOTE I am using Mono for Android with Visual Studio 2010


I'm not sure if this is a bug in Mono For Android or not (seems like it might be, though), but if you modify your adapter to take in an IList instead of an array, the problem goes away:

private class TpAdapter : ArrayAdapter<MobileTalkingPoint>
{
    public TpAdapter(Context context, int textViewResourceId, IList<MobileTalkingPoint> items)
        : base(context, textViewResourceId, items)
    {
    }
}

You can still call it using an array, so that doesn't need to be modified:

MobileTalkingPoint[] points = { };
TpAdapter adapStrength = new TpAdapter(this, Resource.Layout.ItemTalkingPoint, points);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号