简单的“hello world”的问题Android中ListView的实现
我只是想按照 Google 和其他网站提供的在线教程来创建一个填充静态数据数组的列表视图。我的活动类包含以下代码:
public class HelloListActivity extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, PENS));
}
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Object o = this.getListAdapter().getItem(position);
String pen = o.toString();
Toast.makeText(this, "You have chosen the pen: " + " " + pen, Toast.LENGTH_LONG).show();
}
static final String[] PENS = new String[] { "MONT Blanc", "Gucci", "Parker", "Sailor", "Porsche Design", "Rotring", "Sheaffer", "Waterman" };
}
当我尝试在模拟器中运行它时,我在 logcat 中收到以下异常:
10-23 12:34:44.019: ERROR/AndroidRuntime(679): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.testproj/com.testproj.ListActivity}: java.lang.ClassNotFoundException: com.testproj.ListActivity in loader dalvik.system.PathClassLoader[/data/app/com.testproj-2.apk]
关于我应该在哪里查找此问题的任何想法?我只是在 Eclipse 中创建了一个新的 android 项目,并将活动代码替换为上面的代码,希望生成静态数据的列表视图。
感谢您的任何想法
i'm simply trying to follow online tutorials provided by Google and other websites to create a listview populated with a static array of data. My activity class contains the following code:
public class HelloListActivity extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, PENS));
}
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Object o = this.getListAdapter().getItem(position);
String pen = o.toString();
Toast.makeText(this, "You have chosen the pen: " + " " + pen, Toast.LENGTH_LONG).show();
}
static final String[] PENS = new String[] { "MONT Blanc", "Gucci", "Parker", "Sailor", "Porsche Design", "Rotring", "Sheaffer", "Waterman" };
}
When I try to run this in the emulator, I get the following exception in logcat:
10-23 12:34:44.019: ERROR/AndroidRuntime(679): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.testproj/com.testproj.ListActivity}: java.lang.ClassNotFoundException: com.testproj.ListActivity in loader dalvik.system.PathClassLoader[/data/app/com.testproj-2.apk]
Any thoughts on where I should look for this problem? I've simply created a new android project in Eclipse and replaced the activity code with the above, hoping to produce a listview of the static data.
Thanks for any thoughts
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查manifest.xml。我认为您重命名了该类,但没有更新 maifest。
com.testproj.ListActivity 是 Android 尝试运行的类的名称,但您的是 HelloListActivity。
Check the manifest.xml. I reckon you renamed the class but didn't update the maifest.
com.testproj.ListActivity is the name of the class Android is trying to run but yours is HelloListActivity.