Search code examples
androidlogcat

getting logcat error as cannot be casted


I want to generate a listview from sqlite database but the LOGCAT shows error. What does this below error mean?

09-23 12:01:20.354: E/AndroidRuntime(3682): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.abhishekp.listproduct/com.abhishekp.listproduct.List}: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.ListView

Solution

  • Its Happen only because of..two possibilities.

    1) If you are using TextView in xml file...

    and try to initialize it with.

    TextView tv=(ListView)findViewbyId(R.id.textView);
    

    and if it is right then change it with

    TextView tv=(TextView)findViewbyId(R.id.textView);
    

    2) May be you are trying to put id of listView instead of text view.

    like

    TextView tv=(TextView)findViewbyId(R.id.listView);
    

    if it is then should change

    TextView tv=(TextView )findViewbyId(R.id.textView );
    

    And if it is all good then try to clean your project and rebuild it...

    Thanks!!