0

i want to update my list view after downloading complete but it gives me Nullpointer Exception my code is as per under

try {
                    URL url = new URL(GlobalVariable.Getstr());
                    HttpURLConnection c = (HttpURLConnection) url.openConnection();
                    c.setRequestMethod("GET");
                    c.setDoOutput(true);
                    c.connect();
                       int lenghtOfFile = c.getContentLength();
                       Log.d("ANDRO_ASYNC", "Lenght of file: " + lenghtOfFile);
                    String PATH = Environment.getExternalStorageDirectory()
                            + "/download/";
                    Log.v(LOG_TAG, "PATH: " + PATH);
                    File file = new File(PATH);
                    file.mkdirs();

                    // String fileName = "workTest.mp3";
                    String fileName = GlobalVariable.Getstrpath().toString();

                    File outputFile = new File(file, fileName);
                    FileOutputStream fos = new FileOutputStream(outputFile);

                    InputStream is = c.getInputStream();

                    byte[] buffer = new byte[1024];
//                  int len1 = 0;
                     long total = 0;
//                  while ((len1 = is.read(buffer)) != -1) {
//                      total += len1;
//                      publishProgress(""+(int)((total*100)/lenghtOfFile));
//                      fos.write(buffer, 0, len1);
//                  
                     while ((count = is.read(buffer)) != -1) {
                            total += count;
                            publishProgress(""+(int)((total*100)/lenghtOfFile));
                            fos.write(buffer, 0, len1);

                    }
                    fos.close();
                    is.close();
//                  ArrayAdapter aa=new ArrayAdapter(FindFilesByType.this, android.R.layout.test_list_item,Ringtones);
//                  aa.setNotifyOnChange(true);
//                  lv1.setAdapter(aa);
                    try{

                        ((ArrayAdapter) lv1.getAdapter()).notifyDataSetChanged();

                //      adapter.notifyDataSetChanged();




                    }
                    catch (Exception e) {
                        Log.i(LOG_TAG, "Error: " + e.toString());
                    }



i am getting the

04-28 15:56:17.198: INFO/app(624): Error: java.lang.NullPointerException

what is wrong i am doing?

thanks in advance

1
  • this is my array adapter on create method ArrayAdapter<String> adapter=new ArrayAdapter<String>(FindFilesByType.this, android.R.layout.test_list_item,Ringtones); this.lv1.setAdapter(adapter); Commented Apr 28, 2011 at 10:31

1 Answer 1

1

At which line exception coming.

and use notifyDataSetChanged(); method on adapter rather than lvl.getAdapter(). notifyDataSetChanged();

edited : notifydatasetChange see this

Hope it helps..

Sign up to request clarification or add additional context in comments.

2 Comments

lvl.setAdapter(aa) it showing list..? and data adding is not null right
same error it showing?? that means null is in data your adding to listview.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.