简单的“hello world”的问题Android中ListView的实现

发布于 2024-12-11 05:44:59 字数 1312 浏览 1 评论 0原文

我只是想按照 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

婴鹅 2024-12-18 05:44:59

检查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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文