0

我创建了我的第一个安卓应用程序。一切正常,除了一个问题。当我在我的应用程序中打开数据库时。在我的 oncreate 活动中,它运行良好。但是当我使用相同的代码来检索方法中的值时,我的应用程序崩溃并给出一个java.null pointer exception.

所以我的问题是,是否有另一种方法可以打开数据库,或者我做错了什么。这是我的代码。

这里我的方法给出了 java.null 指针异常。

public class SendGlass extends Activity{

  static String replay;

   public void sms (String phone,String Sms )
   {
        SmsManager smsManager = SmsManager.getDefault();

        String phoneNo = phone;
        String sms = Sms;
        String api = "You Entered one";
        String api2 = "You Entered two";
        String api3 = "Nothing great";
        String rep = sms.replace(phoneNo+" :", "");

        SQLiteDatabase db = openOrCreateDatabase("ComDB", MODE_PRIVATE, null);
        Cursor c = db.rawQuery("SELECT REPLAYS FROM Rtm WHERE ID = 1", null);

        while(c.moveToNext())
        {
            replay = c.getString(c.getColumnIndex("REPLAYS"));

            if(rep.equals("1"))
            {
                smsManager.sendTextMessage(phoneNo, null, replay, null, null);
            }
            if(rep.equals("2"))
            {
                smsManager.sendTextMessage(phoneNo, null, replay, null, null);
            }
            if(rep.equals("3"))
            {
                smsManager.sendTextMessage(phoneNo, null, replay, null, null);
            }
            if(rep.equals("4"))
            {
                smsManager.sendTextMessage(phoneNo, null, replay, null, null);
            }
            if(rep.equals("5"))
            {
                smsManager.sendTextMessage(phoneNo, null, replay, null, null);
            }
            if(rep.equals("6"))
            {
                smsManager.sendTextMessage(phoneNo, null, replay, null, null);
            }
            if(rep.equals("7"))
            {
                smsManager.sendTextMessage(phoneNo, null, replay, null, null);
            }
            if(rep.equals("8"))
            {
                smsManager.sendTextMessage(phoneNo, null, replay, null, null);
            }
       }
 }  

我通过以下方式为此代码提供参数

     class obj = new Class();
     obj.sms (value,value )
4

1 回答 1

-1

尝试这个

c.moveToFirst():

做{你的代码////

} 而(c.moveToNext)

于 2012-12-11T11:54:14.797 回答