本文介绍了启动后,轰然的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序正在使用启动service.In的服务,我需要从数据库中获取的值,但应用程序崩溃,因为它试图获取值...

My application is using a bootup service.In the service i have to get values from a database,but the app is crashing as it tries getting the values...

该错误的logcat下面列出...........

The logcat error is listed below...........

01-03 22:19:46.0​​97:E / AndroidRuntime(240):致命异常:主要  01-03 22:19:46.0​​97:E / AndroidRuntime(240):java.lang.RuntimeException的:无法创建服务com.android.antitheft.MyService:java.lang.IllegalStateException:从第0山坳得到现场插槽-1失败  01-03 22:19:46.0​​97:E / AndroidRuntime(240):在android.app.ActivityThread.handleCreateService(ActivityThread.java:2969)  01-03 22:19:46.0​​97:E / AndroidRuntime(240):在android.app.ActivityThread.access $ 3300(ActivityThread.java:125)  01-03 22:19:46.0​​97:E / AndroidRuntime(240):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:2087)  01-03 22:19:46.0​​97:E / AndroidRuntime(240):在android.os.Handler.dispatchMessage(Handler.java:99)  01-03 22:19:46.0​​97:E / AndroidRuntime(240):在android.os.Looper.loop(Looper.java:123)  01-03 22:19:46.0​​97:E / AndroidRuntime(240):在android.app.ActivityThread.main(ActivityThread.java:4627)  01-03 22:19:46.0​​97:E / AndroidRuntime(240):在java.lang.reflect.Method.invokeNative(本机方法)  01-03 22:19:46.0​​97:E / AndroidRuntime(240):在java.lang.reflect.Method.invoke(Method.java:521)  01-03 22:19:46.0​​97:E / AndroidRuntime(240):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:868)  01-03 22:19:46.0​​97:E / AndroidRuntime(240):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)  01-03 22:19:46.0​​97:E / AndroidRuntime(240):在dalvik.system.NativeStart.main(本机方法)  01-03 22:19:46.0​​97:E / AndroidRuntime(240):java.lang.IllegalStateException:产生的原因从第0山坳得到现场插槽-1失败  01-03 22:19:46.0​​97:E / AndroidRuntime(240):在android.database.CursorWindow.getString_native(本机方法)  01-03 22:19:46.0​​97:E / AndroidRuntime(240):在android.database.CursorWindow.getString(CursorWindow.java:329)  01-03 22:19:46.0​​97:E / AndroidRuntime(240):在android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:49)  01-03 22:19:46.0​​97:E / AndroidRuntime(240):在com.android.antitheft.MyService.onCreate(MyService.java:69)  01-03 22:19:46.0​​97:E / AndroidRuntime(240):在android.app.ActivityThread.handleCreateService(ActivityThread.java:2959)  01-03 22:19:46.0​​97:E / AndroidRuntime(240):10 ...更多

感谢名单提前..............

Thanx in advance..............

我service.java //文件

my service.java //file

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;

@Override
public IBinder onBind(Intent arg0) {
    // TODO Auto-generated method stub
    return null;
}
@Override
public 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();
//          }


}

@Override
public 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;
    }

}

推荐答案

我找到了答案对这个自己...

I found the answer for this myself...

错误,而不是说,我的编码错误是,我应该使用使用MoveToNext()而不是 isAfterLast()

the error,rather say;my mistake in coding was that i was supposed to use moveToNext() instead of isAfterLast()

这篇关于启动后,轰然的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 04:21