押すとボタンがあり、新しいアクティビティを開始しmyActivity
ます。myActivity
から取得したデータをのレイアウトでプレビューしたいのですが、プログラム crashmyDataBase
のテキストを変更すると、次のコードが表示されます。TextView
public class myActivity extends Activity {
TextView tv1;
myDataBase DB;
String s;
String reqName
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.information);
tv1 = (TextView)findViewById(R.id.testtest);
Bundle bundle = getIntent().getExtras();
reqName = bundle.getString("someKey");
DB = new myDataBase(this);
new GetSomeData().execute(reqName);
}
public class GetSomeData extends AsyncTask<String,Integer ,String>
{
@Override
protected String doInBackground(String... arg0) {
// TODO Auto-generated method stub
try
{
String name = reqName;
DB.open();
s = DB.getData(name);
DB.close();
}
catch(Exception e)
{
e.printStackTrace();
}
tv1.setText(s); // this line makes the program crash
return s;
}
}}
クロススレッドが原因でプログラムがクラッシュしたと思います (よくわかりません!)、どうすればこの問題を解決できますか? データベースからデータをプレビューするためのより良いアイデアはありますか?