0
I’m beginner in java programming, I’m trying to catch a ParseUser
specify and send to the TimeLineFragment
but it’s always null, I’ve done several tests but it’s always null
public class TimeLineFragment extends Fragment {
private ArrayList<ParseObject> feedTL;
//private ArrayAdapter<ParseObject> adapter;
private TimeLineLayout timeLineLayout;
private ListView feedView;
private ArrayList<ParseUser> userArray;
private ParseUser user;
public TimeLineFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_time_line, container, false);
try {
getPost();
feedView = (ListView) view.findViewById(R.id.lista_post);
feedTL = new ArrayList<>();
//adapter = new TimeLineLayout(getActivity(), feedTL);
timeLineLayout = new TimeLineLayout(getActivity(), feedTL);
timeLineLayout.setImageUrl(user);
feedView.setAdapter(timeLineLayout);
}catch (Exception e){
e.printStackTrace();
}
return view;
}
public void getPost() {
ParseQuery<ParseObject> query = new ParseQuery<>("shared");
//query.whereNotEqualTo("userID", ParseUser.getCurrentUser().getObjectId());
query.orderByDescending("createdAt");
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> list, ParseException e) {
if (e == null) {
if (list.size() > 0) {
feedTL.clear();
for (ParseObject parseObject : list) {
feedTL.add(parseObject);
}
timeLineLayout.notifyDataSetChanged();
}
} else {
Toast.makeText(getActivity(), "Erro ao recuperar o feed", Toast.LENGTH_SHORT).show();
}
}
});
userArray = new ArrayList<>();
ParseQuery<ParseUser> userQuery = ParseUser.getQuery();
userQuery.whereEqualTo("objectId", "WHVTz8ZiX2");
userQuery.findInBackground(new FindCallback<ParseUser>() {
@Override
public void done(List<ParseUser> list, ParseException e) {
if (e == null) {
if (list.size() > 0) {
for (ParseUser parseUser : list) {
userArray.add(parseUser);
user = userArray.get(0);
Log.i("user", " " + user.getParseFile("userPic").getUrl());
}
}else{
Log.i("Lista", "size = 0");
}
}else{
Log.i("Erro", "Erro ao recuperar objeto");
}
}
});
}
Timelinelayout.java
public class TimeLineLayout extends ArrayAdapter<ParseObject> {
private Context context;
private ArrayList<ParseObject> post;
private ImageView picUsuario;
private ParseUser imageUrl;
public TimeLineLayout(Context c, ArrayList<ParseObject> objects) {
super(c, 0, objects);
this.context = c;
this.post = objects;
}
public void setImageUrl(ParseUser imageUrl) {
this.imageUrl = imageUrl;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null){
LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.timeline_layout, parent, false);
}
TextView postTitle = (TextView) view.findViewById(R.id.tv_post_titulo);
TextView postConteudo = (TextView) view.findViewById(R.id.tv_post_conteudo);
picUsuario = (ImageView) view.findViewById(R.id.user_picture_post);
ParseObject object = post.get(position);
postTitle.setText(object.get("titulo").toString());
postConteudo.setText(object.get("conteudo").toString());
String userId = object.get("userID").toString();
//-----------RECUPERAR USUÁRIOS-----------------
if (imageUrl == null){
Log.e("imageUrl: ", "null");
}else{
Log.e("imageUrl: ", "Not null");
}
return view;
}
To imageUrl
always of null
, I’m a beginner in programming
Always happens
null
is because its query do not get the results you expect. Is there anyobjectId
forWHVTz8ZiX2
? Confirm the contents ofuserQuery
after theuserQuery.whereEqualTo("objectId", "WHVTz8ZiX2");
– Isac
I also thought it could be this but I’ve done several tests and everything is fine I have in this line of code the exact expected Log. i("user", " " + user.getParseFile("userPic").geturl()); The problem is that when I step to "Timelinelayout" it is null I have tried to pass as String, Parseuser, Arraylist<Parseuser>, and it always gets null, I tried to pass also by the builder, but also always null
– Tiago Kontarski