有一个 ListAdapter 的噩梦。我已经阅读了有关如何实例化 ListView 的所有代码。我肯定会将有效 TextView 的 id 传递给 ListView.Adaptor。
现在代码执行良好,并最终成功地离开了 LoadAllStats() 函数和周围的 trycatch。然后一切都以 Unexpected stop -> Force Close 对话框爆炸。
Logcat 表示抛出的异常是 ResourcesNotFoundException。它声称文本视图无效,但它绝对是一个文本视图,并且我已经使用已在其他控件中成功使用的文本视图对其进行了测试,所以我不知道这里到底发生了什么。
有任何想法吗?(在我砸烂我的安卓手机之前?)
谢谢。
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)