mohan babu
mohan babu

Reputation: 1448

Unable to save data to Parse.com cloud service

I am trying to save a file in "Parse.com" in my android application.However,I am being pestered by the following error

  java.lang.IllegalArgumentException: invalid type for value: class java.io.File

Below mentioned is my code:

    protected void onCreate(Bundle savedInstanceState) {

    try {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_activity);
        Parse.enableLocalDatastore(this);
        Parse.initialize(this, "nNDrIDPB8evzutqXnMkLNwV5l0yKm6RHQDshJhLN", "bkIb6fI9RWgezwulCHismlNUeYBz9sNxFaLxf8NB");
        File f = new File("C:\\Users\\rishii\\AndroidStudioProjects\\Introduction\\file_input9.txt");
        FileInputStream fileInputStream = new FileInputStream(f);
        byte fileContent[] = new byte[(int)f.length()];
        fileInputStream.read(fileContent);
        ParseFile parseFile = new ParseFile(fileContent);
        ParseObject dataObject = new ParseObject("file_content!");
        dataObject.put("file",parseFile);
        dataObject.saveInBackground();
        ParseUser.enableAutomaticUser();
        ParseACL defaultACL = new ParseACL();
        ParseACL.setDefaultACL(defaultACL, true);


    }
    catch (Exception e) {
        e.printStackTrace();
    }

I am quite sure that the file path that i have given is correct.Below mentioned is my stacktrace:

 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.rishii.introduction/com.example.rishii.introduction.Main_activity}: java.lang.IllegalArgumentException: invalid type for value: class java.io.File
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
        at android.app.ActivityThread.access$800(ActivityThread.java:135)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5021)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:827)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:643)
        at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.IllegalArgumentException: invalid type for value: class java.io.File
        at com.parse.ParseObject.performPut(ParseObject.java:3152)
        at com.parse.ParseObject.put(ParseObject.java:3139)
        at com.example.rishii.introduction.Main_activity.onCreate(Main_activity.java:77)
        at android.app.Activity.performCreate(Activity.java:5231)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1090)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
        at 
    android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)

            

Any Suggestions are helpful!!!

Upvotes: 0

Views: 92

Answers (1)

RajSharma
RajSharma

Reputation: 1971

In android you can not directly import files from your local system.

You ahve to first save it to sdacrd or copy that text file to raw folder in your android porject.

Then you can save it to anyhwhere usign appropriate apis.

File f = new File("C:\\Users\\rishii\\AndroidStudioProjects\\Introduction\\file_input9.txt

This line is causing problem.

Upvotes: 1

Related Questions