简体   繁体   中英

Uploading and Saving the Video file using Parse API was unsuccessful in Android

- I am using Parse api to upload and save the video file to the Parse.com Server for an application.

- I am at present using the following code from Parse Documentation to upload the video file to the Parse Server:

    File f = new File("/sdcard/video-2013-02-21-13-03-24.mp4");

    byte[] videoUp = IOUtils.toByteArray( new FileInputStream(f));


    ParseFile file = new ParseFile("testVideo1", videoUp);




    file.saveInBackground(new SaveCallback() {


        public void done(ParseException e) {

      e.printStackTrace();

     }

     }, new ProgressCallback() {

     public void done(Integer percentDone) {

     System.out.println("Progress :" + percentDone);
      }
     });

- At first its printing progress 100 % which is the resultant of System.out.println statement from done() method with Integer as parameter, and immediately after that its going into the method done() with ParseException as the parameter printing the following stack trace.

FATAL EXCEPTION: main
java.lang.NullPointerException
at com.example.uploadfileusingparse.MainActivity$1$1.done(MainActivity.java:63)
at com.parse.SaveCallback.internalDone(SaveCallback.java:42)
at com.parse.SaveCallback.internalDone(SaveCallback.java:29)
at com.parse.BackgroundTask.onPostExecute(BackgroundTask.java:50)
at com.parse.BackgroundTask.onPostExecute(BackgroundTask.java:16)
at android.os.AsyncTask.finish(AsyncTask.java:417)
at android.os.AsyncTask.access$300(AsyncTask.java:127)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4633)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)

- Parse has given detailed tutorials and info about the IPhone Integration, but i didn't find any tutorial explaining that in Android .

- Can anyone please give me a tutorial explaining the integration of Parse Api into the application to upload the multimedia files to the Parse Server.

You are getting the error because you are trying to call a method from a null variable. If the saveInBackground() is successful by right the ParseException in done(ParseException e) will be null. Fix it by doing a check if the ParseException is null:

  public void done(ParseException e) {
      if(e==null) {
          // SUCCESS!!!
      } else {
          e.printStackTrace();
      }
  }

This applies to all ParseObject methods with names ending with *inBackground

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM