2016-04-03 44 views
1

我试图将应用程序迁移到托管分析server.App启动,但当它试图查询托管分析服务器时它崩溃了。我过去的依赖关系的问题现在我修好了它。应用程序崩溃时,它查询托管分析服务器

如果我使用解析服务,应用程序工作正常。

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 { 
    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' 
} 

错误:

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)  

莫非无法发布整个错误消息,因为这是很长的。我认为解析本地数据存储有问题。据我所知,当我的应用程序指向托管分析服务器时,我只需要添加这几行(appid,clientkey,服务器地址)。应用程序中是否需要进行更多更改?

+0

Parse.enableLocalDatastore(本); // Parse.initialize(this,“”,“”); Parse.initialize(新Parse.Configuration.Builder(本) .applicationId( “APPID”) .clientKey( “ ”) .server(“ http://192.168.1.177:1337/parse/”)/ /'/'在'parse'后很重要 .build()); 你把这段代码放在哪里?它在应用程序中吗? –

+0

是的这段代码是在应用程序中。该应用程序工作正常,如果我保留“Parse.initialize(这,”“,”“);”基本上这一行将解析查询发送到parse.com。一旦我删除这一行,并添加其他参数应用应该向我的托管分析服务器发送查询 – sandy

+0

我的意思是在应用程序类。像这样: public class MyApplication extends Application public void onCreate(){ Parse.enableLocalDatastore(this); Parse.initialize(this,“”,“”); } } –

回答

0

尝试以下操作: Parse.initialize(新Parse.Configuration.Builder(本).applicationId( “yourappid”).clientKey( “yourclientkey”).server( “SERVERURL”).enableLocalDataStore().build ());

+0

这解决了我的问题。非常感谢!! – sandy

0

看起来好像你试图从onClickListener初始化Parse,因此你传递给Parse的对象this是错误的。

如果您从OnClickListener引用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()); 
相关问题