【问题标题】:Error Message-The source attachment does not contain the source for the file ListView.class错误消息 - 源附件不包含文件 ListView.class 的源
【发布时间】:2011-02-04 20:03:11
【问题描述】:

Android 新手。我在调试器透视图中收到以下消息:

源附件不包含文件 ListView.class 的源 您可以通过点击下面的更改附件源来更改源附件

不用说应用程序错误。我尝试将源附件更改为位置路径:

C:/Program Files/Android/android-sdk-windows/platforms/android-8/android.jar

但是,这不起作用。

任何想法将不胜感激。

代码是:

import android.app.ListActivity;
import android.os.Bundle;
import android.view.*;
import android.widget.*;


public class HelloListView extends ListActivity 
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      setListAdapter(new ArrayAdapter<String>(this, R.layout.main, COUNTRIES));

      ListView lv = getListView();
      lv.setTextFilterEnabled(true);

     lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,
            int position, long id) {
          // When clicked, show a toast with the TextView text
          Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
              Toast.LENGTH_SHORT).show();
        }
      });
    }


    static final String[] COUNTRIES = new String[] {
        "Afghanistan", "Albania", "Algeria", "American Samoa...

谢谢!

【问题讨论】:

  • 确保将您的活动添加到清单中。

标签: android listactivity


【解决方案1】:

The source attachment does not contain the source for the file ListView.class

应用错误不用说。

调试器只是说您当前在调试器中突出显示的堆栈帧位于 ListView 类中,而您没有源代码可以在编辑器中使用它。 这当然不是您的程序出现任何问题的原因。如果您找到与您的源代码相对应的堆栈帧,调试器会很高兴地向您显示与堆栈帧相对应的代码.您可能会费心安装 Android 源代码,但它不会解决您的程序遇到的任何问题。

请澄清您的程序做错了什么 - 除了该消息之外还有什么症状。请在 LogCat 中查找错误消息、异常和堆栈跟踪并发布它们。

【讨论】:

    【解决方案2】:

    如果您有源代码,它只允许您进入操作系统类本身的源代码,这可能会让您感到困惑。要查看它在调试器中停止时的原因是什么,请继续按 F6,直到调试透视图中的变量向您显示异常。它会是这样的:

    这个 InvocationTargetException (id=????????)
    异常 IllegalStateException (id=????????)
    导致 ClassCastException (id=????????)
    detailMessage "ArrayAdapter 要求资源 ID 为 TextView" (id=????????)

    因为我过去已经完成了本教程并且知道这行:

    setListAdapter(new ArrayAdapter<String>(this, R.layout.main, COUNTRIES));
    

    应该是

    setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES));
    

    原来如此

    【讨论】:

      【解决方案3】:

      当源路径设置不正确时会显示此错误消息。如果是 Eclipse,则单击错误消息下方显示的更改附加源按钮,并给出源路径(例如 C:/Program Files/Java/jdk1.6.0_24/src.zip)。

      或者

      转到项目 > 属性 > Java 构建路径 > 库 展开 JRE 系统库。展开 rt.jar。 选择源附件并双击或编辑。 输入源代码文件(外部文件...)的路径,然后按确定。

      参考:http://android.okhelp.cz/class-file-editor-source-not-found-change-attached-source-eclipse/

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-17
        • 1970-01-01
        • 2013-01-05
        相关资源
        最近更新 更多