如何在ListView中显示Google云端硬盘文件?

时间:2013-09-10 14:07:07

标签: android listview

这就是我想要做的。但是得到错误。当我初始化字符串数组时...“hi”“Hello”只有这两个才会进入listview。但在循环中,当我尝试将文件标题分配给String数组获取错误。详情如下。

     Thread thread = new Thread(new Runnable()
     {
        @Override
            public void run()
            {
                showToast("Cal");
                monthsArray=GetFiles(service);  // Line No 52
            }

     });
     thread.start();

            arrayAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1,                  monthsArray);     
             lv.setAdapter(arrayAdapter);



                public String[] GetFiles(Drive service)
                {
                  ArrayList<String> MyFiles = new ArrayList<String>();
                  String[] nm = null;

                 try {
                   String req= service.files().list().getFields();
                  Files.List request = service.files().list().setQ("mimeType !=     'application/vnd.google-apps.folder'");
                 FileList files = request.execute();
                 for(File file : files.getItems())
              { 
                String field= file.getId();
                String title = file.getTitle();
                nm[i]=title;     //Line No 80;
                MyFiles.add(title); 
              }     
           } catch (IOException e) {
             e.printStackTrace();
            }
                 showToast("sending back.."); 
               return nm;
             }


             Error Details:  Line No 80 and 52

             LogCat
              FATAL EXCEPTION: Thread-10881
              java.lang.NullPointerException
              at com.example.vturesources.pdf.GetFiles(pdf.java:80)
              at com.example.vturesources.pdf$1.run(pdf.java:52)
              at java.lang.Thread.run(Thread.java:841)

0 个答案:

没有答案