Skip to content

Instantly share code, notes, and snippets.

@tomorrowkey
Created September 26, 2012 04:45
Show Gist options
  • Save tomorrowkey/3786118 to your computer and use it in GitHub Desktop.
Save tomorrowkey/3786118 to your computer and use it in GitHub Desktop.
crush closeable
package com.example.android.crushcloseable;
import java.io.Closeable;
import java.io.IOException;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Bundle;
public class HomeActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
SQLiteOpenHelper helper = new SQLiteOpenHelper(this, "test.db", null, 1) {
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table test(_id integer primary key autoincrement, message text)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion,
int newVersion) {
}
};
SQLiteDatabase database = helper.getWritableDatabase();
String table = "test";
String[] columns = new String[] { "_id", "message" };
Cursor cursor = database.query(table, columns, null, null, null, null,
null);
// cursor.close();
forceClose(cursor);
}
private void forceClose(Closeable closeable) {
if (closeable == null)
return;
try {
closeable.close();
} catch (IOException e) {
}
}
/*
* 3330 dalvikvm D Late-enabling CheckJNI
* 3330 AndroidRuntime D Shutting down VM
* 3330 dalvikvm W threadid=1: thread exiting with uncaught exception (group=0x40a291f8)
* 3330 AndroidRuntime E FATAL EXCEPTION: main
* 3330 AndroidRuntime E java.lang.IncompatibleClassChangeError: interface not implemented
* 3330 AndroidRuntime E at com.example.android.crushcloseable.HomeActivity.forceClose(HomeActivity.java:45)
* 3330 AndroidRuntime E at com.example.android.crushcloseable.HomeActivity.onCreate(HomeActivity.java:37)
* 3330 AndroidRuntime E at android.app.Activity.performCreate(Activity.java:4465)
* 3330 AndroidRuntime E at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
* 3330 AndroidRuntime E at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
* 3330 AndroidRuntime E at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
* 3330 AndroidRuntime E at android.app.ActivityThread.access$600(ActivityThread.java:123)
* 3330 AndroidRuntime E at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
* 3330 AndroidRuntime E at android.os.Handler.dispatchMessage(Handler.java:99)
* 3330 AndroidRuntime E at android.os.Looper.loop(Looper.java:137)
* 3330 AndroidRuntime E at android.app.ActivityThread.main(ActivityThread.java:4424)
* 3330 AndroidRuntime E at java.lang.reflect.Method.invokeNative(Native Method)
* 3330 AndroidRuntime E at java.lang.reflect.Method.invoke(Method.java:511)
* 3330 AndroidRuntime E at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
* 3330 AndroidRuntime E at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
* 3330 AndroidRuntime E at dalvik.system.NativeStart.main(Native Method)
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment