我的以下代码没有显示错误,但没有执行。
package my.project.mil;
import android.content.Context;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class Cbdata 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 += msgs[i].getMessageBody().toString();
str += "\n";
}}
}
SQLiteDatabase cd = openOrCreateDatabase("MLIdb", MODE_WORLD_READABLE, null);
Button submit;
Button viewdb;
EditText name;
@Override
public void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.seventh);
viewdb = (Button) findViewById(R.id.viewdb);
submit = (Button) findViewById(R.id.submit);
name = (EditText) findViewById(R.id.name);
submit.setOnClickListener(new View.OnClickListener()
{
public void onClick(View arg0) {
String locname = name.getText().toString();
if (locname.length()>0)
{
cd.execSQL("CREATE TABLE IF NOT EXITSTS MLITable (CblocationCode INT(10), CblocationName VARCHAR);");
cd.execSQL("INSERT INTO MLITable VALUES (' ',' ');" +str +locname);
Toast.makeText(getBaseContext(), "value successfully entered.", Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(getBaseContext(), "Please enter the location name, for example 'Home'.", Toast.LENGTH_LONG).show();
}
}
});
cd.close();
viewdb.setOnClickListener(new View.OnClickListener()
{
public void onClick(View arg0) {
// TODO Auto-generated method stub
// here comes the code for viewing the database
}
});
}
}
我的错误日志如下所示,我还检查了我的清单和 MainActivity 文件但没有运气。
我的代码应该收集用户蜂窝塔区号并将其保存在用户选择名称的数据库中,该数据库包含两个属性,一个是从用户那里收集的位置名称,第二个是蜂窝广播塔信息,它是从 onReceive 方法获得的,单独的 onReceive 方法可以正常工作。
仅当我将数据库集成到我的代码中时才会出现此问题。
谢谢你。