本文介绍了光标返回零从广播接收器类中调用时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到光标零值当我从广播接收器类访问它,
这是code这是我用它来访问值从数据库

 公共光标select_in(字符串NUM)
{
   最后光标CUR = db.rawQuery(选择从传入WHERE contactlist数= \\+ NUM +\\,NULL);
   返回CUR;
}

这就是我如何调用该函数从我的广播接收器类,我已通过的onReceive方法的情况下。

  openhelper =新OpenHelper(背景);this.db = openhelper.getWritableDatabase();
this.dh =新DataHelper(背景);
字符串NUM = PHONENUMBER;
光标CUR = this.dh.select_in(NUM);
如果(cur.moveToFirst()){做{
   传入= cur.getInt(cur.getColumnIndex(进入));
}而(cur.moveToNext());
}

我的操作是不那么沉重,它不会在10秒内,因为我在广播接收机,使用它完成了,我也关闭了数据库,并光标,请任何一个可以建议我如何获得该值。
提前致谢。


解决方案

 光标C;
         尝试{
            C = theDatabase.query(数据,新的String [] {KEY_CITY,KEY_TIMEZONE,KEY_COUNTRY,KEY_TIMEZONE_DISPLAY_NAME,KEY_TIMEZONE_ID} _ ID +=+身份证+;,NULL,NULL,NULL,NULL,NULL);
         }赶上(例外五){
                Log.e(时钟,错误获取时区为+ KEY_CITY +:+ e.getMessage());
                返回null;
        }

I am getting the cursor value zero when i access it from Broadcast Receiver class ,this is the code which i have use to access value from database

public Cursor select_in(String num)
{
   final Cursor cur= db.rawQuery("SELECT incoming FROM contactlist WHERE number=\""+num+"\"",null);
   return cur;
}

and this is how I call the function from my Broadcast Receiver Class and i have passed the context of OnReceive Method.

openhelper=new OpenHelper(context);

this.db=openhelper.getWritableDatabase();
this.dh=new DataHelper(context);
String num=phonenumber;
Cursor cur=this.dh.select_in(num);  
if (cur.moveToFirst()){

do{
   incoming=cur.getInt(cur.getColumnIndex("incoming"));
}while(cur.moveToNext());
}

My operations are not so heavy that it will not get completed within 10 sec as I am using it in broadcast Receiver, I have also closed the database and also the cursor ,please can any one suggest me how to get that value .Thanks In Advance.

解决方案
Cursor c ;
         try{
            c = theDatabase.query("data", new String[] {KEY_CITY, KEY_TIMEZONE, KEY_COUNTRY, KEY_TIMEZONE_DISPLAY_NAME, KEY_TIMEZONE_ID},_ID+" = '"+id+"';", null, null, null, null, null);
         }catch(Exception e){
                Log.e("CLOCK", "Error getting Timezone for "+KEY_CITY+" : "+e.getMessage());
                return null;
        }

这篇关于光标返回零从广播接收器类中调用时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 12:49