L
Lauda
Neues Mitglied
- 0
Hallo,
habe ein Problem mit dem im Titel beschriebenen Thema. Ich frage eine bisher leere Tabelle ab. Die Activity die aufgerufen wird, soll demnach eine leere Liste anzeigen, allerdings stürtzt die Anwendung beim ausführen der App ab.
XML:
<ListView
android:id="@android:id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<TextView
android:id="@+android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/tx_data_database_empty"
/>
ListActivity:
package niklaskasper.TrainLog.Basics;
import niklaskasper.TrainLog.Daten.DatabaseManager;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;
public class TrainingSchedule extends ListActivity {
private SQLiteDatabase sDatabase;
private DatabaseManager sHelper;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.trainingschedule);
sHelper = new DatabaseManager(this);
}
@Override
protected void onPause() {
sDatabase.close();
Toast.makeText(this, getResources().getString(R.string.tx_database_close), Toast.LENGTH_SHORT).show();
super.onPause();
}
@Override
protected void onResume() {
super.onResume();
sDatabase = sHelper.getReadableDatabase();
Toast.makeText(this, getResources().getString(R.string.tx_database_open), Toast.LENGTH_SHORT).show();
Cursor scheduleCursor = sDatabase.query("trainingSchedules", new String[]{
"_id","name"},null,null,null,null,null);
this.startManagingCursor(scheduleCursor);
String[] columns = new String[] {"_id"};
int[] to = new int[] { android.R.id.text1 };
SimpleCursorAdapter scheduleAdapter =
new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, scheduleCursor, columns, to);
this.setListAdapter(scheduleAdapter);
}
public void back(final View view){
startActivity(new Intent(this, MainActivity.class));
sDatabase.close();
Toast.makeText(this, getResources().getString(R.string.tx_database_close), Toast.LENGTH_SHORT).show();
finish();
}
}
Ich finde den Fehler leider nicht. Habe mir schon verschiedene Tutorials zu dem Thema durchgelesen, aber ich sehe den Fehler nicht.
Dazu ist zu sagen, das die Anwendung nicht abbricht, wenn ich diesen Teil auskommentiere:
SimpleCursorAdapter scheduleAdapter =
new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, scheduleCursor, columns, to);
this.setListAdapter(scheduleAdapter);
Gruß
Lauda
habe ein Problem mit dem im Titel beschriebenen Thema. Ich frage eine bisher leere Tabelle ab. Die Activity die aufgerufen wird, soll demnach eine leere Liste anzeigen, allerdings stürtzt die Anwendung beim ausführen der App ab.
XML:
<ListView
android:id="@android:id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<TextView
android:id="@+android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/tx_data_database_empty"
/>
ListActivity:
package niklaskasper.TrainLog.Basics;
import niklaskasper.TrainLog.Daten.DatabaseManager;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;
public class TrainingSchedule extends ListActivity {
private SQLiteDatabase sDatabase;
private DatabaseManager sHelper;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.trainingschedule);
sHelper = new DatabaseManager(this);
}
@Override
protected void onPause() {
sDatabase.close();
Toast.makeText(this, getResources().getString(R.string.tx_database_close), Toast.LENGTH_SHORT).show();
super.onPause();
}
@Override
protected void onResume() {
super.onResume();
sDatabase = sHelper.getReadableDatabase();
Toast.makeText(this, getResources().getString(R.string.tx_database_open), Toast.LENGTH_SHORT).show();
Cursor scheduleCursor = sDatabase.query("trainingSchedules", new String[]{
"_id","name"},null,null,null,null,null);
this.startManagingCursor(scheduleCursor);
String[] columns = new String[] {"_id"};
int[] to = new int[] { android.R.id.text1 };
SimpleCursorAdapter scheduleAdapter =
new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, scheduleCursor, columns, to);
this.setListAdapter(scheduleAdapter);
}
public void back(final View view){
startActivity(new Intent(this, MainActivity.class));
sDatabase.close();
Toast.makeText(this, getResources().getString(R.string.tx_database_close), Toast.LENGTH_SHORT).show();
finish();
}
}
Ich finde den Fehler leider nicht. Habe mir schon verschiedene Tutorials zu dem Thema durchgelesen, aber ich sehe den Fehler nicht.
Dazu ist zu sagen, das die Anwendung nicht abbricht, wenn ich diesen Teil auskommentiere:
SimpleCursorAdapter scheduleAdapter =
new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, scheduleCursor, columns, to);
this.setListAdapter(scheduleAdapter);
Gruß
Lauda
Zuletzt bearbeitet: