I'm receiving this message when launching my code, i have tried to use other answers but none seem to work for me, here is my Xml code for contents.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/GamesURL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="@+id/GameName"
android:layout_alignLeft="@+id/GameName"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignRight="@+id/GameName"
android:layout_alignStart="@+id/GameName"
android:layout_below="@+id/GameName"
android:text="URL" />
<ImageView
android:id="@+id/GamesImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:contentDescription="GameDiscrip"
android:src="@drawable/destiny" />
<TextView
android:id="@+id/GameName"
style="GameName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/ivCard"
android:layout_marginLeft="22dp"
android:layout_marginStart="22dp"
android:layout_toEndOf="@+id/GamesImage"
android:layout_toRightOf="@+id/GamesImage"
android:text="Game_name" />
<ListView
android:id="@id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="multipleChoice"
android:drawSelectorOnTop="false" />
Then this is my code for UseCustomAdapter.java:
public class UseCustomAdapter extends ListActivity {
ArrayList<Games> Games = new ArrayList<Games>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
registerForContextMenu(getListView());
setContentView(R.layout.scrollable_contents);
ScrollView scrollable_contents = (ScrollView) findViewById(R.id.scrollableContents);
getLayoutInflater().inflate(R.layout.contents, scrollable_contents);
Games.add(new Games("Destiny", "Xbox360",
"http://www.graingergames.co.uk/destiny"));
Games.add(new Games("Saints Row", "Xbox360",
"http://www.graingergames.co.uk/games/xbox-360/xt1490-saints-row-iv"));
Games.add(new Games("Batman", "Xbox360",
"http://www.graingergames.co.uk/games/xbox-360/xt1508-batman-arkham-origins"));
Games.add(new Games("BattleField Hardline", "Xbox360",
"http://www.graingergames.co.uk/games/xbox-360/xt1663-battlefield-hardline"));
Games.add(new Games("Dynasty Warriors 8", "Xbox360",
"http://www.graingergames.co.uk/games/xbox-360/xt1501-dynasty-warriors-8"));
Games.add(new Games("DragonBall Xenoverse", "Xbox360",
"http://www.graingergames.co.uk/games/xbox-360/xt1677-dragon-ball-xenoverse"));
ListView lv = getListView();
CustomAdapter adapter = new CustomAdapter(this, Games);
setListAdapter(adapter);
}
protected void onListItemClick(ListView lv, View v, int position, long id) {
super.onListItemClick(lv, v, position, id);
Games G = Games.get(position);
Toast.makeText(this, "User selected: " + G.getGamesTitle(),
Toast.LENGTH_SHORT).show();
}
My code was running properly until i started adding in scroll view but adding that in should not return this kind exception as it has nothing to do with the actual list attribute, if you require to see my additional java or xml files that this code refer to then just ask thanks.
Update
Both android:id="@id/android:list"
to android:id="@android:id/list
do not fix error.
This is the logcat messages im receiving for android:id="@android:id/list :
03-15 09:40:18.050: E/AndroidRuntime(961): FATAL EXCEPTION: main
03-15 09:40:18.050: E/AndroidRuntime(961): Process: com.Lewis.c3383583task2, PID: 961
03-15 09:40:18.050: E/AndroidRuntime(961): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.Lewis.c3383583task2/com.Lewis.c3383583task2.UseCustomAdapter}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
03-15 09:40:18.050: E/AndroidRuntime(961): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
03-15 09:40:18.050: E/AndroidRuntime(961): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
03-15 09:40:18.050: E/AndroidRuntime(961): at android.app.ActivityThread.access$800(ActivityThread.java:135)
03-15 09:40:18.050: E/AndroidRuntime(961): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
03-15 09:40:18.050: E/AndroidRuntime(961): at android.os.Handler.dispatchMessage(Handler.java:102)
03-15 09:40:18.050: E/AndroidRuntime(961): at android.os.Looper.loop(Looper.java:136)
03-15 09:40:18.050: E/AndroidRuntime(961): at android.app.ActivityThread.main(ActivityThread.java:5017)
03-15 09:40:18.050: E/AndroidRuntime(961): at java.lang.reflect.Method.invokeNative(Native Method)
03-15 09:40:18.050: E/AndroidRuntime(961): at java.lang.reflect.Method.invoke(Method.java:515)
03-15 09:40:18.050: E/AndroidRuntime(961): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-15 09:40:18.050: E/AndroidRuntime(961): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-15 09:40:18.050: E/AndroidRuntime(961): at dalvik.system.NativeStart.main(Native Method)
03-15 09:40:18.050: E/AndroidRuntime(961): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
03-15 09:40:18.050: E/AndroidRuntime(961): at android.app.ListActivity.onContentChanged(ListActivity.java:243)
03-15 09:40:18.050: E/AndroidRuntime(961): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:293)
03-15 09:40:18.050: E/AndroidRuntime(961): at android.app.Activity.setContentView(Activity.java:1929)
03-15 09:40:18.050: E/AndroidRuntime(961): at com.Lewis.c3383583task2.UseCustomAdapter.onCreate(UseCustomAdapter.java:31)
03-15 09:40:18.050: E/AndroidRuntime(961): at android.app.Activity.performCreate(Activity.java:5231)
03-15 09:40:18.050: E/AndroidRuntime(961): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
03-15 09:40:18.050: E/AndroidRuntime(961): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
03-15 09:40:18.050: E/AndroidRuntime(961): ... 11 more