みんなこれを実行すると、事実上の例外とnullポインター例外としてエラーが発生しました
どのように修正するか、sqliteから値を取得して配列に保存する方法、次にその配列をAndroidのリストビューに与える方法
public class FindByLocation extends ListActivity{
AutoCompleteTextView t1;
Button b1;
ListView l1;
SQLiteDatabase sqldb;
Cursor cur;
String[] loc;
String[] locat={"//some values i given "};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.location);
t1=(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);
b1=(Button)findViewById(R.id.locationSearchbtn);
l1=getListView();
l1.setChoiceMode(2);
l1.setTextFilterEnabled(true);
ArrayAdapter<String> aa=new ArrayAdapter<String>(FindByLocation.this, android.R.layout.simple_dropdown_item_1line, locat);
t1.setAdapter(aa);
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String getloc=t1.getText().toString();
sqldb=FindByLocation.this.openOrCreateDatabase("madrasmtcinfo", MODE_PRIVATE, null);
try{
cur=sqldb.rawQuery("select * from mtcbusroute where route Like '%"+getloc+"%';", null);
if(cur.moveToFirst()){
int i=0;
do{
loc[i]="" + cur.getString(cur.getColumnIndexOrThrow("routeno")).toString() + ", " + cur.getString(cur.getColumnIndexOrThrow("source")).toString()+", "+ cur.getString(cur.getColumnIndexOrThrow("Destination")).toString();
i++;
cur.moveToNext();
}while(cur.isLast()!=true);
}
}
catch(Exception e){
Toast.makeText(getBaseContext(), "Error"+e, Toast.LENGTH_SHORT).show();
}
setListAdapter(new ArrayAdapter<String>(FindByLocation.this, android.R.layout.simple_list_item_1, loc));
}
});
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
Toast.makeText(getBaseContext(), ""+loc[position], Toast.LENGTH_SHORT).show();
}
}