2016-08-09 18 views
0

私のアプリについて:トレーニングパフォーマンスを保存します - 1つのデータベースが多数のテーブル(1つのテーブルはトレーニングログです)。日付は表の名前です(例:d2016_08_09)。ユーザーが「保存ボタン」を押すと、appはテーブルの名前を設定します。SQLiteLog:そのようなテーブルはありません

public static final String DB_NAME ="db_workout";//name of base 
public static String DB_TABLE ="dateOfWorkout";//name of table 
public static final int DB_VER =1; 

public static void setDbTable(String dbTable) { 
    DB_TABLE = dbTable; 
} 

public Base(Context context, String name, SQLiteDatabase.CursorFactory factory, int version, String db_table_name) { 
    super(context, DB_NAME, null, DB_VER); 
    setDbTable(db_table_name); 
    System.out.println(DB_TABLE); 
} 


@Override 


public void onCreate(SQLiteDatabase db){ 
    db.execSQL(
      "create table IF NOT EXISTS "+ DB_TABLE +"(" 
      + "nr integer primary key autoincrement," 
      + "name text," 
      + "s1 integer," 
      + "s2 integer," 
      + "s3 integer," 
      + "s4 integer," 
      + "s5 integer," 
      + "weight integer);" 
      +""); 

} 

public void addWorkoutPlan(String i, int q, int w, int e, int r, int t, int wt) { 
    SQLiteDatabase db = getWritableDatabase(); 
    ContentValues wartosci = new ContentValues(); 

    wartosci.put("name", i); 
    wartosci.put("s1", q); 
    wartosci.put("s2", w); 
    wartosci.put("s3", e); 
    wartosci.put("s4", r); 
    wartosci.put("s5",t); 
    wartosci.put("weight",wt); 



    db.insertOrThrow(DB_TABLE, null, wartosci); 
} 
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 
    //uzupelnic 

} 

と私は、アプリのクラッシュを日付を追加するには、ボタンを押してAndroidStudioは、このログを取得するとき

sNameTable = "d"+sNameTable; 
    db= new Base(this,null,null,0,sNameTable); 

    bAddDate = (Button) findViewById(R.id.bAddDate); 



    bAddDate.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 

      setValues(); // setting values 





       for (int i = 0; i < 1; i++) { 

        db.addWorkoutPlan(
          tName[0][i].toString(),//nazwa cwiczenia 
          Integer.parseInt(tSeries[0][i].getText().toString()),//1. seria 
          Integer.parseInt(tSeries[1][i].getText().toString()), 
          Integer.parseInt(tSeries[2][i].getText().toString()), 
          Integer.parseInt(tSeries[3][i].getText().toString()), 
          Integer.parseInt(tSeries[4][i].getText().toString()), 
          Integer.parseInt(tWeight[0][i].getText().toString()) 

        ); 
       } 

       Context context = getApplicationContext(); 
       CharSequence text = "Trening dodany"; 
       int duration = Toast.LENGTH_SHORT; 
       Toast toast = Toast.makeText(context, text, duration); 
       toast.show(); 


     } 
    }); 
} 

をベースに日付を追加使用クラス:

23190から23190/com.example.konra_000.workoutplan E/SQLiteLog:(1)そのようなテーブルはありません:d2016_08_09

23190-23190/com.example.konra_000.workoutplan E/AndroidRuntime:致命的な例外:メイン プロセス:com.example.konra_000.workoutplan、PID:23190 android.database.sqlite.SQLiteException:そのようなテーブル:d2016_08_09 (コード1)、コンパイル中: 。INSERT INTO d2016_08_09(名前、S3、体重、S2、S1、S5、S4)VALUES(?、?、?、?、?、?、?)

+1

テーブル名に情報を入力しないでください。日付を追加の列にします。 –

答えて

0

あなたはSQLiteデータベースに息子が変化し、時々変更を行いますDBを作成するロジックが最適化されていないために表示されません。

おそらくあなたのデバイスに古いバージョンのデータベースがあります。アプリをアンインストールして再インストールするだけです。

関連する問題