您好我是新解析并成功创建了友谊表。现在我正在尝试检索已请求成为ParseUser B的朋友的Parseuser A.但是我收到错误说java.lang.IllegalStateException: ParseObject has no data for 'username'. Call fetchIfNeeded() to get the data.
基本上我检索请求者信息并尝试在listView中显示为用户可以决定拒绝或接受友谊。请有人能告诉我我做错了什么。我只想在发送请求以添加朋友时显示请求者信息。然后userB可以选择接受或拒绝请求。
private void queryFriendShipRequest() {
//retrieving requesters info to display on a list view
ParseQuery<ParseObject> parseQuery = ParseQuery.getQuery("Friendship");
parseQuery.whereEqualTo("accepterId", ParseUser.getCurrentUser());
parseQuery.whereEqualTo("Status", "pending");
parseQuery.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
parseUserList.clear();
for (ParseObject parseObject : objects) {
parseUserList.add((FriendShip) parseObject);
// Log.d("FriendShip", parseUserList.toString());
}
updateFriendsList();
}
else {
Log.d(TAG, "Unable to retreive Invites: " + e.getMessage());
}
}
});
}
private void updateFriendsList() {
ArrayAdapter adapter = new ArrayAdapter(getActivity(), R.layout.friend_request_list, parseUserList) {
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// return super.getView(position, convertView, parent);
if(convertView==null) {
convertView = getActivity().getLayoutInflater().inflate(R.layout.friend_request_list, parent, false);
}
ProfilePictureView profilePictureView1 = (ProfilePictureView)convertView.findViewById(R.id.userProfileName11);
TextView textView = (TextView)convertView.findViewById(R.id.IDNameOfPerson);
Button button = (Button)convertView.findViewById(R.id.accept);
Button button1 = (Button)convertView.findViewById(R.id.reject);
profilePictureView1.setProfileId(parseUserList.get(position).getFrom().getString("UserId); //errors complaining it cannot retrieve parseuser
textView.setText(parseUserList.get(position).getFrom().getUsername()); //errors complaining it cannot retrieve parseuser
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
acceptFriendRequest(position);
}
});
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//rejectFriendRequest(position);
}
});
return convertView;
}
};
friendsList.setAdapter(adapter);
}
我的错误:
12-06 17:26:20.236 18468-18468/com.example.davchen.skibuddies E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.davchen.skibuddies, PID: 18468
java.lang.IllegalStateException: ParseObject has no data for 'username'. Call fetchIfNeeded() to get the data.
at com.parse.ParseObject.checkGetAccess(ParseObject.java:3513)
at com.parse.ParseObject.getString(ParseObject.java:3089)
at com.parse.ParseUser.getUsername(ParseUser.java:373)
at com.example.davchen.skibuddies.Fragments.ProfileTab$2.getView(ProfileTab.java:114)
at android.widget.AbsListView.obtainView(AbsListView.java:2823)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1290)
at android.widget.ListView.onMeasure(ListView.java:1202)
at android.view.View.measure(View.java:18596)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5827)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1435)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:721)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:612)
at android.view.View.measure(View.java:18596)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1489)
at android.view.View.measure(View.java:18596)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5827)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1435)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:721)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:612)
at android.view.View.measure(View.java:18596)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5827)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
at android.support.v7.internal.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:124)
at android.view.View.measure(View.java:18596)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5827)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1435)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:721)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:612)
at android.view.View.measure(View.java:18596)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5827)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
at android.view.View.measure(View.java:18596)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5827)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1435)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:721)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:612)
at android.view.View.measure(View.java:18596)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5827)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2897)
at android.view.View.measure(View.java:18596)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2248)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1306)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1548)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1191)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6642)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:777)
at android.view.Choreographer.doCallbacks(Choreographer.java:590)
at android.view.Choreographer.doFrame(Choreographer.java:560)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:763)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
答案 0 :(得分:1)
解决了它。我所要做的就是使用include来访问requesterId。
query.include("requesterId");