i have made this array column in parse.com dashboard.i am able to add values in the array from my app but m not able to get the array or list and using any function on it(even size() ) give null point exception on that line.
i have used many solutions but none worked.
my code where it is giving error.
real = (TextView) v.findViewById(R.id.realtext);
fake = (TextView) v.findViewById(R.id.faketext);
realbutton = (ImageButton) v.findViewById(R.id.realbutton);
fakebutton = (ImageButton) v.findViewById(R.id.fakebutton);
real.setText(String.valueOf(news.getRealvote()));
fake.setText(String.valueOf(news.getFake()));
fakebutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
news.setuserArray(news.getAuthor().getUsername());
List<ParseObject> a = news.getUserArray();
Toast.makeText(c, a.toString(), Toast.LENGTH_SHORT).show();//any thing with a.size() etc anything gives error
news.setFake();
news.saveInBackground();
fake.setText(String.valueOf(news.getFake()));
realbutton.setVisibility(View.GONE);
fakebutton.setVisibility(View.GONE);
}
});
here is my getUserArray() method
public List<ParseObject> getUserArray() {
return getList("users_rated");
}
the method to store data is working
public void setuserArray(String file) {
addUnique("users_rated", file);
}
i have tried a lot but no success.plss help me retrieving the array.
are you asking for list adapter??
public class Customnewslistview extends ParseQueryAdapter<News> {
Context c;
public Customnewslistview(Context context) {
super(context, "News");
c = context;
}
@Override
public View getItemView(final News news, View v, ViewGroup parent) {
if (v == null) {
final TextView real;
final TextView fake;
final ImageButton realbutton;
final ImageButton fakebutton;
final ProgressBar loader;
v = View.inflate(getContext(), R.layout.item_list_news_public, null);
loader = (ProgressBar) v.findViewById(R.id.eachnewsloder);
ParseImageView newsImage = (ParseImageView) v
.findViewById(R.id.icon);
ParseFile photoFile = news.getParseFile("photo");
if (photoFile != null) {
newsImage.setParseFile(photoFile);
newsImage.loadInBackground(new GetDataCallback() {
@Override
public void done(byte[] data, ParseException e) {
Log.d("done pic", data.toString());
loader.setVisibility(View.GONE);
}
});
} else {
loader.setVisibility(View.GONE);
newsImage.setBackgroundResource(R.drawable.image40);
}
TextView titleTextView = (TextView) v.findViewById(R.id.text1);
titleTextView.setText(news.getTitle());
// trying real fake buttons
real = (TextView) v.findViewById(R.id.realtext);
fake = (TextView) v.findViewById(R.id.faketext);
realbutton = (ImageButton) v.findViewById(R.id.realbutton);
fakebutton = (ImageButton) v.findViewById(R.id.fakebutton);
real.setText(String.valueOf(news.getRealvote()));
fake.setText(String.valueOf(news.getFake()));
realbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
news.setuserArray(news.getAuthor().toString());
news.setRealvote();
news.saveInBackground();
real.setText(String.valueOf(news.getRealvote()));
Toast.makeText(getContext(), "No Cheating",
Toast.LENGTH_SHORT).show();
realbutton.setVisibility(View.GONE);
fakebutton.setVisibility(View.GONE);
}
});
fakebutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
news.setuserArray(news.getAuthor().getUsername());
List<ParseObject> a=null;
try {
a = news.fetchIfNeeded().getList("users_rated");
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Toast.makeText(c, a.toString(), Toast.LENGTH_SHORT).show();
news.setFake();
news.saveInBackground();
fake.setText(String.valueOf(news.getFake()));
realbutton.setVisibility(View.GONE);
fakebutton.setVisibility(View.GONE);
}
});
titleTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Dialog d = new Dialog(c);
d.setContentView(R.layout.publicnewsdialog);
d.setTitle("News");
TextView text = (TextView) d.findViewById(R.id.dialogtext);
text.setText(news.getTitle());
// parsing image
ParseImageView newsImage = (ParseImageView) d
.findViewById(R.id.dialogimage);
ParseFile photoFile = news.getParseFile("photo");
if (photoFile != null) {
newsImage.setParseFile(photoFile);
newsImage.loadInBackground(new GetDataCallback() {
@Override
public void done(byte[] data, ParseException e) {
Log.d("done pic", data.toString());
}
});
} else {
loader.setVisibility(View.GONE);
newsImage.setBackgroundResource(R.drawable.image40);
}
d.show();
}
});
}
return v;
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…