DNPereira Posted April 12, 2013 at 02:23 PM Report #502967 Posted April 12, 2013 at 02:23 PM Não estou a prceber onde está o erro import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; public class Sqlite{ final static String KEY_NEW= "_id"; final static String KEY_Buy = "pack_buy"; final static String KEY_NAME= "pack_name"; private final static String DATABASE_NAME = "Purshased"; private final static String DATABASE_TABLE = "PackNames"; private final static int DATABASE_VERSION = 1; private DbHelper ourHelper; private final Context ourContext; private SQLiteDatabase ourDatabase; public static class DbHelper extends SQLiteOpenHelper{ public DbHelper(Context context){ super(context, DATABASE_NAME, null, DATABASE_VERSION); // TODO Auto-generated constructor stub } public void onCreate(SQLiteDatabase db){ // TODO Auto-generated constructor stub db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" + KEY_NEW + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_Buy + " TEXT NOT NULL, " + KEY_NAME + " TEXT NOT NULL);" ); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { // TODO Auto-generated method stub db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE); onCreate(db); } } public Sqlite(Context c){ ourContext = c; } public Sqlite open()throws SQLException{ ourHelper = new DbHelper(ourContext); ourDatabase = ourHelper.getWritableDatabase(); return this; } public void close(){ ourHelper.close(); } public long createEntry(String bUY) { // TODO Auto-generated method stub ContentValues cv = new ContentValues(); cv.put(KEY_NAME, bUY); return ourDatabase.insert(DATABASE_TABLE, KEY_NEW, cv); } public String getData() { // TODO Auto-generated method stub String[] namePack = new String [] {KEY_NAME}; Cursor cs = ourDatabase.rawQuery("SELECT " + DATABASE_TABLE + " (" + KEY_NAME +");", namePack); if (cs.moveToFirst()) { String a = cs.getString(cs.getColumnIndex("pack_name")); cs.close(); return a; } cs.close(); return ""; } } ERRO 04-12 15:19:32.599: E/AndroidRuntime(6374): FATAL EXCEPTION: main 04-12 15:19:32.599: E/AndroidRuntime(6374): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2012, result=-1, data=null} to activity {com.test.pot/com.test.LayoutOne}: android.database.sqlite.SQLiteException: no such column: pack_name: , while compiling: SELECT PackNames (pack_name);
Solution KTachyon Posted April 12, 2013 at 09:02 PM Solution Report #503026 Posted April 12, 2013 at 09:02 PM (edited) SELECT PackNames (pack_name); Isto não me parece uma query bem feita. Mas está lá escrito: SQLiteException: no such column: pack_name: , while compiling: SELECT PackNames (pack_name); Edited April 12, 2013 at 09:04 PM by KTachyon “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.” -- Tony Hoare
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now