2

我在 Mono for Android 中创建了一个 FileDialog 活动。但是,在我看来,在使用 ListView simpleadapter 时,某些 MonoObject 到 JavaObject 的转换存在问题。在我离开 onCreate 后,VM 崩溃并出现以下堆栈跟踪:

07-05 15:04:46.493 D/FileDialogActivity( 3430): Left OnCreate
07-05 15:04:46.503 D/AndroidRuntime( 3430): Shutting down VM
07-05 15:04:46.503 W/dalvikvm( 3430): threadid=1: thread exiting with uncaught exception (group=0xb4127180)
07-05 15:04:46.523 D/dalvikvm( 3430): GC_CONCURRENT freed 115K, 3% free 9634K/9863K, paused 0ms+2ms
07-05 15:04:46.523 E/AndroidRuntime( 3430): FATAL EXCEPTION: main
07-05 15:04:46.523 E/AndroidRuntime( 3430): java.lang.ClassCastException: mono.android.runtime.JavaObject cannot be cast to java.util.Map
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.widget.SimpleAdapter.bindView(SimpleAdapter.java:147)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.widget.SimpleAdapter.createViewFromResource(SimpleAdapter.java:126)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.widget.SimpleAdapter.getView(SimpleAdapter.java:114)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.widget.AbsListView.obtainView(AbsListView.java:2033)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.widget.ListView.makeAndAddView(ListView.java:1772)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.widget.ListView.fillDown(ListView.java:672)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.widget.ListView.fillFromTop(ListView.java:732)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.widget.ListView.layoutChildren(ListView.java:1625)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.widget.AbsListView.onLayout(AbsListView.java:1863)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.view.View.layout(View.java:11278)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.view.ViewGroup.layout(ViewGroup.java:4224)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.view.View.layout(View.java:11278)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.view.ViewGroup.layout(ViewGroup.java:4224)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.widget.RelativeLayout.onLayout(RelativeLayout.java:925)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.view.View.layout(View.java:11278)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.view.ViewGroup.layout(ViewGroup.java:4224)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.view.View.layout(View.java:11278)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.view.ViewGroup.layout(ViewGroup.java:4224)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.view.View.layout(View.java:11278)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.view.ViewGroup.layout(ViewGroup.java:4224)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.view.View.layout(View.java:11278)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.view.ViewGroup.layout(ViewGroup.java:4224)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.view.View.layout(View.java:11278)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.view.ViewGroup.layout(ViewGroup.java:4224)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.view.View.layout(View.java:11278)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.view.ViewGroup.layout(ViewGroup.java:4224)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.view.View.layout(View.java:11278)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.view.ViewGroup.layout(ViewGroup.java:4224)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.view.View.layout(View.java:11278)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.view.ViewGroup.layout(ViewGroup.java:4224)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.view.View.layout(View.java:11278)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.view.ViewGroup.layout(ViewGroup.java:4224)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.view.View.layout(View.java:11278)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.view.ViewGroup.layout(ViewGroup.java:4224)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1489)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.os.Looper.loop(Looper.java:137)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at android.app.ActivityThread.main(ActivityThread.java:4424)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at java.lang.reflect.Method.invokeNative(Native Method)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at java.lang.reflect.Method.invoke(Method.java:511)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-05 15:04:46.523 E/AndroidRuntime( 3430):     at dalvik.system.NativeStart.main(Native Method)

一些代码:

IList<IDictionary<string, object>> mData = new List<IDictionary<string, object>>();
AddFiles(files, mData); // Which just new Dictionary with filedata and icon from a list of files.
SimpleAdapter fileAdapter = new SimpleAdapter(this, mData,
            Resource.Layout.FileDialogRow,
            new string[] { FileKey, FileImage },
            new int[] { Resource.Id.fdrowname, Resource.Id.fdrowimage }
        );
ListAdapter = fileAdapter;
Log.Debug("Left OnCreate");

在 Mono for Android 上使用 SimpleAdapter 时,还有其他人遇到问题吗?或者对这里发生的事情有任何线索?

4

1 回答 1

4

而不是使用List我认为你将需要使用JavaList. 喜欢:

var mData = new JavaList<IDictionary<string, object>>();

这个线程有一个很长的解释:http: //mono-for-android.1047100.n5.nabble.com/SimpleAdapter-break-in-4-2-1-td5709793.html

如果您将在列表中使用更复杂的东西,我建议您实现自己的适配器,这最终更容易维护和调试。

于 2012-07-06T18:39:52.137 回答