我正在尝试从parse.com检索另一个用户的信息。我需要获取“位置”,它是用户在注册时放入的解析对象的一部分。
@Override
public void onListItemClick(ListView l, View v, final int position, long id) {
super.onListItemClick(l, v, position, id);
// String user = mCurrentUser.getObjectId();
Object o = getListView().getItemAtPosition(position);
String user = (String) o;
final ParseObject newUser = mUser.getParseObject(user);
String objId = newUser.getObjectId();
query.getInBackground(objId, new GetCallback<ParseUser>() {
@Override
public void done(ParseUser user, ParseException e) {
if (e == null) {
// String str = (String)
// ParseUser.getCurrentUser().get("Location");
Object o = getListView().getItemAtPosition(position);
String str = (String) o;
String loc = (String) newUser.get("Location");
Toast.makeText(Friends.this, "Location of " + str + " is " + loc,
Toast.LENGTH_LONG).show();
ParseUser.getCurrentUser().saveInBackground();
}
}
});
正如您所看到的,我正在尝试检索用户对象ID,但由于某种原因,它似乎无法获得用户位置。
更新:从下面的其中一条评论我调试过,String o
肯定会返回一个字符串。我会对此表示赏心悦目,但我没有足够的代表......
第127行是:
final ParseObject newUser = mUser.getParseObject(user);
logcat:
09-14 18:07:56.071: E/AndroidRuntime(24912): FATAL EXCEPTION: main
09-14 18:07:56.071: E/AndroidRuntime(24912): Process: com.kooknluke.wingman, PID: 24912
09-14 18:07:56.071: E/AndroidRuntime(24912): java.lang.NullPointerException
09-14 18:07:56.071: E/AndroidRuntime(24912): at com.kooknluke.wingman.Friends.onListItemClick(Friends.java:127)
09-14 18:07:56.071: E/AndroidRuntime(24912): at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
09-14 18:07:56.071: E/AndroidRuntime(24912): at android.widget.AdapterView.performItemClick(AdapterView.java:308)
09-14 18:07:56.071: E/AndroidRuntime(24912): at android.widget.AbsListView.performItemClick(AbsListView.java:1478)
09-14 18:07:56.071: E/AndroidRuntime(24912): at android.widget.AbsListView$PerformClick.run(AbsListView.java:3480)
09-14 18:07:56.071: E/AndroidRuntime(24912): at android.widget.AbsListView$3.run(AbsListView.java:4823)
09-14 18:07:56.071: E/AndroidRuntime(24912): at android.os.Handler.handleCallback(Handler.java:733)
09-14 18:07:56.071: E/AndroidRuntime(24912): at android.os.Handler.dispatchMessage(Handler.java:95)
09-14 18:07:56.071: E/AndroidRuntime(24912): at android.os.Looper.loop(Looper.java:157)
09-14 18:07:56.071: E/AndroidRuntime(24912): at android.app.ActivityThread.main(ActivityThread.java:5356)
09-14 18:07:56.071: E/AndroidRuntime(24912): at java.lang.reflect.Method.invokeNative(Native Method)
09-14 18:07:56.071: E/AndroidRuntime(24912): at java.lang.reflect.Method.invoke(Method.java:515)
09-14 18:07:56.071: E/AndroidRuntime(24912): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
09-14 18:07:56.071: E/AndroidRuntime(24912): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
09-14 18:07:56.071: E/AndroidRuntime(24912): at dalvik.system.NativeStart.main(Native Method)