我正在使用片段创建一个项目。当我想创建数据库时,它给我错误的MODE_WORLD_WRITEABLE.while在其他项目中(我不使用片段)它正在工作我是新来的android请给出一个解决方案。
public class AddEmploy extends Fragment {
public AddEmploy(){
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view= inflater.inflate(R.layout.activity_add_employ, container, false);
final EditText name= (EditText)view.findViewById(R.id.etemname);
final EditText position= (EditText)view.findViewById(R.id.etposition);
final EditText contact= (EditText) view.findViewById(R.id.etcontact);
final EditText address= (EditText) view.findViewById(R.id.etaddress);
Button save= (Button) view.findViewById(R.id.btnsave);
save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final SQLiteDatabase db=openOrCreateDatabase("my_database", MODE_WORLD_WRITEABLE, null);
db.execSQL("create table if not exists employ( name varchar(30),position varchar(30)," +
"contact varchar(20),address varchar(30)," +
" date varchar(255)) ;");
Date d=new Date();
//database insert
db.execSQL("insert into employ values('" + name.getText().toString() + "', '" + position.getText().toString() + "'," +
"'" + contact.getText().toString() + "','" + address.getText().toString() + "'," +
"'" + d + "');");
}
});
return view;
}
}