Parse.com检索ParseObject错误

时间:2015-12-27 07:56:14

标签: android json

我正在使用Parse.com并上传了一个小的1kb json文件我的数据存储。现在我想从Parse.com下载它并将其填充到列表视图中,但是我已经失败了,检索文件在这里是我的代码:

public class MainActivity extends AppCompatActivity {
public static final String TAG = MainActivity.class.getSimpleName();


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
Parse.initialize(this);

    ParseQuery<ParseObject> query = ParseQuery.getQuery("testfile");
    query.getInBackground("VaCCc2YCp3", new GetCallback<ParseObject>() {
        public void done(ParseObject object, ParseException e) {
            if (e == null) {
                Log.v(TAG, "SUCCESS");
            } else {
               Log.v(TAG, "FAILURE");
            }
        }
    });
}}

所以不幸的是我的Logcat告诉我:

V/MainActivity: FAILURE

看起来很简单,但我错过了什么?

我的Logcat更新

12-27 03:46:26.504 19736-19736/? D/dalvikvm: Late-enabling CheckJNI
12-27 03:46:26.540 19736-19742/? D/dalvikvm: Debugger has detached; object registry had 1 entries
12-27 03:46:26.552 19736-19736/? W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
12-27 03:46:26.552 19736-19736/? I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.view.WindowCallbackWrapper.onSearchRequested
12-27 03:46:26.552 19736-19736/? W/dalvikvm: VFY: unable to resolve interface method 14609: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
12-27 03:46:26.552 19736-19736/? D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
12-27 03:46:26.552 19736-19736/? I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode
12-27 03:46:26.552 19736-19736/? W/dalvikvm: VFY: unable to resolve interface method 14613: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
12-27 03:46:26.552 19736-19736/? D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
12-27 03:46:26.588 19736-19736/? I/dalvikvm: Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.widget.TintTypedArray.getChangingConfigurations
12-27 03:46:26.588 19736-19736/? W/dalvikvm: VFY: unable to resolve virtual method 438: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
12-27 03:46:26.588 19736-19736/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
12-27 03:46:26.588 19736-19736/? I/dalvikvm: Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.widget.TintTypedArray.getType
12-27 03:46:26.588 19736-19736/? W/dalvikvm: VFY: unable to resolve virtual method 460: Landroid/content/res/TypedArray;.getType (I)I
12-27 03:46:26.588 19736-19736/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
12-27 03:46:26.604 19736-19739/? D/dalvikvm: GC_CONCURRENT freed 204K, 8% free 3334K/3612K, paused 3ms+1ms, total 7ms
12-27 03:46:26.652 19736-19736/? D/libEGL: loaded /system/lib/egl/libEGL_genymotion.so
12-27 03:46:26.668 19736-19736/? D/libEGL: loaded /system/lib/egl/libGLESv1_CM_genymotion.so
12-27 03:46:26.668 19736-19736/? D/libEGL: loaded /system/lib/egl/libGLESv2_genymotion.so
12-27 03:46:26.684 19736-19736/? W/EGL_genymotion: eglSurfaceAttrib not implemented
12-27 03:46:26.688 19736-19736/? E/OpenGLRenderer: Getting MAX_TEXTURE_SIZE from GradienCache
12-27 03:46:26.688 19736-19736/? E/OpenGLRenderer: MAX_TEXTURE_SIZE: 16384
12-27 03:46:26.700 19736-19736/? E/OpenGLRenderer: Getting MAX_TEXTURE_SIZE from Caches::initConstraints()
12-27 03:46:26.700 19736-19736/? E/OpenGLRenderer: MAX_TEXTURE_SIZE: 16384
12-27 03:46:26.700 19736-19736/? D/OpenGLRenderer: Enabling debug mode 0
12-27 03:46:26.720 19736-19739/? D/dalvikvm: GC_CONCURRENT freed 218K, 8% free 3510K/3804K, paused 5ms+3ms, total 10ms
12-27 03:46:27.068 19736-19739/? D/dalvikvm: GC_CONCURRENT freed 326K, 11% free 3577K/3976K, paused 0ms+6ms, total 14ms
12-27 03:46:27.084 19736-19736/? D/AndroidRuntime: Shutting down VM
12-27 03:46:27.084 19736-19736/? W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xa4d2eb20)
12-27 03:46:27.084 19736-19736/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                   Process: softdev1.jsonapp, PID: 19736
                                                   java.lang.RuntimeException: Unable to start activity ComponentInfo{softdev1.jsonapp/softdev1.jsonapp.MainActivity}: java.lang.IllegalStateException: ParsePlugins is already initialized
                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
                                                       at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3724)
                                                       at android.app.ActivityThread.access$900(ActivityThread.java:135)
                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1202)
                                                       at android.os.Handler.dispatchMessage(Handler.java:102)
                                                       at android.os.Looper.loop(Looper.java:136)
                                                       at android.app.ActivityThread.main(ActivityThread.java:5001)
                                                       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:785)
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
                                                       at dalvik.system.NativeStart.main(Native Method)
                                                    Caused by: java.lang.IllegalStateException: ParsePlugins is already initialized
                                                       at com.parse.ParsePlugins.set(ParsePlugins.java:39)
                                                       at com.parse.ParsePlugins$Android.initialize(ParsePlugins.java:153)
                                                       at com.parse.Parse.initialize(Parse.java:191)
                                                       at com.parse.Parse.initialize(Parse.java:161)
                                                       at softdev1.jsonapp.MainActivity.onCreate(MainActivity.java:27)
                                                       at android.app.Activity.performCreate(Activity.java:5231)
                                                       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 
                                                       at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3724) 
                                                       at android.app.ActivityThread.access$900(ActivityThread.java:135) 
                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1202) 
                                                       at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                       at android.os.Looper.loop(Looper.java:136) 
                                                       at android.app.ActivityThread.main(ActivityThread.java:5001) 
                                                       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:785) 
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
                                                       at dalvik.system.NativeStart.main(Native Method) 

1 个答案:

答案 0 :(得分:0)

似乎你错过了很多东西让我提供示例代码

public class StarterApplication extends Application {

  @Override
  public void onCreate() {
    super.onCreate();

    // Enable Local Datastore.
    Parse.enableLocalDatastore(this);

    // Add your initialization code here
    Parse.initialize(this);

    ParseUser.enableAutomaticUser();
    ParseACL defaultACL = new ParseACL();
    // Optionally enable public read access.
    // defaultACL.setPublicReadAccess(true);
    ParseACL.setDefaultACL(defaultACL, true);
  }

并在onCreate

@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ParseAnalytics.trackAppOpenedInBackground(getIntent());
  }

<强> mainfest.xml

<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (c) 2015-present, Parse, LLC.
  ~ All rights reserved.
  ~
  ~ This source code is licensed under the BSD-style license found in the
  ~ LICENSE file in the root directory of this source tree. An additional grant
  ~ of patent rights can be found in the PATENTS file in the same directory.
  -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.parse.starter" >

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <application
        android:name=".StarterApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <meta-data
            android:name="com.parse.APPLICATION_ID"
            android:value="@string/parse_app_id" />
        <meta-data
            android:name="com.parse.CLIENT_KEY"
            android:value="@string/parse_client_key" />

        <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>

strings.xml

<resources>
    <string name="parse_app_id">YOUR_APPLICATION_ID</string>
    <string name="parse_client_key">YOUR_CLIENT_KEY</string>
    ............ 
    .....



</resources>