sandy
sandy

Reputation: 93

app crashes when it queries to hosted parse server

I'm trying to migrate app to hosted parse server.App start but when it tries to query to hosted parse server it gets crashed.I had the issue with dependencies in the past now i fixed it.

If i use the parse service the app works fine.

Parse.enableLocalDatastore(this);       
// Parse.initialize(this, "<key>", "<key>");
    Parse.initialize(new Parse.Configuration.Builder(this)
            .applicationId("appid")
            .clientKey("<key>")
            .server("http://192.168.1.177:1337/parse/")   // '/' important after 'parse'
            .build());

Dependencies:

dependencies {
    compile 'com.parse.bolts:bolts-android:1.+'
    compile 'com.parse:parse-android:1.+'
    compile 'com.android.support:cardview-v7:+'
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.google.android.gms:play-services:8.1.0'
}

Error:

04-03 12:44:28.409    2911-2911/com.app.nameapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.app.nameapp, PID: 2911
java.lang.IllegalStateException: Could not execute method of the activity
        at android.view.View$1.onClick(View.java:3823)
        at android.view.View.performClick(View.java:4438)
        at android.view.View$PerformClick.run(View.java:18422)
        at android.os.Handler.handleCallback(Handler.java:733)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5017)
        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:779)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
        at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at android.view.View$1.onClick(View.java:3818)
    at android.view.View.performClick(View.java:4438)
    at android.view.View$PerformClick.run(View.java:18422)
Caused by: java.lang.IllegalStateException: Method requires Local Datastore. Please refer to `Parse#enableLocalDatastore(Context)`.
        at com.parse.ParseQuery.throwIfLDSEnabled(ParseQuery.java:292)
        at com.parse.ParseQuery.throwIfLDSDisabled(ParseQuery.java:286)
        at com.parse.ParseQuery.access$200(ParseQuery.java:90) 

Could not able to post entire error message as it was very long. I think there is something wrong with parse local data store. As far as i know when pointing my app to hosted parse server i just need to add those few lines(appid,clientkey,server address). Is there any more changes needed in the app?     

Upvotes: 1

Views: 412

Answers (2)

thepoosh
thepoosh

Reputation: 12587

It seems like you are trying to initialize Parse from an onClickListener, therefore the object this you are passing to Parse is the wrong one.

if you refer to this from on OnClickListener you get a reference to the interface even though it's an inline declaration in the activity.

you need to manually point to the correct Context and use it.

try changing your code to look like this:

Parse.enableLocalDatastore(MyActivity.this);       
// Parse.initialize(this, "<key>", "<key>");
    Parse.initialize(new Parse.Configuration.Builder(MyActivity.this)
            .applicationId("appid")
            .clientKey("<key>")
            .server("http://192.168.X.XXX:1337/parse/")   // '/' important after 'parse'
            .build());

Upvotes: 0

Davi Mac&#234;do
Davi Mac&#234;do

Reputation: 2984

try the following: Parse.initialize(new Parse.Configuration.Builder(this) .applicationId("yourappid") .clientKey("yourclientkey") .server("serverurl") .enableLocalDataStore() .build() );

Upvotes: 1

Related Questions