在这里,我从用户那里获取经度和经度,然后将其转换为整数,这是日志 cat msg 的问题:
无法将 30.01 转换为 int !然后我在数据库中的表中输入纬度和经度:
public class newMission extends Activity
implements OnClickListener{
SQLiteDatabase sql;
EditText e1,e2,e3,e4;
Button b;
MaptoDo obj;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
Intent in =getIntent();
setContentView(R.layout.newmission);
e1=(EditText) findViewById(R.id.edn1);
e2=(EditText) findViewById(R.id.edn2);
e3=(EditText) findViewById(R.id.edn3);
e4=(EditText) findViewById(R.id.edn4);
b=(Button) findViewById(R.id.btnew);
b.setOnClickListener(this);
obj=new MaptoDo();
sql=openOrCreateDatabase("db",0, null);
sql.execSQL("CREATE TABLE Mission" +
"" +
" (emp integer REFERENCES Employee2 (password)," +
"oper_n text,cust_n text,lat double," +
"long double,oper_id integer PRIMARY KEY AUTOINCREMENT)");
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String opN=e1.getText().toString();
String cuN=e2.getText().toString();
String lats=e3.getText().toString();
String lons=e4.getText().toString();
try {
int lat=Integer.parseInt(lats);
int lon=Integer.parseInt(lons);
sql.execSQL("insert into Mission (oper_n,cust_n,lat,long)values('"+opN+"','"+cuN+"',"+lat+","+lon+");");
Toast.makeText(this,"Data Inserted",2000).show();
obj.addMission(lat, lon);
//add to ToDo list too
}catch (NumberFormatException nfe) {
Toast.makeText(this, "Please Enter Valid Data",2000).show();
}}
}