List view crashing

后端 未结 5 1939
迷失自我
迷失自我 2021-01-06 12:48

I am trying to create ListView and fill it with data , but when i launch the application crashes and shows me a message

Unfortunately,…

5条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-06 13:08

    It seem that your layout is out of scope of the code and thus cannot be loaded. When you check the log you can see the error "NullPointerException" which indicates that you are trying to access an object that does not exist.

    Probably it is the line

    ListView  v = (ListView)findViewById(R.id.mylist);
    

    that is not creating the object as you expect. If you put a breakpoint on this line you will see that is is null and by stepping to the next line

    v.setTextFilterEnabled(true);
    

    you will see that the exception occurs here.

    Please check your references and how you invoke the layout in order to get the proper object loading.

提交回复
热议问题