I'm trying to create simple android runner game with cars, the list of cars is going to be on activity which has a background and a listview in it. The listview having an icon and a string (icon of vehicle and its name) When I'm trying to implement the listview im getting the following exception:
android.content.res.Resources$NotFoundException: Resource ID #0x102000a type #0x12 is not valid
I've looked for answers over stackoverflow and didn't found any. Tried to change the resources, remove the setContentView().
car_list.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp" >
<ImageView
android:id="@+id/logo"
android:layout_width="100px"
android:layout_height="100px"
android:layout_marginLeft="5px"
android:layout_marginRight="20px"
android:layout_marginTop="5px"
android:src="@drawable/bike" >
</ImageView>
<TextView
android:layout_marginStart="100dp"
android:id="@+id/label"
android:text="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:textSize="20sp"
android:textAlignment="center">
</TextView>
</LinearLayout>
activity_cars.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bgpick"
>
<TextView
android:layout_marginTop="20dp"
android:layout_gravity="center"
android:gravity="center"
android:layout_width="350dp"
android:layout_height="wrap_content"
android:text="Pick a vehicle"
android:textStyle="bold"
android:textColor="@color/colorWhite"
android:textSize="40dp"
android:background="@drawable/btns"
android:layout_marginBottom="40dp"
/>
<ListView
android:layout_gravity="center"
android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
ListCarsActivity.java:
public class ListCarsActivity extends Activity {
private CarsArrayAdapter carsArrayAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cars);
final ListView listView=findViewById(android.R.id.list);
String[] CARS = new String[] { "Sport","Tank","Space Ship","Mercedes" };
final ArrayList<String> list=new ArrayList<String>();
for(int i=0;i<CARS.length;++i)
list.add(CARS[i]);
final StableArrayAdapter adapter = new StableArrayAdapter (this,android.R.id.list,list);
listView.setAdapter(adapter);
}
private class StableArrayAdapter extends ArrayAdapter<String> {
HashMap<String, Integer> mIdMap = new HashMap<String, Integer>();
public StableArrayAdapter(Context context, int textViewResourceId,
List<String> objects) {
super(context, textViewResourceId, objects);
for (int i = 0; i < objects.size(); ++i) {
mIdMap.put(objects.get(i), i);
}
}
@Override
public long getItemId(int position) {
String item = getItem(position);
return mIdMap.get(item);
}
@Override
public boolean hasStableIds() {
return true;
}
}
}
I have no idea why I'm getting the exception, i made triple sure that all resources are located and being named the same. Thank you for assisting.