После нажатия button, приложение закрывается и выскакивает следующая ошибка: I/Process: Sending signal. PID: 17579 SIG: 9. Данные беру из БД. Класс где слушаю кнопку:
btnTaxi = (Button) findViewById(R.id.Tax);
View.OnClickListener oclBtnTaxi = new View.OnClickListener() {
@Override
public void onClick(View v) {
intent = new Intent(MainActivity.this,TaxiActivity.class);
startActivity(intent);
}
};
btnTaxi.setOnClickListener(oclBtnTaxi);
Класс TaxiActivity:
public class TaxiActivity extends ListActivity {
private ArrayList<Taxi> catalog;
DBHelper databaseHelper;
SQLiteDatabase db;
Cursor userCursor;
SimpleCursorAdapter userAdapter;
ListView lv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listic);
// lv = (ListView) findViewById(android.R.id.list);
catalog = new ArrayList<Taxi>();
databaseHelper = new DBHelper(getApplicationContext());
databaseHelper.create_db();
}
@Override
public void onResume() {
super.onResume();
db = databaseHelper.open();
userCursor = db.rawQuery("select * from " + DBHelper.TABLE, null);
String[] headers = new String[]{DBHelper.COLUMN_NAME, DBHelper.COLUMN_NUMBER};
int[] f = new int[]{R.id.textName, R.id.textNumber};
userAdapter = new SimpleCursorAdapter(this, R.layout.taxi_layout, userCursor, headers, f);
lv = (ListView) findViewById(list);
lv.setAdapter(userAdapter);
}
@Override
public void onDestroy() {
super.onDestroy();
// Закрываем подключение и курсор
db.close();
userCursor.close();
}
}
tax_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="TextView"
android:layout_width="167dp"
android:layout_height="72dp"
android:id="@+id/textName" />
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:id="@+id/textNumber"
android:layout_weight="0.14" />
</LinearLayout>
listic.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</ListView>
</LinearLayout>
Буду благодарен за помощь!.
03-12 19:55:22.625 24411-24411/? I/art: Late-enabling -Xcheck:jni
03-12 19:55:22.729 24411-24411/com.example.lukyn.fiveday W/System: ClassLoader referenced unknown path: /data/app/com.example.lukyn.fiveday-2/lib/arm
03-12 19:55:29.722 24411-24411/com.example.lukyn.fiveday W/System: ClassLoader referenced unknown path: /data/app/com.example.lukyn.fiveday-2/lib/arm
03-12 19:55:29.994 24411-24420/com.example.lukyn.fiveday I/System: FinalizerDaemon: finalize objects = 1
03-12 19:55:30.043 24411-24411/com.example.lukyn.fiveday D/OpenGLRenderer: Dumper init 2 threads <0xb735db38>
03-12 19:55:30.043 24411-24411/com.example.lukyn.fiveday D/OpenGLRenderer: <com.example.lukyn.fiveday> is running.
03-12 19:55:30.046 24411-24648/com.example.lukyn.fiveday D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: false
03-12 19:55:30.046 24411-24648/com.example.lukyn.fiveday D/OpenGLRenderer: CanvasContext() 0xb80a8018
03-12 19:55:30.106 24411-24648/com.example.lukyn.fiveday D/OpenGLRenderer: CanvasContext() 0xb80a8018 initialize window=0xb80c1348, title=com.example.lukyn.fiveday/com.example.lukyn.fiveday.SplashActivity
03-12 19:55:30.106 24411-24411/com.example.lukyn.fiveday D/Surface: Surface::allocateBuffers(this=0xb80c1340)
03-12 19:55:30.134 24411-24648/com.example.lukyn.fiveday I/OpenGLRenderer: Initialized EGL, version 1.4
03-12 19:55:30.137 24411-24648/com.example.lukyn.fiveday D/OpenGLRenderer: Created EGL context (0xb80eff08)
03-12 19:55:30.139 24411-24648/com.example.lukyn.fiveday I/OpenGLRenderer: Get enable program binary service property (1)
03-12 19:55:30.139 24411-24648/com.example.lukyn.fiveday I/OpenGLRenderer: Initializing program atlas...
03-12 19:55:30.139 24411-24648/com.example.lukyn.fiveday D/ProgramBinary/Service: BpProgramBinaryService.getFileDescriptor
03-12 19:55:30.140 24411-24648/com.example.lukyn.fiveday D/ProgramBinary/Service: BpProgramBinaryService.getProgramMapLen
03-12 19:55:30.141 24411-24648/com.example.lukyn.fiveday D/ProgramBinary/Service: BpProgramBinaryService.getProgramMapArray
03-12 19:55:30.141 24411-24648/com.example.lukyn.fiveday D/ProgramBinary/Service: BpProgramBinaryService.getProgramBinaryLen
03-12 19:55:30.141 24411-24648/com.example.lukyn.fiveday I/OpenGLRenderer: Program binary detail: Binary length is 111796, program map length is 152.
03-12 19:55:30.142 24411-24648/com.example.lukyn.fiveday I/OpenGLRenderer: Succeeded to mmap program binaries. File descriptor is 34, and path is /dev/ashmem�}�Ҷhpȵ�{�.
03-12 19:55:30.142 24411-24648/com.example.lukyn.fiveday I/OpenGLRenderer: No need to use file discriptor anymore, close fd(34).
03-12 19:55:30.143 24411-24648/com.example.lukyn.fiveday D/OpenGLRenderer: Initializing program cache from 0xb6d5703c, size = 5
03-12 19:55:30.143 24411-24648/com.example.lukyn.fiveday D/OpenGLRenderer: -- init (key = 0x0000000000000000)
03-12 19:55:30.144 24411-24648/com.example.lukyn.fiveday D/OpenGLRenderer: -- init (key = 0x0000000000000001)
03-12 19:55:30.144 24411-24648/com.example.lukyn.fiveday D/OpenGLRenderer: -- init (key = 0x0000000800000003)
03-12 19:55:30.145 24411-24648/com.example.lukyn.fiveday D/OpenGLRenderer: -- init (key = 0x0000001000500040)
03-12 19:55:30.145 24411-24648/com.example.lukyn.fiveday D/OpenGLRenderer: -- init (key = 0x0000003800000000)
03-12 19:55:30.145 24411-24648/com.example.lukyn.fiveday D/Surface: Surface::connect(this=0xb80c1340,api=1)
03-12 19:55:30.146 24411-24648/com.example.lukyn.fiveday W/libEGL: [ANDROID_RECORDABLE] format: 1
03-12 19:55:30.147 24411-24648/com.example.lukyn.fiveday D/Surface: Surface::setBufferCount(this=0xb80c1340,bufferCount=4)
03-12 19:55:30.161 24411-24648/com.example.lukyn.fiveday D/GraphicBuffer: register, handle(0xb81034b0) (w:480 h:800 s:480 f:0x1 u:0x000f02)
03-12 19:55:30.173 24411-24648/com.example.lukyn.fiveday D/OpenGLRenderer: CacheTexture 2 upload: x, y, width height = 0, 0, 512, 103
03-12 19:55:30.174 24411-24648/com.example.lukyn.fiveday D/OpenGLRenderer: ProgramCache save to disk, size = 5
03-12 19:55:32.242 24411-24411/com.example.lukyn.fiveday W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
03-12 19:55:32.507 24411-24648/com.example.lukyn.fiveday D/OpenGLRenderer: CanvasContext() 0xb8175850
03-12 19:55:32.550 24411-24411/com.example.lukyn.fiveday D/Surface: Surface::allocateBuffers(this=0xb817e1c8)
03-12 19:55:32.550 24411-24648/com.example.lukyn.fiveday D/OpenGLRenderer: CanvasContext() 0xb8175850 initialize window=0xb817e1d0, title=com.example.lukyn.fiveday/com.example.lukyn.fiveday.MainActivity
03-12 19:55:32.550 24411-24648/com.example.lukyn.fiveday D/Surface: Surface::connect(this=0xb817e1c8,api=1)
03-12 19:55:32.551 24411-24648/com.example.lukyn.fiveday W/libEGL: [ANDROID_RECORDABLE] format: 1
03-12 19:55:32.552 24411-24648/com.example.lukyn.fiveday D/Surface: Surface::setBufferCount(this=0xb817e1c8,bufferCount=4)
03-12 19:55:32.560 24411-24648/com.example.lukyn.fiveday D/GraphicBuffer: register, handle(0xb81814c8) (w:480 h:800 s:480 f:0x1 u:0x000f02)
03-12 19:55:32.622 24411-24648/com.example.lukyn.fiveday D/OpenGLRenderer: CacheTexture 2 upload: x, y, width height = 0, 0, 512, 249
03-12 19:55:32.643 24411-24648/com.example.lukyn.fiveday D/GraphicBuffer: register, handle(0xb80dd3b8) (w:480 h:800 s:480 f:0x1 u:0x000f02)
03-12 19:55:32.654 24411-24648/com.example.lukyn.fiveday D/Surface: Surface::disconnect(this=0xb80c1340,api=1)
03-12 19:55:32.654 24411-24648/com.example.lukyn.fiveday D/GraphicBuffer: unregister, handle(0xb81034b0) (w:480 h:800 s:480 f:0x1 u:0x000f02)
03-12 19:55:32.656 24411-24648/com.example.lukyn.fiveday D/Surface: Surface::disconnect(this=0xb80c1340,api=1)
03-12 19:55:34.522 24411-24648/com.example.lukyn.fiveday D/GraphicBuffer: register, handle(0xb81a1630) (w:480 h:800 s:480 f:0x1 u:0x000f02)
03-12 19:55:34.595 24411-24411/com.example.lukyn.fiveday D/AndroidRuntime: Shutting down VM
03-12 19:55:34.609 24411-24411/com.example.lukyn.fiveday I/Process: Sending signal. PID: 24411 SIG: 9
Да, id не было, добавил но все равно не выходит
public void onResume() {
super.onResume();
db = databaseHelper.open();
userCursor = db.rawQuery("select * from " + DBHelper.TABLE, null);
String[] headers = new String[]{DBHelper.COLUMN_ID,DBHelper.COLUMN_NAME, DBHelper.COLUMN_NUMBER};
int[] f = new int[]{R.id.textName, R.id.textNumber};
userAdapter = new SimpleCursorAdapter(this, R.layout.taxi_layout, userCursor, headers, f);
lv = (ListView) findViewById(list);
lv.setAdapter(userAdapter);
вот
03-13 22:08:02.479 24415-24415/com.example.lukyn.fiveday E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.lukyn.fiveday, PID: 24415
java.lang.RuntimeException: Unable to resume activity {com.example.lukyn.fiveday/com.example.lukyn.fiveday.TaxiActivity}: android.database.sqlite.SQLiteException: no such table: db (code 1): , while compiling: select * from db
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3384)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3422)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.access$900(ActivityThread.java:183)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1572)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5834)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1119)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:885)
Caused by: android.database.sqlite.SQLiteException: no such table: db (code 1): , while compiling: select * from db
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:906)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:517)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
at
android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1346)
at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1285)
at com.example.lukyn.fiveday.TaxiActivity.onResume(TaxiActivity.java:49)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1286)
at android.app.Activity.performResume(Activity.java:6202)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3369)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3422)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.access$900(ActivityThread.java:183)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1572)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5834)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1119)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:885)
03-13 22:08:02.504 24415-24415/com.example.lukyn.fiveday I/Process: Sending signal. PID: 24415 SIG: 9
DBHelper.class
public class DBHelper extends SQLiteOpenHelper {
private static String DB_PATH;
private static String DB_NAME = "bd.db";
private static final int SCHEMA = 2;
static final String TABLE = "db";
// названия столбцов
static final String COLUMN_NUMBER = "number";
static final String COLUMN_NAME = "name";
static final String COLUMN_ID = "_id";
private Context myContext;
DBHelper(Context context) {
super(context, DB_NAME, null, SCHEMA);
this.myContext=context;
DB_PATH =context.getFilesDir().getPath() + DB_NAME;
}
@Override
public void onCreate(SQLiteDatabase db) {
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
void create_db(){
InputStream myInput = null;
OutputStream myOutput = null;
try {
File file = new File(DB_PATH);
if (!file.exists()) {
this.getReadableDatabase();
myInput = myContext.getAssets().open(DB_NAME);
String outFileName = DB_PATH;
myOutput = new FileOutputStream(outFileName);
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer)) > 0) {
myOutput.write(buffer, 0, length);
}
myOutput.flush();
myOutput.close();
myInput.close();
}
}
catch(IOException ex){
Log.d("DatabaseHelper", ex.getMessage());
}
}
public SQLiteDatabase open()throws SQLException {
return SQLiteDatabase.openDatabase(DB_PATH, null, SQLiteDatabase.OPEN_READWRITE);
}
}