老师让我们做的是一个安卓学生成绩管理系统
我创建了一个学生类表 有stuid stuname stusex wuli shuxue yingyu jisuanji
就是四科成绩加上一些个人信息
然后我现在想通过插入五条数据 先显示他们5个人的名字
然后通过名字点击item跳转到他们的详细信息ACTIVITY
但是!!
崩溃啊!!
我自己研究了4天都没弄好才敢上来问啊
这对我很重要啊 希望大神表要吝啬教小弟啊
现在贴一下主函数list 的代码
public class list extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DBHelper helper = new DBHelper(this,null,null,1);
SQLiteDatabase database = helper.getWritableDatabase();
database.execSQL("INSERT INTO Student VALUES (stuid,stuname,stusex,wuli,shuxue,yingyu,shuxue)", new Object[]{131,"小红","女",88,77,85,46});
database.execSQL("INSERT INTO Student VALUES (?,?,?,?,?,?,?)", new Object[]{10002,"小红","女",88,77,85,46});
database.execSQL("INSERT INTO Student VALUES (?,?,?,?,?,?,?)", new Object[]{10003,"小蓝","男",88,78,65,22});
database.execSQL("INSERT INTO Student VALUES (?,?,?,?,?,?,?)", new Object[]{10004,"小绿","男",88,77,55,55});
database.execSQL("INSERT INTO Student VALUES (?,?,?,?,?,?,?)", new Object[]{10005,"小黄","男",88,75,55,98});
database.execSQL("INSERT INTO Student VALUES (?,?,?,?,?,?,?)", new Object[]{10006,"小青","女",88,77,59,82});
String sql = "select * from Student where stuid = ?";
String[] args = {Student.stuid + ""};
Cursor cursor = helper.getReadableDatabase().rawQuery(sql, args);
while (cursor.moveToNext()) {
Student student = new Student();
student.setId(cursor.getInt(0));
}
helper.close();
}
@Override
public void onListItemClick(ListView parent,View v, int position, long id){
super.onListItemClick(parent, v, position, id);
Intent intent=new Intent();
if (0==position){
intent.setClass(list.this,MainActivity.class);
list.this.startActivity(intent);
list.this.finish();
}
}
}详细信息的第二个activity的代码
public class MainActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main
我创建了一个学生类表 有stuid stuname stusex wuli shuxue yingyu jisuanji
就是四科成绩加上一些个人信息
然后我现在想通过插入五条数据 先显示他们5个人的名字
然后通过名字点击item跳转到他们的详细信息ACTIVITY
但是!!
崩溃啊!!
我自己研究了4天都没弄好才敢上来问啊
这对我很重要啊 希望大神表要吝啬教小弟啊
现在贴一下主函数list 的代码
public class list extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DBHelper helper = new DBHelper(this,null,null,1);
SQLiteDatabase database = helper.getWritableDatabase();
database.execSQL("INSERT INTO Student VALUES (stuid,stuname,stusex,wuli,shuxue,yingyu,shuxue)", new Object[]{131,"小红","女",88,77,85,46});
database.execSQL("INSERT INTO Student VALUES (?,?,?,?,?,?,?)", new Object[]{10002,"小红","女",88,77,85,46});
database.execSQL("INSERT INTO Student VALUES (?,?,?,?,?,?,?)", new Object[]{10003,"小蓝","男",88,78,65,22});
database.execSQL("INSERT INTO Student VALUES (?,?,?,?,?,?,?)", new Object[]{10004,"小绿","男",88,77,55,55});
database.execSQL("INSERT INTO Student VALUES (?,?,?,?,?,?,?)", new Object[]{10005,"小黄","男",88,75,55,98});
database.execSQL("INSERT INTO Student VALUES (?,?,?,?,?,?,?)", new Object[]{10006,"小青","女",88,77,59,82});
String sql = "select * from Student where stuid = ?";
String[] args = {Student.stuid + ""};
Cursor cursor = helper.getReadableDatabase().rawQuery(sql, args);
while (cursor.moveToNext()) {
Student student = new Student();
student.setId(cursor.getInt(0));
}
helper.close();
}
@Override
public void onListItemClick(ListView parent,View v, int position, long id){
super.onListItemClick(parent, v, position, id);
Intent intent=new Intent();
if (0==position){
intent.setClass(list.this,MainActivity.class);
list.this.startActivity(intent);
list.this.finish();
}
}
}详细信息的第二个activity的代码
public class MainActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main