有一个ListAdapter噩梦。我已经阅读了有关如何实例化ListView的所有代码。 我绝对将有效TextView的id传递给ListView.Adaptor。
现在代码执行正常并成功地离开了LoadAllStats()函数和周围的trycatch。 然后一切都爆发出意外的停止 - >强制关闭对话框。
Logcat表示抛出的异常是ResourcesNotFoundException。它声称文本视图无效,但它绝对是一个textview,我用一个已成功用于其他控件的textview测试它,所以我不知道这到底是怎么回事。
有什么想法吗? (在我粉碎Android手机之前?)
感谢。
namespace Project
{
[Activity(Label="History")]
public class HistoryFileDialog : Activity
{
ListView ItemList;
ADatabase<Stats> Database;
List<Stats> History;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.HistoryWnd);
ItemList = FindViewById<ListView>(Resource.Id.ListView);
ItemList.ItemClick += new EventHandler<AdapterView.ItemClickEventArgs> (ItemList_ItemClick);
ItemList = FindViewById<ListView>(Resource.Id.ListView);
string Path = Globals._SDROOT + Globals._PROFILEDIR + "user" + "//progress.profile";
LoadAllStats(Path);
}
private void LoadAllStats(string HistoryDBasePath)
{
this.Database = new ADatabase<Stats>(this.ApplicationContext,
HistoryDBasePath);
List<Stats> All = Database.ReadAll();
this.History = new List<Stats>(All.Count);
string[] Test = new string[] { "work", "you", "goddamn", "list", "adapter" };
try
{
// just some test data for the adaptor.
ItemList.Adapter = new ArrayAdapter<String>(this, Resource.Id.Output, Test);
}
catch (Exception e)
{
string Foo = e.StackTrace;
}
}
}
}
Full Logcat =
12-30 02:01:56.948: E/AndroidRuntime(16400): FATAL EXCEPTION: main
12-30 02:01:56.948: E/AndroidRuntime(16400): android.content.res.Resources$NotFoundException: Resource ID #0x7f050026 type #0x12 is not valid
12-30 02:01:56.948: E/AndroidRuntime(16400): at android.content.res.Resources.loadXmlResourceParser(Resources.java:1892)
12-30 02:01:56.948: E/AndroidRuntime(16400): at android.content.res.Resources.getLayout(Resources.java:740)
12-30 02:01:56.948: E/AndroidRuntime(16400): at android.view.LayoutInflater.inflate(LayoutInflater.java:318)
12-30 02:01:56.948: E/AndroidRuntime(16400): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:332)
12-30 02:01:56.948: E/AndroidRuntime(16400): at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
12-30 02:01:56.948: E/AndroidRuntime(16400): at android.widget.AbsListView.obtainView(AbsListView.java:1430)
12-30 02:01:56.948: E/AndroidRuntime(16400): at android.widget.ListView.measureHeightOfChildren(ListView.java:1307)
12-30 02:01:56.948: E/AndroidRuntime(16400): at android.widget.ListView.onMeasure(ListView.java:1127)
12-30 02:01:56.948: E/AndroidRuntime(16400): at android.view.View.measure(View.java:8510)
12-30 02:01:56.948: E/AndroidRuntime(16400): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3202)
12-30 02:01:56.948: E/AndroidRuntime(16400): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1017)
12-30 02:01:56.948: E/AndroidRuntime(16400): at android.widget.LinearLayout.measureVertical(LinearLayout.java:386)
12-30 02:01:56.948: E/AndroidRuntime(16400): at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
12-30 02:01:56.948: E/AndroidRuntime(16400): at android.view.View.measure(View.java:8510)
12-30 02:01:56.948: E/AndroidRuntime(16400): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3202)
12-30 02:01:56.948: E/AndroidRuntime(16400): at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
12-30 02:01:56.948: E/AndroidRuntime(16400): at android.view.View.measure(View.java:8510)
12-30 02:01:56.948: E/AndroidRuntime(16400): at android.widget.LinearLayout.measureVertical(LinearLayout.java:531)
12-30 02:01:56.948: E/AndroidRuntime(16400): at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
12-30 02:01:56.948: E/AndroidRuntime(16400): at android.view.View.measure(View.java:8510)
12-30 02:01:56.948: E/AndroidRuntime(16400): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3202)
12-30 02:01:56.948: E/AndroidRuntime(16400): at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
12-30 02:01:56.948: E/AndroidRuntime(16400): at android.view.View.measure(View.java:8510)
12-30 02:01:56.948: E/AndroidRuntime(16400): at android.view.ViewRoot.performTraversals(ViewRoot.java:871)
12-30 02:01:56.948: E/AndroidRuntime(16400): at android.view.ViewRoot.handleMessage(ViewRoot.java:1939)
12-30 02:01:56.948: E/AndroidRuntime(16400): at android.os.Handler.dispatchMessage(Handler.java:99)
12-30 02:01:56.948: E/AndroidRuntime(16400): at android.os.Looper.loop(Looper.java:143)
12-30 02:01:56.948: E/AndroidRuntime(16400): at android.app.ActivityThread.main(ActivityThread.java:4196)
12-30 02:01:56.948: E/AndroidRuntime(16400): at java.lang.reflect.Method.invokeNative(Native Method)
12-30 02:01:56.948: E/AndroidRuntime(16400): at java.lang.reflect.Method.invoke(Method.java:507)
12-30 02:01:56.948: E/AndroidRuntime(16400): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-30 02:01:56.948: E/AndroidRuntime(16400): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-30 02:01:56.948: E/AndroidRuntime(16400): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:1)
我的猜测是:
或者
要测试第一个,请尝试更改ArrayAdapter以使用如下构造函数:
new ArrayAdapter<string>(this, Resource.Layout.list_item, Test);
尝试测试第二个......
尝试重建所有内容,尝试删除生成的资源设计器cs文件,尝试添加更多控件,尝试在编译器中尖叫等。