繁体   English   中英

找不到Android资源异常

[英]Android resource not found exception

我的应用程序代码如下,

public class Alarm extends MainActivity {

public String str;

public void onReceive(Context context, Intent intent) {
    //---get the CB message passed in---
    Bundle bundle = intent.getExtras();        
    SmsCbMessage[] msgs = null;
    str = "";            
    if (bundle != null)  {
        //---retrieve the SMS message received---
        Object[] pdus = (Object[]) bundle.get("pdus");
        msgs = new SmsCbMessage[pdus.length];            
        for (int i=0; i<msgs.length; i++) {
            msgs[i] = SmsCbMessage.createFromPdu((byte[])pdus[i]);                
            str += "CB " + msgs[i].getGeographicalScope() + msgs[i].getMessageCode() + msgs[i].getMessageIdentifier() + msgs[i].getUpdateNumber();                     
            str += " :";
            str += "\n";        
        }
        }
        }


EditText user_value;
Button startalarm;


@Override
 public void onCreate(Bundle savedInstanceState) 
{
 super.onCreate(savedInstanceState);
 setContentView(R.layout.third);

startalarm = (Button) findViewById(R.id.startalarm);
user_value = (EditText) findViewById(R.id.user_value);

startalarm.setOnClickListener(new View.OnClickListener() 
{

public void onClick(View arg0)
{
        // TODO Auto-generated method stub
if(user_value.length()==0)
{
    Toast.makeText(getBaseContext(), "Please enter a value.", Toast.LENGTH_LONG).show();
}

    SQLiteDatabase aa = openOrCreateDatabase("MLIdata", MODE_WORLD_READABLE, null);
    Cursor c = aa.rawQuery("SELECT CblocationName FROM MLITable WHERE CblocationCode = '"+str+"'", null);
    c.moveToFirst();
    c.getString(c.getColumnIndex("CblocationName"));
    String sas = user_value.getText().toString();
    if(sas==getString(c.getColumnIndex("CblocationName")))
    {
        //here comes the alarm code

        Toast.makeText(getBaseContext(), "till here it has executed.",     Toast.LENGTH_LONG).show();
        Notification notification = new     Notification(android.R.drawable.ic_popup_reminder,
        "My Notification", System.currentTimeMillis());
        notification.defaults |= Notification.DEFAULT_SOUND;
        notification.defaults |= Notification.DEFAULT_VIBRATE;
    }
}


});
}
   }

虽然没有错误,但是当我运行此代码时,当我按下“启动警报”按钮时,它会强制关闭。

我的日志猫如下

11-05 01:31:03.029: W/ResourceType(1554): No package identifier when getting value for resource number 0x00000000
11-05 01:31:03.029: W/dalvikvm(1554): threadid=1: thread exiting with uncaught exception (group=0x40018578)
11-05 01:31:03.029: E/AndroidRuntime(1554): FATAL EXCEPTION: main
11-05 01:31:03.029: E/AndroidRuntime(1554): android.content.res.Resources$NotFoundException:     String resource ID #0x0
11-05 01:31:03.029: E/AndroidRuntime(1554):     at android.content.res.Resources.getText(Resources.java:201)
11-05 01:31:03.029: E/AndroidRuntime(1554):     at android.content.res.Resources.getString(Resources.java:254)
11-05 01:31:03.029: E/AndroidRuntime(1554):     at android.content.Context.getString(Context.java:183)
11-05 01:31:03.029: E/AndroidRuntime(1554):     at my.project.mil.Alarm$1.onClick(Alarm.java:68)
11-05 01:31:03.029: E/AndroidRuntime(1554):     at android.view.View.performClick(View.java:2485) 
11-05 01:31:03.029: E/AndroidRuntime(1554):     at android.view.View$PerformClick.run(View.java:9080)
11-05 01:31:03.029: E/AndroidRuntime(1554):     at android.os.Handler.handleCallback(Handler.java:587)
11-05 01:31:03.029: E/AndroidRuntime(1554):     at android.os.Handler.dispatchMessage(Handler.java:92)
11-05 01:31:03.029: E/AndroidRuntime(1554):     at android.os.Looper.loop(Looper.java:130)
11-05 01:31:03.029: E/AndroidRuntime(1554):     at android.app.ActivityThread.main(ActivityThread.java:3687)
11-05 01:31:03.029: E/AndroidRuntime(1554):     at java.lang.reflect.Method.invokeNative(Native Method)
11-05 01:31:03.029: E/AndroidRuntime(1554):     at java.lang.reflect.Method.invoke(Method.java:507)
11-05 01:31:03.029: E/AndroidRuntime(1554):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
11-05 01:31:03.029: E/AndroidRuntime(1554):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
11-05 01:31:03.029: E/AndroidRuntime(1554):     at dalvik.system.NativeStart.main(Native Method)

我已经尝试了以下链接中提供的所有解决方案,但都无济于事。

Android,找不到字符串资源

需要帮助,

谢谢。

我不知道我的评论会解决您的例外情况。 我将其作为答案,以便您可以关闭此问题。

更改此行:

if(sas==getString(c.getColumnIndex("CblocationName")))

if(sas.equals(getString(c.getColumnIndex("CblocationName"))))

如果您不明白为什么应该这样,请继续阅读String比较

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM