从Parse User类中检索电子邮件地址

时间:2015-03-29 00:15:39

标签: android parse-platform

我正在尝试使用objectId从解析数据库中获取用户的电子邮件地址。

ParseQuery query = ParseUser.getQuery();
        query.whereEqualTo("objectId", "EMqw4TOQ0c");
        query.getInBackground("email",new GetCallback() { 
        @Override
        public void done(ParseObject parseObject, ParseException e) {
            email= parseObject.getString("email");
        }
    });
        }
    });

我正在尝试使用getInBackground()方法,但它会出错。

03-29 02:13:33.600  19659-19659/com.parse.starter E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.parse.starter/com.parse.starter.MainActivity}: java.lang.NullPointerException: println needs a message
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
            at android.app.ActivityThread.access$700(ActivityThread.java:159)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:176)
            at android.app.ActivityThread.main(ActivityThread.java:5419)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NullPointerException: println needs a message
            at android.util.Log.println_native(Native Method)
            at android.util.Log.d(Log.java:155)
            at com.parse.starter.Dummy.getEmail(Dummy.java:54)
            at com.parse.starter.MainActivity.onCreate(MainActivity.java:28)
            at android.app.Activity.performCreate(Activity.java:5372)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
            at android.app.ActivityThread.access$700(ActivityThread.java:159)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:176)
            at android.app.ActivityThread.main(ActivityThread.java:5419)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
            at dalvik.system.NativeStart.main(Native Method)

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

试试这个:

ParseQuery<ParseUser> query = ParseUser.getQuery();
        query.getInBackground("EMqw4TOQ0c",new GetCallback<ParseUser>() { 
        @Override
        public void done(ParseUser parseObject, ParseException e) {
            email= parseObject.getEmail();
        }
    });
        }
    });

有三点不同:

  1. getInBackground的第一个参数是对象ID
  2. 查询指定它将返回ParseUser
  3. 有一种获取用户电子邮件地址的特殊方法