我试图在 SQLite DB 中插入 Web 服务数据。但它在创建数据库时显示错误。有了这个,我附上了我的代码和错误。
公共类免责声明扩展活动{
GPSTracker gps;
static String latlan;
DatabaseHandler db;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.disclaimer);
/*Getting GPS Location and Address Convertion , Lat and lang*/
gps = new GPSTracker(getApplicationContext());
db = new DatabaseHandler(getApplicationContext());
//db = new DatabaseHandler();
latlan=String.valueOf(gps.getLatitude())+","+String.valueOf(gps.getLongitude());
Global.setlatlan(latlan);
Geocoder geocoder = new Geocoder(this, Locale.ENGLISH);
try {
List<Address> address = geocoder.getFromLocation(gps.getLatitude(),gps.getLongitude(), 1);
if(address != null) {
Address returnedAddress = address.get(0);
StringBuilder strReturnedAddress = new StringBuilder("Source Address \n\n");
for(int i=0; i<returnedAddress.getMaxAddressLineIndex(); i++) {
strReturnedAddress.append(returnedAddress.getAddressLine(i)).append("\n");
}
String curadr = strReturnedAddress.toString();
Global.setCurrAddress(curadr);
}
else{
Global.setCurrAddress("No Address Defined");
}
}
catch (IOException e)
{
e.printStackTrace();
}
/*Getting Device ID */
TelephonyManager mTelephonyMgr;
mTelephonyMgr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String devno = mTelephonyMgr.getDeviceId();
//Global.setDeviceID(devno);
Global.setDeviceID("359462040979303");
/*Calling Setting Service Details */
SettingsService set = new SettingsService();
/*Button Action Activities*/
Button agree = (Button)findViewById(R.id.btnagree);
agree.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
gps = new GPSTracker(Disclaimer.this);
// check if GPS enabled
if(gps.canGetLocation()){
/* Include App Web Service for Settings and Current Location and DB Storage*/
String Settingres = Global.getResult();
//String Settingres =null;
Toast.makeText(getApplicationContext(), Settingres, Toast.LENGTH_LONG).show();
//db = new DatabaseHandler(getApplicationContext());
List<Details> contacts = db.getAllContacts();
//check for setting result
if(Settingres.equals(null)==true)
{
/*Toast.makeText(getApplicationContext(), "check DB", Toast.LENGTH_LONG).show();
boolean val =contacts.isEmpty();
Toast.makeText(getApplicationContext(),String.valueOf(val), Toast.LENGTH_LONG).show();*/
if((contacts.isEmpty())==true)
{
Toast.makeText(getApplicationContext(),"Your Application Settings Not Loaded", Toast.LENGTH_LONG).show();
}
else
{
for (Details cn : contacts) {
String log = "APP ID: "+cn.getAPPID()+" ,Unique ID: " + cn.getUniqueID() + " ,Driver Name: " + cn.getDriverName()+ " ,Vehicle Name: " + cn.getVehicleName()+ " ,Mobile number: " + cn.getPhoneNumber();
Log.d("Name: ", log);
// Toast.makeText(getApplicationContext(), log, Toast.LENGTH_LONG).show();
}
}
}
else if(Settingres.equals("Device Not Updated")==true)
{
if((contacts.isEmpty())==true)
{
Toast.makeText(getApplicationContext(),"Your Application Settings Not Loaded.Contact Customer Care", Toast.LENGTH_LONG).show();
}
else
{
for (Details cn : contacts) {
String log = "APP ID: "+cn.getAPPID()+" ,Unique ID: " + cn.getUniqueID() + " ,Driver Name: " + cn.getDriverName()+ " ,Vehicle Name: " + cn.getVehicleName()+ " ,Mobile number: " + cn.getPhoneNumber();
Log.d("Name: ", log);
// Toast.makeText(getApplicationContext(), log, Toast.LENGTH_LONG).show();
}
}
}
else
{
//Store in Setting DB
if((contacts.isEmpty())==true)
{
db.addDetails(new Details(Settingres));
}
else
{
db.dropAllTable(getApplicationContext());
db.addDetails(new Details(Settingres));
}
CurrentTime tim = new CurrentTime();
LocationService curadrloc = new LocationService("App Open");
Intent mainscr = new Intent(Disclaimer.this, MainScreen.class);
startActivity(mainscr);
}
/*List<Details> contacts1 = db.getAllContacts();
for (Details cn : contacts1) {
Global.setAppID(cn.getAPPID());
String log = "APP ID: "+cn.getAPPID()+" ,Unique ID " + cn.getUniqueID() + " ,Driver Name: " + cn.getDriverName()+ " ,Vehicle Name: " + cn.getVehicleName()+ " ,Mobile number: " + cn.getPhoneNumber();
Log.d("Name: ", log);
Toast.makeText(getApplicationContext(), log, Toast.LENGTH_LONG).show();
}
*/
/*// Call current location Service
CurrentTime tim = new CurrentTime();
LocationService curadrloc = new LocationService("App Open");
Intent mainscr = new Intent(Disclaimer.this, MainScreen.class);
startActivity(mainscr);*/
//db.close();
}
else{
gps.showSettingsAlert();
}
}
});
Button disagree =(Button)findViewById(R.id.btndisagree);
disagree.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
finish();
}
});
}
public void currentdetail()
{
Geocoder geocoder = new Geocoder(this, Locale.ENGLISH);
try {
List<Address> address = geocoder.getFromLocation(gps.getLatitude(),gps.getLongitude(), 1);
if(address != null) {
Address returnedAddress = address.get(0);
StringBuilder strReturnedAddress = new StringBuilder("Source Address \n\n");
for(int i=0; i<returnedAddress.getMaxAddressLineIndex(); i++) {
strReturnedAddress.append(returnedAddress.getAddressLine(i)).append("\n");
}
String curadr = strReturnedAddress.toString();
Global.setCurrAddress(curadr);
}
else{
Global.setCurrAddress("No Address Defined");
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
我的错误是
有时像
10-25 11:03:26.580: W/dalvikvm(1101): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
10-25 11:03:26.580: E/AndroidRuntime(1101): Uncaught handler: thread main exiting due to uncaught exception
10-25 11:03:26.585: E/AndroidRuntime(1101): java.lang.ArrayIndexOutOfBoundsException
10-25 11:03:26.585: E/AndroidRuntime(1101): at com.example.routemytrip.Details.<init>(Details.java:22)
10-25 11:03:26.585: E/AndroidRuntime(1101): at com.example.routemytrip.Disclaimer$1.onClick(Disclaimer.java:153)
10-25 11:03:26.585: E/AndroidRuntime(1101): at android.view.View.performClick(View.java:2364)
10-25 11:03:26.585: E/AndroidRuntime(1101): at android.view.View.onTouchEvent(View.java:4179)
10-25 11:03:26.585: E/AndroidRuntime(1101): at android.widget.TextView.onTouchEvent(TextView.java:6540)
10-25 11:03:26.585: E/AndroidRuntime(1101): at android.view.View.dispatchTouchEvent(View.java:3709)
10-25 11:03:26.585: E/AndroidRuntime(1101): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
10-25 11:03:26.585: E/AndroidRuntime(1101): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
10-25 11:03:26.585: E/AndroidRuntime(1101): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
10-25 11:03:26.585: E/AndroidRuntime(1101): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
10-25 11:03:26.585: E/AndroidRuntime(1101): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
10-25 11:03:26.585: E/AndroidRuntime(1101): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
10-25 11:03:26.585: E/AndroidRuntime(1101): at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
10-25 11:03:26.585: E/AndroidRuntime(1101): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
10-25 11:03:26.585: E/AndroidRuntime(1101): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
10-25 11:03:26.585: E/AndroidRuntime(1101): at android.os.Handler.dispatchMessage(Handler.java:99)
10-25 11:03:26.585: E/AndroidRuntime(1101): at android.os.Looper.loop(Looper.java:123)
10-25 11:03:26.585: E/AndroidRuntime(1101): at android.app.ActivityThread.main(ActivityThread.java:4363)
10-25 11:03:26.585: E/AndroidRuntime(1101): at java.lang.reflect.Method.invokeNative(Native Method)
10-25 11:03:26.585: E/AndroidRuntime(1101): at java.lang.reflect.Method.invoke(Method.java:521)
10-25 11:03:26.585: E/AndroidRuntime(1101): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
10-25 11:03:26.585: E/AndroidRuntime(1101): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
10-25 11:03:26.585: E/AndroidRuntime(1101): at dalvik.system.NativeStart.main(Native Method)
10-25 11:03:26.607: I/dalvikvm(1101): threadid=7: reacting to signal 3
10-25 11:03:26.607: E/dalvikvm(1101): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
有时喜欢
10-25 11:03:08.965: E/Database(956): Leak found
10-25 11:03:08.965: E/Database(956): java.lang.IllegalStateException: /data/data/com.example.routemytrip/databases/RouteFetchMgr SQLiteDatabase created and never closed
10-25 11:03:08.965: E/Database(956): at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1694)
10-25 11:03:08.965: E/Database(956): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:738)
10-25 11:03:08.965: E/Database(956): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:760)
10-25 11:03:08.965: E/Database(956): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:753)
10-25 11:03:08.965: E/Database(956): at android.app.ApplicationContext.openOrCreateDatabase(ApplicationContext.java:473)
10-25 11:03:08.965: E/Database(956): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:193)
10-25 11:03:08.965: E/Database(956): at com.example.routemytrip.RouteDBHandler.dropAllTable(RouteDBHandler.java:86)
10-25 11:03:08.965: E/Database(956): at com.example.routemytrip.MainScreen$7.onClick(MainScreen.java:415)
10-25 11:03:08.965: E/Database(956): at android.view.View.performClick(View.java:2364)
10-25 11:03:08.965: E/Database(956): at android.view.View.onTouchEvent(View.java:4179)
10-25 11:03:08.965: E/Database(956): at android.widget.TextView.onTouchEvent(TextView.java:6540)
10-25 11:03:08.965: E/Database(956): at android.view.View.dispatchTouchEvent(View.java:3709)
10-25 11:03:08.965: E/Database(956): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
10-25 11:03:08.965: E/Database(956): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
10-25 11:03:08.965: E/Database(956): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
10-25 11:03:08.965: E/Database(956): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
10-25 11:03:08.965: E/Database(956): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
10-25 11:03:08.965: E/Database(956): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
10-25 11:03:08.965: E/Database(956): at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
10-25 11:03:08.965: E/Database(956): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
10-25 11:03:08.965: E/Database(956): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
10-25 11:03:08.965: E/Database(956): at android.os.Handler.dispatchMessage(Handler.java:99)
10-25 11:03:08.965: E/Database(956): at android.os.Looper.loop(Looper.java:123)
10-25 11:03:08.965: E/Database(956): at android.app.ActivityThread.main(ActivityThread.java:4363)
10-25 11:03:08.965: E/Database(956): at java.lang.reflect.Method.invokeNative(Native Method)
10-25 11:03:08.965: E/Database(956): at java.lang.reflect.Method.invoke(Method.java:521)
10-25 11:03:08.965: E/Database(956): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
10-25 11:03:08.965: E/Database(956): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
10-25 11:03:08.965: E/Database(956): at dalvik.system.NativeStart.main(Native Method)
谁能帮我解决