问题描述
- 使用Provider传输数据时程序强制Finish
- protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button addData = (Button) findViewById(R.id.add_data);
addData.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Uri uri = Uri.parse(""content://com.example.databasetest.provider/book"");
ContentValues values = new ContentValues();
values.put(""name""A Clash of Kings"");
values.put(""author""George Martin"");
values.put(""pages"" 1040);
values.put(""price"" 22.85);
Uri newUri = getContentResolver().insert(uri values);
newId = newUri.getPathSegments().get(1);
}
});public class MyDatabaseHelper extends SQLiteOpenHelper {public static final String CREATE_BOOK = ""create table Book("" + ""id integer primary key autoincrement + ""author text + ""price real + ""pages integer + ""name text)""; public class MyDatabaseHelper extends SQLiteOpenHelper {public static final String CREATE_BOOK = ""create table Book("" + ""id integer primary key autoincrement + ""author text + ""price real + ""pages integer + ""name text)"";
解决方案
把错误日志贴出来啊,这样看不出来
时间: 2024-10-28 14:33:08