Databaseden veri çekmede sorun yaşıyorum
24.10.2015 - 02:38
Simülasyonun logları
10091-10091/com.example.dogruprint.dogruprint2 E/AndroidRuntime﹕ FATAL EXCEPTION: main
android.database.sqlite.SQLiteException: no such table: users (code 1): , while compiling: SELECT _id, u_name, u_pass FROM users
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
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:1314)
at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1161)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1032)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1200)
at com.example.dogruprint.dogruprint2.Database.getThat(Database.java:123)
at com.example.dogruprint.dogruprint2.siparisekle$2.onClick(siparisekle.java:113)
at android.view.View.performClick(View.java:4084)
at android.view.View$PerformClick.run(View.java:16966)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
############################ Database.java ##################################
public void onCreate(SQLiteDatabase db) {
/*
final String CREATE_TABLE = " CREATE TABLE " + DB_TABLE + " ( " + KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT , "
+ KEY_NAME + " VARCHAR(255) , "
+ KEY_PASS + " VARCHAR(255) ,"
;
*/
String CREATE_USERS_TABLE = "CREATE TABLE " + DB_TABLE + "(" + KEY_ROWID +
" INTEGER PRIMARY KEY," + KEY_NAME + " TEXT," + KEY_PASS + " TEXT"
+ ");";
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXIST " + DB_TABLE);
}
}
public Database open() throws SQLException {
ourHelper = new DBHelper(ourContext);
ourDatabase = ourHelper.getWritableDatabase();
return this;
}
public Database close() {
ourHelper.close();
return this;
}
public void addThat(String name, String pass) {
ContentValues cv = new ContentValues();
cv.put(KEY_NAME, name);
cv.put(KEY_PASS, pass);
ourDatabase.insert(DB_TABLE, null, cv);
}
public String getThat()
{
String[] colomns = new String[]{KEY_ROWID,KEY_NAME,KEY_PASS};
Cursor c = ourDatabase.query(DB_TABLE,colomns,null,null,null,null,null);
int İROW = c.getColumnIndex(KEY_ROWID);
int İNAME= c.getColumnIndex(KEY_NAME);
int İPASS = c.getColumnIndex(KEY_PASS);
String result = "";
for(c.moveToFirst();!c.isAfterLast();c.moveToNext())
{
result = result + "name" + c.getString(İNAME) + "pass" + c.getString(İPASS)+"\n";
}
return result;
}
}
######################## siparisekle.java #######################################
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import java.io.IOException;
import java.sql.SQLException;
import static android.R.*;
public class siparisekle extends Activity {
private AutoCompleteTextView act1, act2, act3;
private EditText edittxt1;
EditText etName,etPass;
TextView tvResult;
Button bSave;
Button bShow;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_siparisekle);
final Database db = new Database(this);
install_elements();
bSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean ok = true;
String name = etName.getText().toString();
String pass = etPass.getText().toString();
try {
db.open();
db.addThat(name, pass);
tvResult.setText(name + "Eklendi");
db.close();
} catch (Exception e) {
ok = false;
e.printStackTrace();
tvResult.setText("Sorun var");
} finally {
if (ok) {
Dialog d = new Dialog(siparisekle.this);
TextView tv = new TextView(siparisekle.this);
tv.setText("BASARILI");
d.setTitle("Sonuç");
d.setContentView(tv);
d.show();
}
}
}
});
bShow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
try {
db.open();
String data = db.getThat();
tvResult.setText(data);
db.close();
} catch (SQLException e)
{
Toast.makeText(getApplicationContext(),"Çağırmada Bir Sorun Oluştu",Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
});
}
protected void install_elements()
{
etName = (EditText) findViewById(R.id.etName);
etPass= (EditText) findViewById(R.id.etPass);
tvResult= (TextView) findViewById(R.id.tvResult);
bSave= (Button) findViewById(R.id.bSave);
bShow= (Button) findViewById(R.id.bShow);
}
}
299
Görüntülenme
0 Beğeni