在我的项目中有 2 个活动;在一个活动中,用户输入 2 个症状并按下一个按钮,打开下一个活动。我希望下一个活动根据症状以列表视图格式显示所有可能疾病的名称。谁能告诉我该怎么做?我试过了,但它显示空指针异常。我正在使用 Sqlite 数据库。
public class LstView extends Activity {
private Database db;
private Auto ato;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listname);
ListView lstv =(ListView) findViewById(R.id.listView1);
db=new Database(LstView.this);
db.openDB();
String a=ato.selected;
String b=ato.selected1;
// String[] lst=db.getName(a, b);
String[] from=new String[]{db.COLUMN_1_NAME};
int[] to= new int[]{R.id.text};
Cursor csr=db.getName(a, b);
// ArrayAdapter<String> adt= new ArrayAdapter<String>(getBaseContext(),R.layout.list_view,lst);
SimpleCursorAdapter adt =new SimpleCursorAdapter(this, R.layout.list_view, csr, from, to);
// SimpleCursorAdapter adt = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, db.getName(a,b), new String[] { "Name" }, new int[] { android.R.id.text1 });
lstv.setAdapter(adt);
}
}
String[] Sympt= db.getSymptom();
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,R.layout.list_view,Sympt);
textView.setAdapter(adapter);
textView.setThreshold(1);
textView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView arg0, View arg1, int arg2,
long arg3) {
int idn=arg0.getId();
selected = arg0.getItemAtPosition(arg2).toString();
System.out.println("newww "+idn);
System.out.println("newww1 "+selected);
String[] Sympt1=db.getSymptom1(selected);
for(int i=0;i<Sympt1.length;i++)
{
System.out.println("value array "+Sympt1[i]);
}
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(getBaseContext(), R.layout.list_view,Sympt1);
textView1.setAdapter(adapter1);
textView1.setThreshold(1);
// TODO Auto-generated method stub
//Toast.makeText(getApplicationContext(), "HI", Toast.LENGTH_SHORT).show();
}
});
textView1.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
int idn1=arg0.getId();
selected1=arg0.getItemAtPosition(arg2).toString();
System.out.println("neww2"+idn1);
System.out.println("neww3"+selected1);
}
});
search.setOnClickListener(new OnClickListener(){
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(getApplicationContext(),LstView.class);
startActivity(i);
}
});
}
here is the which im geting after clicking on button
NullPointerException 03-16 09:49:34.003: E/AndroidRuntime(331): at com.example.autocmplt.LstView.onCreate(LstView.java:22) 03-16 09:49:34.003: E/AndroidRuntime(331):在 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 03-16 09:49:34.003: E/AndroidRuntime(331): 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 03-16 09 :49:34.003: E/AndroidRuntime(331): ... 11 更多 03-16 09:49:37.643: I/Process(331): 发送信号。PID:331 SIG:9 1611) 03-16 09:49:34.003: E/AndroidRuntime(331): ... 11 更多 03-16 09:49:37.643: I/Process(331): 发送信号。PID:331 SIG:9 1611) 03-16 09:49:34.003: E/AndroidRuntime(331): ... 11 更多 03-16 09:49:37.643: I/Process(331): 发送信号。PID:331 SIG:9