In android studio, I have a main class where I create a button wherein i create an intent and go to another class called 'listTest' which has a listView in it wherein i add a list adapter to create the list adapter.
However, whenever I click on the button, The app force closes. I have added the manifest permission, tried everything but can't find the error. Here is the code
Main:
public class Main extends AppCompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button b2=(Button)findViewById(R.id.button2);
b2.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Intent intent=new Intent(Main.this,listTest.class);
startActivity(intent);
}
});
}
}
listView:
public class listTest extends ListActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.listtest);
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
getResources().getStringArray(R.array.countries)
));
}
}
XML Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.example.user.uinteraface.listTest">
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="143dp"/>
</RelativeLayout>
LOG Error:
11-18 06:01:43.118 19449-19449/? E/AndroidRuntime: FATAL EXCEPTION: main 11-18 06:01:43.118 19449-19449/? E/AndroidRuntime: Process: com.example.user.uinteraface, PID: 19449 11-18 06:01:43.118 19449-19449/? E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.user.uinteraface/com.example.user.uinteraface.listTest}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'