I have read similar posts but none of this used external db as i do.Here is my problem.Firtsly i had the below code and worked fine :
public class ArchaeologyMuseums extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_archaeology_museums);
String[] from = new String[]{"museum_name", "museum_category", "museum_open_now", "museum_distance"};
int[] to = new int[]{R.id.item_name, R.id.item_category, R.id.item_open_now, R.id.item_distance};
DataBaseHelper myDbHelper = new DataBaseHelper(this);
try {
myDbHelper.createDataBase();
} catch (IOException ioe) {
}
try {
myDbHelper.openDataBase();
} catch (SQLException sqle) {
throw sqle;
}
Cursor c = myDbHelper.getArchaeologicalData();
SimpleCursorAdapter adapter = new SimpleCursorAdapter(
getApplicationContext(), R.layout.list_layout, c, from, to);
ListView list = (ListView) findViewById(R.id.listView1);
list.setAdapter(adapter);}}
Then i changed my db and added 3 new columns: museum_name_greek, museum_category_greek, museum_greek_hours and used the code below:
public class ArchaeologyMuseums extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_archaeology_museums);
String[] gr = new String[]{"museum_greek_name", "museum_greek_category", "museum_greek_hours", "museum_distance"};
String[] from = new String[]{"museum_name", "museum_category", "museum_open_now", "museum_distance"};
int[] to = new int[]{R.id.item_name, R.id.item_category, R.id.item_open_now, R.id.item_distance};
DataBaseHelper myDbHelper = new DataBaseHelper(this);
String locale = Locale.getDefault().getLanguage();
try {
myDbHelper.createDataBase();
} catch (IOException ioe) {
}
try {
myDbHelper.openDataBase();
} catch (SQLException sqle) {
throw sqle;
}
Cursor c = myDbHelper.getArchaeologicalData();
if(locale.equals("el")) {
SimpleCursorAdapter adapter = new SimpleCursorAdapter(
getApplicationContext(), R.layout.list_layout, c, gr, to);
ListView list = (ListView) findViewById(R.id.listView1);
list.setAdapter(adapter);}
else {
SimpleCursorAdapter adapter = new SimpleCursorAdapter(
getApplicationContext(), R.layout.list_layout, c, from, to);
ListView list = (ListView) findViewById(R.id.listView1);
list.setAdapter(adapter);}}}
So if locale is "el" i get IllegalArgumentException: column museum_greek_name does not exist.I tried with 2 different cursor calls (c,c_gr) but no fix.Any suggestion?