Saturday, 15 August 2015

java - NullPointException on startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION); -


So I'm using Google Drive tutorials to help understand the basics of interacting with Google Drive and Works fine on code Samsung Ace 2 Android 2.3.6 is running, so I'm able to upload files to my Google Drive location. My point is that when I run the same application running Android 4.2.2 on my Samsung CII, it finds this account and allows me to upload a new file for uploading, but when I crash:

  startActivityForResult (e.getIntent (), REQUEST_AUTHORIZATION);   

Logkat gives me the following:

  03-26 18: 29: 39.686: E / Android Random (6775): Flat exception: Thread-256 03 -26 18: 29: 39.686: E / AndroidRuntime (6775): java.lang.NullPointerException 03-26 18: 29: 39.686: E / AndroidRuntime (6775): android.app.Activity.startActivityForResult (Activity.java: 3370) 03-26 18: 29: 39.686: E / AndroidRuntime (6775): android.app.Activity.startActivityForResult (Activity.java:3331) at 03-26 18: 29: 39.686: E / AndroidRuntime (6775): on 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)   

relevant code

  public zero saveFileToDrive (last string fileName) {th D folder = new thread (New Runnable) {@Override Public Zero Run (try {{Files}. List request = service.files () list () setQ ("MIMETYPE = 'application / vnd.google-apps Folder 'and trashed = false'); Last 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 (); Parent = files. Gadgets (). Obtain (i) .getId (); }}} {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 example file file = service.files (). Insert (body). Execute (); Parent = file.getKind (); Parent = file.getId (); DriveFile = File; Logs. V ("File exists here:", "" + driveFile.getTitle ()); } String mediastorage = "/ sdcard / APP folder /"; FileUri = Uri.fromFile (new java.official (mediastoragedir + java.ofoofail.separator + filename)); // file's binary content java.io.file file resource = new java.io.file (fileUri.getPath ()); FileContent Media Content = New File Resource ("Text / Plain", File Content); // file's metadata file body = new file (); Body.setTitle (fileContent.getName ()); Body.setMimeType ("text / plain"); Body.setParents (Arrays.asList (new parent reference). SetId (parentID)); Final file file1 = service.files (). Insert (body, media content). Execute (); If (file1 = null!) {RunOnUiThread (New Runnable () {@Override Public Zero Run) {Toast.makeText (getApplicationContext (), "File uploaded:" + file.getTitle (), Toast.LENGTH_SHORT). Show (); log.V ("SUCESSFULL UPLOADTO GOOGLEDRIVE", "" + file1.getTitle ());}}); }} Hold (UserRecoverableAuthIOException e) {startActivityForResult (e.getIntent (), REQUEST_AUTHORIZATION); } Hold (IOException e) {e.printStackTrace (); }}}); Folder.start (); }   

What could happen to anyone, what is happening due to this?

I've included the file upload function, where the error occurs.

Thank you in advance for your help.

You like stuff

  last filelive files = request Exempt (); Request.setPageToken (files.getNextPageToken ());   

If you receive a NPE on the second line, then you do not get the file as a result.

You should protect yourself against the incident as a code.

  final file list file = request Exempt (); If (files! = Null) {request.setPageToken (files.getNextPageToken ()); }   

Specifically, for your error, you have to preserve your code in such a way

  if ((e! = Null) Amp; amp; (.getIntent ()! = Null)) {startActivityForResult (e.getIntent (), REQUEST_AUTHORIZATION); } And if (e = = null) {e.printStackTrace (); }    

No comments:

Post a Comment