• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Problems trying to set a ListView inside a OnClickListener using AlertDialog  RSS feed

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi, everybody. I'm new in Android and after doing some programming I'm facing this problem. In line 125 of my code in MainActivityAlertDialog where I set adapter for the listview  lvInternalStorage.setAdapter(adapter); I get this error:
MainActivityAlertDialog: checkInternalStorage: NULLPOINTEREXCEPTION Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
After googling I've found this error is because of line 124 of MainActivityAlertDialog  ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivityAlertDialog.this, android.R.layout.simple_list_item_1, FilePathStrings);
where anonymous onclicklistener cannot be converted to context , so If this is the case. What should I have to do?

I'll appreciate any help.







 
Saloon Keeper
Posts: 5048
135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The important part is

Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference



So "lyInternalStorage" is null. Start by checking after line 51 that it isn't. You posted two layout files, but "lyInternalStorage" is used only in the second - is the "activity_main" layout maybe the first one that doesn't contain it?

anonymous onclicklistener cannot be converted to context


How do you figure? It doesn't say anything about that anywhere.

FileNameStrings


One last thing: Don't use uppercase names for variables. In Java, class names always start with an uppercase letter, but variable names never do. Not following this convention will confuse anyone looking at your code.
 
joe encalada
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Tim thanks for your suggestions. A solve my problem after taken out alertDialog = new AlertDialog.Builder(MainActivityAlertDialog.this); of mostrarPopupRutas and putting it in onCreate method here below the modified code:

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!