I have Created Three Columns "class1" "class2 "class3" in parse server. and retrieving each column to different activity. table
some table fields are empty. So when i retrieve it displays empty field in listview and gives an error "Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference" for undefined field
I know i can just create different classes for each column and retrieve but wondering is there any way to not display the empty field in listview.
Activity.java
public class topics_class1 extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_topics_class1);
final ArrayList<String> topics1 = new ArrayList<>();
final ListView listView = findViewById(R.id.listView_topics_class1);
final ArrayAdapter arrayAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, topics1);
ParseQuery<ParseObject> query = ParseQuery.getQuery("Topics");
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> objects, ParseException e) {
if (e == null){
for (ParseObject topic : objects){
topics1.add(topic.getString("class_2"));
}
listView.setAdapter(arrayAdapter);
}
else {
e.printStackTrace();
}
}
});
}
}
Just skip empty values.
String text = topic.getString("class_2");
if(text != null && !text.isEmpty()) {
//topics1.add(..
}
Update: if you need "empty cell" then assign empty string instead of null:
topics1.add("");