每次按保存按钮更新数据或删除电影详细信息时,我的应用程序都会崩溃,我不知道为什么。这是一些信息:我向我的数据库添加了一些数据(那部分工作正常),并且我设法在自定义列表视图中从数据库中显示。现在,在列表视图上的单击事件中,我想从数据库中提取数据,获取数据和在字段中设置的部分工作正常,但是当我想更新或删除时,应用程序崩溃。
请帮忙。
这是我的代码:
主活动.java
public class MainActivity extends AppCompatActivity {
DBAdapter db;
SimpleCursorAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
db = new DBAdapter(this);
db.open();
ListView lv = (ListView) findViewById(R.id.listView1);
int layoutstyle=R.layout.liststyle;
int[] xml_id = new int[] {
R.id.txtname,
R.id.txtnumber,
R.id.textView2
};
String[] column = new String[] {
"naziv",
"zanr",
"rejting"
};
Cursor row = db.fetchAllData();
adapter = new SimpleCursorAdapter(this, layoutstyle,row,column, xml_id, 0);
lv.setAdapter(adapter);
//onClick function
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) {
Cursor row = (Cursor) adapterview.getItemAtPosition(position);
String _id = row.getString(row.getColumnIndexOrThrow("_id"));
String naziv = row.getString(row.getColumnIndexOrThrow("naziv"));
String zanr = row.getString(row.getColumnIndexOrThrow("zanr"));
String glumci = row.getString(row.getColumnIndexOrThrow("glumci"));
Float rejting = row.getFloat(row.getColumnIndexOrThrow("rejting"));
//go to detailsContact page
Intent todetais = new Intent(MainActivity.this, DetailsMovie.class);
todetais.putExtra("ID",_id);
todetais.putExtra("NAZIV", naziv);
todetais.putExtra("ZANR",zanr);
todetais.putExtra("GLUMCI",glumci);
todetais.putExtra("REJTING",rejting);
startActivity(todetais);
}
});
繁花如伊
小怪兽爱吃肉
拉丁的传说
相关分类