解析错误时已达到文件末尾(附加日志)

时间:2015-11-24 06:39:16

标签: java android

我重写了代码并注意到我的ID错了所以将其更改为ListView但我仍然遇到错误...... :(

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    String[] Categories = {"Abstract", "Android", "Apple", "Animals", "Cartoons", "Celebrities",
            "Girls", "Holidays", "Marvel", "Nature", "Sports", "Vehicles"};

    ListAdapter theAdapter = new ArrayAdapter<String>(this, R.layout.row_layout, Categories);

    ListView theListView = (ListView) findViewById(R.id.theListView);

    theListView.setAdapter(theAdapter);

    theListView.setOnItemClickListener(new parent.OnItemClickListener() {
        @Override
        public void onItemClick(parent<?> parent, View view, int position, long id) {

            String categoryPicked = "You Selected " +
                    String.valueOf(parent.getItemAtPosition(position));

            Toast.makeText(MainActivity.this, categoryPicked, Toast.LENGTH_SHORT).show();

         }
    });
}

@Override
public void (onItemClick(parent<?>parent, View view, int position, long id);
{
    String CategoryPicked = "You selected " + String.valueOf(parent.getItemAtPosition(position));
    Toast.makeText(MainActivity.this, CategoryPicked, LENGTH_SHORT).show();
}

1 个答案:

答案 0 :(得分:0)

更改

String CategoryPicked = "You selected " + String.valueOf(adapterView.getItemAtPosition(position));

到:

String CategoryPicked = "You selected " + String.valueOf(parent.getItemAtPosition(position));