java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ferryfinal/com.example.ferryfinal.Timings}: java.lang.NullPointerException
M 在调用 i 函数时出现空指针异常,即(在Timings.java调用display_all中)我猜。
//评论数据源.java
public List<Comment> display_all()
{
// String args[]={ref_id};
Comment comment=new Comment();
//String q = "SELECT * FROM timings where ref_id = ?";
String q= " select * from timings ";
Cursor cursor=database.rawQuery(q, null);
List<Comment> list = new ArrayList<Comment>();
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
comment = cursorToComment(cursor);
list.add(comment);
cursor.moveToNext();
}
// make sure to close the cursor
// cursor.close();
Log.w(MySQLiteHelper.class.getName(), "in display fn"+comment.get_Ref_Id());
return list;
}
//Route1.java
ferry.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String ref_id="1";
Intent intent = new Intent(Route1.this, Timings.class);
intent.putExtra(EXTRA_MESSAGE, ref_id);
Log.w(MySQLiteHelper.class.getName(),intent.getStringExtra(EXTRA_MESSAGE));
startActivity(intent);
}
});
}
//Timings.java
public class Timings extends Activity {
final CommentsDataSource dt=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_timings);
Intent intent = getIntent();
String message = intent.getStringExtra(Route1.EXTRA_MESSAGE);
Log.w(MySQLiteHelper.class.getName(),message+"hello");
//String message = "1";
List<Comment> values = dt.display_all();
Log.w(MySQLiteHelper.class.getName(),values.toString()+"hello1");
StringBuilder builder = new StringBuilder();
Log.w(MySQLiteHelper.class.getName(),builder+"hello2");
for (Comment c: values)
{
Log.w(MySQLiteHelper.class.getName(),message+"hello3");
builder.append(c.get_Ref_Id()).append(";")
.append(c.get_Starting_From()).append(";")
.append(c.get_Departure_Time()).append(";")
.append(c.get_Destination()).append("_");
Log.w(MySQLiteHelper.class.getName(),builder+"hello4");
}
//tv.setText(builder.toString());
......