title: Displaying PDF files on Android
body: <p>I want load and display PDF files. These files are in a listview and I want display a selected PDF file. This is the code:</p>
  
  <pre><code> public class MainActivity extends ActionBarActivity {
  
          final StringBuffer sb = new StringBuffer();
      private ListView mainListView ;  
          private ArrayAdapter&lt;String&gt; listAdapter ;  
      String filepath;
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_firstactivity);
              mainListView = (ListView) findViewById( R.id.mainListView );  
              final ArrayList&lt;String&gt; List = new ArrayList&lt;String&gt;();  
          final File storage = Environment.getExternalStorageDirectory();
              File file = new File(storage,"/Folder/");
          if (file.exists() &amp;&amp; file.isDirectory()) {
                  for (String s : file.list()) {
                      sb.append(s + " ");
          List.addAll( Arrays.asList(s) );
                  }
              }
  
              listAdapter = new ArrayAdapter&lt;String&gt;(this, R.layout.simplerow, R.id.rowTextView,List); 
              mainListView.setAdapter( listAdapter );  
      mainListView.setOnItemClickListener(new OnItemClickListener() {
          public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3) {
  
                      String filepath = new File("/Folder/"+ List.get(arg2)).getAbsolutePath();
                       File file = new File(filepath);
                      openPdfIntent(file);
  
  
                  }
  
  
              });
          }
          private void openPdfIntent(File file) {
                 Uri path = Uri.fromFile(file);
  
                              Intent pdfIntent = new Intent(Intent.ACTION_VIEW);
                              pdfIntent.setDataAndType(path, "application/pdf");
                              pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                              try {
                                  startActivity(pdfIntent);
                              } catch (Exception e) {
                              e.printStackTrace();
                          }
       }
  </code></pre>
  
  <p>This code doesn't work. The logcat error is : "java.lang.NullPointerException". 
  How can I solve this problem? </p>