public class MainActivity extends Activity {
ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_view);
setTitle("First Window");
listView = (ListView) findViewById(R.id.list);
}
This is my code. R.id.List is a ListView in my .xml file. while trying to build project i am getting error on line
listView = (ListView) findViewById(R.id.list); //that is "Cannot cast from View to ListView" please help me.
And my XML file is
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>