gpt4 book ai didi

c# - 在 ArrayAdapter 构造函数上抛出 Android NoSuchMethodError

转载 作者:太空狗 更新时间:2023-10-29 13:40:33 26 4
gpt4 key购买 nike

我正在尝试扩展通用 ArrayAdapter 以自定义 ListView,并且在我点击 TpAdapter(我的扩展适配器)构造函数时抛出 NoSuchMethodError

这是扩展的 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;
}
}

我在 Activity 中按如下方式实例化它们:

        MobileTalkingPoint[] weaknesses = talkingPoints;

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

异常的堆栈跟踪如下

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.invokeNative(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.

注意我在 Visual Studio 2010 中使用 Mono for Android

最佳答案

我不确定这是否是 Mono For Android 中的错误(虽然看起来可能是),但是如果您修改适配器以接受 IList 而不是数组,问题就会消失:

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

你仍然可以使用数组调用它,所以不需要修改:

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

关于c# - 在 ArrayAdapter 构造函数上抛出 Android NoSuchMethodError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6350533/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com