-1

I am trying to put ListView and TextView in same layout and I managed to do so but on executing the application I got some errors. Below is the xml code `

    <ListView
        android:id="@+id/lvCourses"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="40" >
    </ListView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="60"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/tvHOD"
            android:layout_width="wrap_content"
            android:layout_height="48dp"
            android:text="Output here" />
    </LinearLayout>

</LinearLayout>

Here is the JAVA code

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.teacher);
    Courses = (ListView) findViewById(R.id.lvCourses);
    Output = (TextView) findViewById(R.id.tvHOD);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, android.R.id.text1,      Names);
    Courses.setAdapter(adapter);
    Courses.setOnItemClickListener(this);
}

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {

    Output.setText(HOD[arg2]);

}

Here is the logcat screenshot

enter image description here

Logcat says the error is in onCreate function but on seeing code I can't understand everything looks fine. Need help please.

Charuක
  • 12,953
  • 5
  • 50
  • 88
Ashish Pal
  • 43
  • 2
  • 9

1 Answers1

2

In the logcat output, you can single out:

Your content must have a ListView whose id attribute is 'android.R.id.list'

Have you missed this line? This might be the problem. Just check it out.

So, this is the solution:

< ListView android:id="@android:id/list" >

varun
  • 2,027
  • 1
  • 15
  • 17