Note that there are some explanatory texts on larger screens.

plurals
  1. PONullPointException on startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION);
    primarykey
    data
    text
    <p>So I am using the Google Drive <a href="https://developers.google.com/drive/quickstart-android" rel="nofollow">QuickStart</a> tutorial to help me understand the basics of interacting with Google Drive and the code works fine on a Samsung Ace 2 running Android 2.3.6 so I am able to upload files to my Google Drive space. My issue is when I run the same application on my Samsung SII running Android 4.2.2 it finds the account and allows me to create a new file for uploading but crashes on:</p> <pre><code>startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION); </code></pre> <p>LogCat gives me the following : </p> <pre><code>03-26 18:29:39.686: E/AndroidRuntime(6775): FATAL EXCEPTION: Thread-256 03-26 18:29:39.686: E/AndroidRuntime(6775): java.lang.NullPointerException 03-26 18:29:39.686: E/AndroidRuntime(6775): at android.app.Activity.startActivityForResult(Activity.java:3370) 03-26 18:29:39.686: E/AndroidRuntime(6775): at android.app.Activity.startActivityForResult(Activity.java:3331) 03-26 18:29:39.686: E/AndroidRuntime(6775): at com.blitz_labs.Google$3.run(Google.java:209) 03-26 18:29:39.686: E/AndroidRuntime(6775): at java.lang.Thread.run(Thread.java:856) </code></pre> <p>Relevant Code</p> <pre><code>public void saveFileToDrive(final String fileName) { Thread folder = new Thread(new Runnable() { @Override public void run() { try { Files.List request = service.files().list().setQ("mimeType='application/vnd.google-apps.folder' and trashed=false"); final FileList files = request.execute(); request.setPageToken(files.getNextPageToken()); if (!files.getItems().isEmpty()){ for(int i=0; i &lt; files.getItems().size(); i++){ if(files.getItems().get(i).getTitle().equals("APP FOLDER")){ parentKind = files.getItems().get(i).getKind(); parentID = files.getItems().get(i).getId(); } } }else{ File body = new File(); body.setTitle("APP FOLDER"); body.setDescription("App folder"); body.setMimeType("application/vnd.google-apps.folder"); // service is an authorized Drive API service instance File file = service.files().insert(body).execute(); parentKind = file.getKind(); parentID = file.getId(); driveFile = file; Log.v("file EXISTS HERE:",""+driveFile.getTitle()); } String mediaStorageDir = "/sdcard/APP FOLDER/"; fileUri = Uri.fromFile(new java.io.File(mediaStorageDir +java.io.File.separator + fileName)); // File's binary content java.io.File fileContent = new java.io.File(fileUri.getPath()); FileContent mediaContent = new FileContent("text/plain", fileContent); // File's metadata. File body = new File(); body.setTitle(fileContent.getName()); body.setMimeType("text/plain"); body.setParents(Arrays.asList(new ParentReference().setId(parentID) )); final File file1 = service.files().insert(body, mediaContent).execute(); if (file1 != null) { runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext() , "file uploaded: " + file.getTitle(), Toast.LENGTH_SHORT).show(); Log.v("SUCESSFULL UPLOADTO GOOGLEDRIVE",""+file1.getTitle()); } }); } } catch (UserRecoverableAuthIOException e) { startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION); } catch (IOException e) { e.printStackTrace(); } } }); folder.start(); } </code></pre> <p>Does anyone have any ideas to what maybe causing this?</p> <p>I have included the file upload function where the error gets generated.</p> <p>Thank you in advance, for your help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload