我的应用程序正在使用启动服务.在该服务中,我必须从数据库中获取值,但是该应用程序在尝试获取值时崩溃了…
logcat错误在下面列出………..
01-03 22:19:46.097: E/AndroidRuntime(240): FATAL EXCEPTION: main
01-03 22:19:46.097: E/AndroIDRuntime(240): java.lang.RuntimeException: Unable to create service com.androID.antitheft.MyService: java.lang.IllegalStateException: get fIEld slot from row 0 col -1 @R_301_5138@
01-03 22:19:46.097: E/AndroIDRuntime(240): at androID.app.ActivityThread.handleCreateService(ActivityThread.java:2969)
01-03 22:19:46.097: E/AndroIDRuntime(240): at androID.app.ActivityThread.access$3300(ActivityThread.java:125)
01-03 22:19:46.097: E/AndroIDRuntime(240): at androID.app.ActivityThread$H.handleMessage(ActivityThread.java:2087)
01-03 22:19:46.097: E/AndroIDRuntime(240): at androID.os.Handler.dispatchMessage(Handler.java:99)
01-03 22:19:46.097: E/AndroIDRuntime(240): at androID.os.Looper.loop(Looper.java:123)
01-03 22:19:46.097: E/AndroIDRuntime(240): at androID.app.ActivityThread.main(ActivityThread.java:4627)
01-03 22:19:46.097: E/AndroIDRuntime(240): at java.lang.reflect.Method.invokeNative(Native Method)
01-03 22:19:46.097: E/AndroIDRuntime(240): at java.lang.reflect.Method.invoke(Method.java:521)
01-03 22:19:46.097: E/AndroIDRuntime(240): at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-03 22:19:46.097: E/AndroIDRuntime(240): at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-03 22:19:46.097: E/AndroIDRuntime(240): at dalvik.system.NativeStart.main(Native Method)
01-03 22:19:46.097: E/AndroIDRuntime(240): Caused by: java.lang.IllegalStateException: get fIEld slot from row 0 col -1 @R_301_5138@
01-03 22:19:46.097: E/AndroIDRuntime(240): at androID.database.CursorWindow.getString_native(Native Method)
01-03 22:19:46.097: E/AndroIDRuntime(240): at androID.database.CursorWindow.getString(CursorWindow.java:329)
01-03 22:19:46.097: E/AndroIDRuntime(240): at androID.database.AbstractwindowedCursor.getString(AbstractwindowedCursor.java:49)
01-03 22:19:46.097: E/AndroIDRuntime(240): at com.androID.antitheft.MyService.onCreate(MyService.java:69)
01-03 22:19:46.097: E/AndroIDRuntime(240): at androID.app.ActivityThread.handleCreateService(ActivityThread.java:2959)
01-03 22:19:46.097: E/AndroIDRuntime(240): … 10 more
提前谢谢…………..
我的service.java //文件
package com.androID.antitheft;import androID.app.Service;import androID.content.Context;import androID.content.Intent;import androID.database.Cursor;import androID.database.sqlite.sqliteDatabase;import androID.os.IBinder;import androID.telephony.TelephonyManager;import androID.telephony.SmsManager;import androID.util.Log;import androID.Widget.Toast;public class MyService extends Service {sqliteDatabase myDB;@OverrIDepublic IBinder onBind(Intent arg0) { // Todo auto-generated method stub return null;}@OverrIDepublic voID onCreate() { super.onCreate(); System.out.println("@@@@@@@@@@@OnCreate1111"); Toast.makeText(this, "Service Created", Toast.LENGTH_LONG).show(); myDB = MyService.this.openorCreateDatabase("antitheft", MODE_PRIVATE, null); Cursor cursor1 = myDB.query("Simserial", null, null, null, null, null, null); cursor1.movetoLast(); //cursor1.movetoFirst(); String ss1 = cursor1.getString(cursor1.getColumnIndex("simno")); Toast.makeText(this, "FROM DATABASE: SIM SERIAL "+ss1, Toast.LENGTH_LONG).show(); cursor1.close(); myDB.close();// cursor2.movetoNext();// String num2 = cursor2.getString(cursor2.getColumnIndex("secure"));// // cursor2.movetoNext();// String num3 = cursor2.getString(cursor2.getColumnIndex("secure")); TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); String ss=tm.getSimserialNumber(); Log.v("SERVICE", ss); Toast.makeText(this, "Service started : SIM SERIAL "+ss, Toast.LENGTH_LONG).show(); Log.v("StartServiceAtBoot", "StartAtBootService -- onStartCommand()"); if(ss.equals(ss1)) { SmsManager sms = SmsManager.getDefault();// sms.sendTextMessage("5556", null, "message", null, null); Toast.makeText(this, "INSIDE iffffffffffff ", Toast.LENGTH_LONG).show(); myDB = MyService.this.openorCreateDatabase("antitheft", MODE_PRIVATE, null); Cursor cursor2 = myDB.query("Simserial", null, null, null, null, null, null); cursor2.movetoFirst(); while (cursor2.isAfterLast() == false) { String num1 = cursor2.getString(cursor2.getColumnIndex("secure")); sms.sendTextMessage(num1, null, "message", null, null); cursor2.movetoNext(); } cursor2.close(); myDB.close();// sms.sendTextMessage(num1, null, "message", null, null); // sms.sendTextMessage(num2, null, "message", null, null);// sms.sendTextMessage(num3, null, "message", null, null); }// else// // {// SmsManager sms = SmsManager.getDefault();// sms.sendTextMessage("5556", null, "message", null, null);// // Toast.makeText(this, "INSIDE elseeeeeeeeeeeeee", Toast.LENGTH_LONG).show();// }}@OverrIDepublic voID onDestroy() { super.onDestroy(); Toast.makeText(this, "Service Destroyed", Toast.LENGTH_LONG).show();} @OverrIDe public int onStartCommand(Intent intent, int flags, int startID) { // We want this service to continue running until it is explicitly // stopped, so return sticky. return START_STICKY; }
}
解决方法:
从数据库创建游标时,必须首先检查两者(游标!= null&& cursor.movetoFirst()).在您的情况下,如果没有任何可用数据,则将产生问题.
所以在使用游标之前,请先添加条件
if(c != null && c.movetoFirst()) {//write your code here}
java.lang.IllegalStateException: get fIEld slot from row 0 col -1
@R_301_5138@
通常,如果您试图从游标中读取列值,但该列在游标中不存在,则会出现此错误.
总结以上是内存溢出为你收集整理的android-启动后崩溃全部内容,希望文章能够帮你解决android-启动后崩溃所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)