我正在创建一个应用程序,其中通过parse.com的表listview将从DonAcc列中的表中获取数据(对于donar或acceptors)如果donar那么其用户名将在listview中获取相同的受体。这样做我得到一个错误
FATAL EXCEPTION: main
java.lang.NullPointerException
at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:394)
at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362)
at android.widget.AbsListView.obtainView(AbsListView.java:2045)
我的用户信息表名为“User”,DonAcc字段位于“Data”表中 这是代码
public class Donar_Acceptor_list extends Activity {
ListView listview;
List<ParseObject> ob;
ProgressDialog mProgressDialog;
ArrayAdapter<String> adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.donar_acceptor_list);
new RemoteDataTask().execute();
}
private class RemoteDataTask extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
mProgressDialog = new ProgressDialog(Donar_Acceptor_list.this);
mProgressDialog.setTitle("Parse.com Simple ListView Tutorial");
mProgressDialog.setMessage("Loading...");
mProgressDialog.setIndeterminate(false);
mProgressDialog.show();
}
@Override
protected Void doInBackground(Void... params) {
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Data");
query.orderByDescending("_created_at");
query.whereEqualTo("DonAcc", "donar");
try {
ob = query.find();
} catch (ParseException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
listview = (ListView) findViewById(R.id.list);
adapter = new ArrayAdapter<String>(Donar_Acceptor_list.this,
R.layout.donar_aceptor_discription);
for (ParseObject names : ob) {
adapter.add((String) names.get("username"));
}
// Binds the Adapter to the ListView
listview.setAdapter(adapter);
// Close the progressdialog
mProgressDialog.dismiss();
// Capture button clicks on ListView items
listview.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Intent i = new Intent(Donar_Acceptor_list.this,
Donar_Acceptor_Discription.class);
i.putExtra("name", ob.get(position).getString("name").toString());
startActivity(i);
} }); }}}
//对于描述活动&gt;&gt;
public class Donar_Acceptor_Discription extends Activity {
// Declare Variables
TextView txtname;
String name;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.donar_aceptor_discription);
txtname=(TextView) findViewById(R.id.text);
Intent i = getIntent();
name = i.getStringExtra("name");
txtname = (TextView) findViewById(R.id.text);
txtname.setText(name); } }