Skip to content Skip to sidebar Skip to footer

Cannot Cast 'android.view.view' To 'com.example.shabeer.listview.listview'

I get an error in this line here list_view = (ListView)findViewById(R.id.listView_id); shows error inconvertible type; cannot cast android.view.View to com.example.shabeer.list

Solution 1:

Change your class name "ListView" to "OtherName"

publicclassListViewextendsAppCompatActivity {

to

publicclassListViewSampleextendsAppCompatActivity {

Solution 2:

You cannot cast an Android listview to your own listview.

Instead of "com.example.shabeer.listview.ListView" you need a "android.widget.ListView". This is the one you are referencing in your xml layout file.

publicstatic android.widget.ListView list_view;

and

list_view = (android.widget.ListView)findViewById(R.id.listView_id);

Solution 3:

Call listView() method inside onCreate then try, it should work.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list_view);
    listView();
}

Solution 4:

Edit: This would be the answer if your ListView were a View, but now I see that it's actually an Activity. ListView is a very misleading name for an activity class!

Use the fully-qualified class name in your XML:

<com.example.shabeer.listview.ListView
    android:id="@+id/listView_id"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal" />

Otherwise, it will assume you mean android.widget.ListView.

Post a Comment for "Cannot Cast 'android.view.view' To 'com.example.shabeer.listview.listview'"