Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

new to Android. I get the following message in the debugger perspective:

The source attachment does not contain the source for the file ListView.class You can change the source attachment by clicking the change attached Source Below

Needless to say the app errors. I've tried to change the source attachment to the location path:

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

However, this did not work.

Any thoughts would be much appreciated.

Code is:

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

Thanks!

like image 243
user603695 Avatar asked Feb 04 '11 20:02

user603695


2 Answers

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

Needless to say the app errors.

The debugger is simply saying your stack frame currently highlight in the debugger is in the ListView class and you don't have the source code to be able it in the editor. This certainly is not the cause of your whatever problem you're having with your program. If you find the stackframe that corresponds to your source code, the debugger will happily show you the code corresponding to the stack frame. You could go to the trouble of installing the Android source code, but it won't solve whatever problem you're having with your program.

Please clarify what your program is doing wrong - what are the symptoms other than that message. Please look in LogCat for error messages, exceptions, and stack traces and post them.

like image 109
Bert F Avatar answered Nov 04 '22 13:11

Bert F


If you had the source it would only allow you to step into the source for the operating system classes themselves, which would probably confuse you. To see what your cause is when it stops in the debugger, keep hitting F6 until the variables in the debug perspective show you the exception. It will be something like:

this InvocationTargetException (id=????????)
exception IllegalStateException (id=????????)
cause ClassCastException (id=????????)
detailMessage "ArrayAdapter requires the resource ID to be a TextView" (id=????????)

because I've done this tutorial in the past and know that the line:

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

should be

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

That's the cause

like image 42
NickT Avatar answered Nov 04 '22 12:11

NickT