0

I did not understand the Error i am getting;

enter image description here

my elements declared as following;

ListView listViewLocations;
private ArrayAdapter<String> listAdapter ;
ArrayList<Long> addressList = new ArrayList<Long>();

and inside onCreate;

         listViewLocations = (ListView) findViewById(R.id.listViewLocations);
    ArrayList<Long>  addresses = new ArrayList<>();

then the method displayed in the picture.

In my Stacktrace i made sure to log the final ArrayList by commenting the code and adding the log.i statement in order to confirm the retrieval of Data, and it is logging it as an Array;

 5-08 14:28:06.265 22794-22794/net.we4x4 I/myTag: [20.4203339/84.5712178, 62.4334592/94.5716614, 22.4214592/59.5711114]

Simply i am trying to put this Array in a listView and i followed a simple tutorial on how to do so :

http://windrealm.org/tutorials/android/android-listview.php

Then i tried declaring the ArrayList in a different way;

   ListView listViewLocations;
   private ArrayAdapter<String> listAdapter ;
   ArrayList addressList;

to resolve the redline (error shown in the picture)

and i got this error in my stack trace;

 05-08 15:12:16.790 22349-22349/net.we4x4 E/AndroidRuntime: FATAL EXCEPTION: main
                                                       Process: net.we4x4, PID: 22349
                                                       java.lang.NullPointerException
                                                           at android.widget.ArrayAdapter.getCount(ArrayAdapter.java:330)
                                                           at android.widget.ListView.setAdapter(ListView.java:486)
                                                           at net.we4x4.GPSlocations.listAddresses(GPSlocations.java:228)
                                                           at net.we4x4.GPSlocations.access$000(GPSlocations.java:47)
                                                           at net.we4x4.GPSlocations$1.onClick(GPSlocations.java:93)
                                                           at android.view.View.performClick(View.java:4508)
                                                           at android.view.View$PerformClick.run(View.java:18675)
                                                           at android.os.Handler.handleCallback(Handler.java:733)
                                                           at android.os.Handler.dispatchMessage(Handler.java:95)
                                                           at android.os.Looper.loop(Looper.java:136)
                                                           at android.app.ActivityThread.main(ActivityThread.java:5584)
                                                           at java.lang.reflect.Method.invokeNative(Native Method)
                                                           at java.lang.reflect.Method.invoke(Method.java:515)
                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
                                                           at dalvik.system.NativeStart.main(Native Method)
madnomad10011
  • 341
  • 2
  • 6
  • 19
  • 1
    the conflict is because of the mismatch between the gernic type you declared (String) and the dataset List – Blackbelt May 08 '16 at 11:24
  • Well, indeed the current code the is a mistake in declaration, fixing that i faced another problem which i resolved by fixing the layout, since it stated in the stack trace that a textView need, and it is present in the current layout "rowv_vid" but i had to create another layout with only a textView in it in order for it to pass the data to it. – madnomad10011 May 08 '16 at 12:50

1 Answers1

0

I believe that forgot to create listAdapter

 listAdapter = new ArrayAdapter<string>();
Zamrony P. Juhara
  • 5,222
  • 2
  • 24
  • 40
  • no i am afraid the declaration is present, it was the String assignment of it which conflict with the type of data extracted. fixed that and i had another issue which i resolved as it is explained in my answer. thank you. – madnomad10011 May 08 '16 at 12:52