我的申请代码如下,
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;
}
}
});
}
}
虽然没有错误,但是当我运行此代码时,当我按下&#39; startalarm&#39;按钮。
我的日志猫如下,
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, string resource not found
需要帮助,
谢谢。
答案 0 :(得分:0)
我不知道我的评论会修复您的例外情况。我会把它作为答案,以便你可以关闭这个问题。
更改此行:
if(sas==getString(c.getColumnIndex("CblocationName")))
到
if(sas.equals(getString(c.getColumnIndex("CblocationName"))))
如果您不明白为什么会这样,请阅读String comparison。