我正在尝试使用parse但是parse告诉我要将第一个代码包含到项目中以检查数据是否被转移....我的应用程序崩溃...
然后我按照堆栈溢出的解决方案解释了如何在单独的类中初始化解析并将其包含在清单文件中...但是在我关注它之后...我的应用程序仍然无效...它每次都崩溃..
Android清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.parseexample"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="21" />
<application
android:name=".Initializeparse"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.java
package com.example.parseexample;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ParseObject testObject = new ParseObject("TestObject");
testObject.put("foo", "bar");
testObject.saveInBackground();
}
}
这是我的 parseexample.java
package com.example.parseexample;
import com.parse.Parse;
import android.app.Application;
public class Initializeparse extends Application{
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
Parse.enableLocalDatastore(getApplicationContext());
Parse.initialize(getApplicationContext(), "lUdLAC7d7HXQfdv1g7SO0T70jcc6vIMIHJRlYEvE", "ObFeYoJE3dqJmxMSfMkCQx37MvAqQfrNvnXHr38v");
}
}
logcat的
08-14 05:07:48.569: D/HyLog(3996): I : /data/font/config/sfconfig.dat, No such file or directory (2)
08-14 05:07:48.569: D/HyLog(3996): I : /data/font/config/dfactpre.dat, No such file or directory (2)
08-14 05:07:48.569: D/HyLog(3996): I : /data/font/config/sfconfig.dat, No such file or directory (2)
08-14 05:07:48.579: I/dalvikvm(3996): Could not find method com.parse.Parse.initialize, referenced from method com.example.parseexample.Initializeparse.onCreate
08-14 05:07:48.579: W/dalvikvm(3996): VFY: unable to resolve static method 19: Lcom/parse/Parse;.initialize (Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;)V
08-14 05:07:48.579: D/dalvikvm(3996): VFY: replacing opcode 0x71 at 0x0007
08-14 05:07:48.579: D/AndroidRuntime(3996): Shutting down VM
08-14 05:07:48.579: W/dalvikvm(3996): threadid=1: thread exiting with uncaught exception (group=0x41a00e48)
08-14 05:07:48.579: E/AndroidRuntime(3996): FATAL EXCEPTION: main
08-14 05:07:48.579: E/AndroidRuntime(3996): Process: com.example.parseexample, PID: 3996
08-14 05:07:48.579: E/AndroidRuntime(3996): java.lang.NoClassDefFoundError: com.parse.Parse
08-14 05:07:48.579: E/AndroidRuntime(3996): at com.example.parseexample.Initializeparse.onCreate(Initializeparse.java:14)
08-14 05:07:48.579: E/AndroidRuntime(3996): at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
08-14 05:07:48.579: E/AndroidRuntime(3996): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4432)
08-14 05:07:48.579: E/AndroidRuntime(3996): at android.app.ActivityThread.access$1500(ActivityThread.java:142)
08-14 05:07:48.579: E/AndroidRuntime(3996): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1263)
08-14 05:07:48.579: E/AndroidRuntime(3996): at android.os.Handler.dispatchMessage(Handler.java:102)
08-14 05:07:48.579: E/AndroidRuntime(3996): at android.os.Looper.loop(Looper.java:136)
08-14 05:07:48.579: E/AndroidRuntime(3996): at android.app.ActivityThread.main(ActivityThread.java:5120)
08-14 05:07:48.579: E/AndroidRuntime(3996): at java.lang.reflect.Method.invokeNative(Native Method)
08-14 05:07:48.579: E/AndroidRuntime(3996): at java.lang.reflect.Method.invoke(Method.java:515)
08-14 05:07:48.579: E/AndroidRuntime(3996): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
08-14 05:07:48.579: E/AndroidRuntime(3996): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
08-14 05:07:48.579: E/AndroidRuntime(3996): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:1)
添加'Initializeparse parseHelper = new Initializeparse();'在MainActivity的onCreate方法中。
答案 1 :(得分:0)
在Initializeparse类中使用这样的方法。
Parse.enableLocalDatastore(this);
Parse.initialize(this, "lUdLAC7d7HXQfdv1g7SO0T70jcc6vIMIHJRlYEvE", "ObFeYoJE3dqJmxMSfMkCQx37MvAqQfrNvnXHr38v");