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?
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.
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.
posted 3 months ago
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:
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database