Android programozásban kellene segítség (? )
Van egy kódrészlet, ami hibát dob, csak nem tudom miért. Elvben helyes, de nem működik...
public class MySQLiteAdapter {
MySQLite sql;
Context context;
public MySQLiteAdapter(Context context) { //constructor
sql = new MySQLite(context);
this.context=context;
}
public long insertUser(String Username,String Pass, String Name, String Mail){
SQLiteDatabase db=sql.getWritableDatabase();
ContentValues cv=new ContentValues();
cv.put(MySQLite.COLUMN_USERNAME,Username);
cv.put(MySQLite.COLUMN_PASSWORD,Pass);
cv.put(MySQLite.COLUMN_REALNAME,Name);
cv.put(MySQLite.COLUMN_MAIL,Mail);
long id=db.insert(MySQLite.TABLE_USERS,null,cv);
return id;
}
class MySQLite extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "APPLICATION"; //name database
private static final int DATABASE_VERSION = 2;
public static final String TABLE_USERS="users_table";
public static final String COLUMN_ID = "_id";
public static final String COLUMN_USERNAME="USERNAME";
public static final String COLUMN_PASSWORD="PASSWORD";
public static final String COLUMN_REALNAME="NAME";
public static final String COLUMN_MAIL="E-MAIL";
private static final String TABLE_CREATE_USERS="CREATE TABLE "+TABLE_USERS+"("+COLUMN_ID
+"INTEGER PRIMARY KEY AUTOINCREMENT, "
+COLUMN_USERNAME+"VARCHAR(250) NOT NULL, "+COLUMN_PASSWORD+"VARCHAR(250) NOT NULL, "
+COLUMN_REALNAME+"VARCHAR(250) NOT NULL, "+COLUMN_MAIL+"VARCHAR(250) NOT NULL );";
//Szerintem itt a hiba
private static final String DROP_TABLE_USERS="DROP TABLE IF EXISTS "+TABLE_USERS;
public MySQLite(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
Message.mess(context,"CONSTRUCTOR WAS CALLED ");
}
@Override
public void onCreate(SQLiteDatabase db) {
try {
db.execSQL(TABLE_CREATE_USERS);
Message.mess(context,"USERS TABLE WAS CREATED");
} catch (SQLException e) {
Message.mess(context,"ERROR CREATING TABLE "+e); //Itt adja a hiba uzenetet
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL(DROP_TABLE_USERS);
Message.mess(context,"UPGRADE WAS CALLED");
onCreate(db);
}
}//end of inner class
}
a Message.mess egy Toast-ot ir ki a hibaval vagy a sikeres muveletet megerosito uzenettel
Error creating table "CREATE TABLE "+TABLE_USERS+"("+COLUMN_ID
+"INTEGER PRIMARY KEY AUTOINCREMENT, "
+COLUMN_USERNAME+"VARCHAR(250) NOT NULL, "+COLUMN_PASSWORD+"VARCHAR(250) NOT NULL, "
+COLUMN_REALNAME+"VARCHAR(250) NOT NULL, "+COLUMN_MAIL+"VARCHAR(250) NOT NULL );
ez a hibauzenet Toast formaban, de nem ertem miert
android.database.sqlite.SQLiteException: near "-": syntax error (code 1): , while compiling: INSERT INTO users_table(USERNAME,NAME,PASSWORD,E-MAIL) VALUES (?,?,?,?)
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:892)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:503)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:726)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1568)
at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1440)
at com.example.levi.gestiune.MySQLiteAdapter.insertUser(MySQLiteAdapter.java:68) //Ez lesz az*---->
at com.example.levi.gestiune.SignUp.onClick(SignUp.java:105)
at android.view.View.performClick(View.java:4442)
at android.view.View$PerformClick.run(View.java:18473)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
at dalvik.system.NativeStart.main(Native Method)
//---->*ami pedig a kodban: long id=db.insert(MySQLite.TABLE_USERS,null,cv);
kijavitva :)
de most meg ez van, pedig valoztattam a Version number-t is
android.database.sqlite.SQLiteException: no such table: users (code 1): , while compiling: INSERT INTO users(EMAIL,USERNAME,NAME,PASSWORD) VALUES (?,?,?,?)
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:892)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:503)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:726)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1568)
at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1440)
at com.example.levi.gestiune.MySQLiteAdapter.insertUser(MySQLiteAdapter.java:68)
at com.example.levi.gestiune.SignUp.onClick(SignUp.java:106)
at android.view.View.performClick(View.java:4442)
at android.view.View$PerformClick.run(View.java:18473)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
at dalvik.system.NativeStart.main(Native Method)
Megkapod a "USERS TABLE WAS CREATED" üzenetet?
Szerintem most az lenne a legegyszerűbb, ha a verziószámot visszarakod 1-re, a programot meg letörlöd a telefonról és újratelepíted. Nem a legszebb megoldás, de valószínűleg működni fog.
Kapcsolódó kérdések:
Minden jog fenntartva © 2024, www.gyakorikerdesek.hu
GYIK | Szabályzat | Jogi nyilatkozat | Adatvédelem | Cookie beállítások | WebMinute Kft. | Facebook | Kapcsolat: info(kukac)gyakorikerdesek.hu
Ha kifogással szeretne élni valamely tartalommal kapcsolatban, kérjük jelezze e-mailes elérhetőségünkön!