public class Project {
int _id ;
String _name;
String _pprice ;
String _start ;
String _manhours ;
String _finish ;
public Project(int id, String name, String pprice, String start, String manhours, String finish) {
this._id=id;
this._name=name;
this._pprice=pprice;
this._start=start;
this._manhours=manhours;
this._finish=finish;
}
public Project(String name, String pprice, String start, String manhours, String finish) {
this._name=name;
this._pprice=pprice;
this._start=start;
this._manhours=manhours;
this._finish=finish;
}
public int getprojid(){
return this._id;
}
public String getprojName(){
return this._name;
}
public String getpvalue(){
return this._pprice;
}
public String getstartdate(){ return this._start; }
public String getmanhours(){
return this._manhours;
}
public String getfinishdate(){ return this._finish; }
public void setprojid(int projid){ this._id = projid;}
public void setprojname(String projname){ this._name = projname;}
public void setprojvalue(String ppprice){ this._pprice = ppprice;}
public void setstartdate(String startdate){this._start = startdate;}
// public void setduration(String duration){this._DURATION = duration;}
public void setprojmanhours(String pmanhours){
this._manhours = pmanhours;
}
public void setfinishdate(String finishdate){
this._finish = finishdate;
}
}
SQLiteHelperクラス私はアンドロイドのスタジオでのSQLiteを使用して私のプログラムでエラーメッセージを見つけました
public class popopHandler extends SQLiteOpenHelper {
// All Static variables
// Database Version
private static final int DATABASE_VERSION = 1;
// Database Name
private static final String DATABASE_NAME = "projects4_Manager";
// Contacts table name
private static final String TABLE_CONTACTS = "proj4";
// Contacts Table Columns names
private static final String KEY_ID = "id";
private static final String KEY_NAME = "name";
private static final String KEY_PRICE = "price";
private static final String KEY_START = "start";
private static final String KEY_MANHOURS="pmanhours";
private static final String KEY_FINISH = "finish";
public popopHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_CONTACTS + "("
+ KEY_ID + " INTEGER PRIMARY KEY," + KEY_NAME + "TEXT,"+ KEY_PRICE + "INTEGER,"
+ KEY_START + " TEXT," + KEY_MANHOURS + "INTEGER,"
+ KEY_FINISH + " TEXT" + ")";
sqLiteDatabase.execSQL(CREATE_CONTACTS_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) {
sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + TABLE_CONTACTS);
// Create tables again
onCreate(sqLiteDatabase);
}
// Adding new contact
public void addproject(Project project) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_NAME, project.getprojName()); // Contact Name
values.put(KEY_PRICE, project.getpvalue());
values.put(KEY_START,project.getstartdate());
values.put(KEY_MANHOURS, project.getmanhours());
values.put(KEY_FINISH, project.getfinishdate());
// Inserting Row
db.insert(TABLE_CONTACTS, null, values);
db.close(); // Closing database connection
}
public Project getProject(String proname) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_CONTACTS, new String[]{KEY_ID,
KEY_NAME,KEY_PRICE,KEY_START,KEY_MANHOURS,KEY_FINISH},KEY_NAME + "=?",
new String[]{String.valueOf(proname)}, null, null, null, null);
if (cursor != null)
cursor.moveToFirst();
Project project = new Project(Integer.parseInt(cursor.getString(cursor.getColumnIndex(KEY_ID))),
cursor.getString(cursor.getColumnIndex(KEY_NAME)),
cursor.getString(cursor.getColumnIndex(KEY_PRICE)),
cursor.getString(cursor.getColumnIndex(KEY_START)),
cursor.getString(cursor.getColumnIndex(KEY_MANHOURS)),
cursor.getString(cursor.getColumnIndex(KEY_FINISH)));
return project;
}
public String updateproject(Project project) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_NAME, project.getprojName()); // Contact Name
values.put(KEY_PRICE, project.getpvalue());
values.put(KEY_START,project.getfinishdate());
values.put(KEY_MANHOURS,project.getmanhours());
values.put(KEY_FINISH, project.getstartdate());
// updating row
return String.valueOf(db.update(TABLE_CONTACTS, values,KEY_NAME+ " = ?",
new String[]{String.valueOf(project.getprojName())}));
}
// Deleting single contact
public void deleteproject(Project project) {
SQLiteDatabase db = this.getWritableDatabase();
db.delete(TABLE_CONTACTS,KEY_NAME + " = ?",
new String[]{String.valueOf(project.getprojName())});
db.close();
}
}
Activityクラス
public class AdProject2 extends AppCompatActivity {
private static final String TAG = "AdProject2";
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final popopHandler db = new popopHandler(AdProject2.this);
setContentView(R.layout.addproject2);
final EditText value;
final EditText name;
final EditText start;
final EditText manhours;
final EditText finish;
value = (EditText) findViewById(R.id.projectvalue);
name = (EditText) findViewById(R.id.myprojectname);
manhours = (EditText) findViewById(R.id.projectmanhour);
start = (EditText) findViewById(R.id.startdate);
finish = (EditText) findViewById(R.id.finishdate);
// value.addTextChangedListener(onTextChangedListener());
// final TextInputLayout projnamelayout = (TextInputLayout) findViewById(firstnameInputLayout);
Button saveButton = (Button) findViewById(R.id.saveButton);
saveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
db.addproject(new Project(name.getText().toString(),
value.getText().toString(),
start.getText().toString(), manhours.getText().toString(),
finish.getText().toString()));
}
});
}
}
私のエラーメッセージ:
E/SQLiteLog :(1)テーブルproj4にpmanhoursという名前の列がありません E/SQLiteDatabase:finish = 11/6/2018の挿入エラーpmanhours = 55555 price = 885 start = 11/6/2016の名前= ff android.database.sqlite.SQLiteException:テーブルproj4にpmanhoursという名前の列がありません(コード1 )、コンパイル中:INSERT INTO proj4(finish、pmanhours、price、start、name)VALUES(?、?、?、?、?) android.database.sqlite.SQLiteConnection.nativePrepareStatement(ネイティブ メソッド) (SQLiteConnection.java:693)android.database.sqlite.SQLiteSession.prepare :588)android.database.sqlite.SQLiteProgramの (SQLiteProgram.ja VA:58) android.database.sqlite.SQLiteDatabase.insertで android.database.sqlite.SQLiteDatabase.insertWithOnConflictでandroid.database.sqlite.SQLiteStatement(SQLiteStatement.java:31) (SQLiteDatabase.java:1589)で。 (SQLiteDatabase.java:1461) at pioneers.safwat.earnedvaluecalculations.popopHandler.addproject(popopHandler.java:73) at pioneers.safwat.earnedvaluecalculations.AdProject2 $ 1.onClick(AdProject2.java:39) android.viewにあります。 View.performClick(View.java:4476) android.view.View $ PerformClick.run(View.java:18795) (android.os.Handler.handleCallback(Handler.java:730) )は、アンドロイドです。 Handler.dispatchMessage(Handler.java:92) android.os.Looper.loop(Looper.java:177) android.app.ActivityThread.main(ActivityThread.java:5496) at java.lang.reflect.Method.invokeNative(ネイティブメソッド) at java .lang.reflect.Method.invoke(Method.java:525) com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1225) at com.android.internal.os.ZygoteInit.main dalvik.system.NativeStart.main(ネイティブメソッド)W/IInputConnectionWrapperで(ZygoteInit.java:1041) 作動休止 InputConnection W/IInputConnectionWrapperにgetTextBeforeCursor: 非アクティブInputConnection W/IInputConnectionWrapperにgetCursorCapsMode作動休止InputConnectionにgetCursorCapsMode
私はいつもそれを参照しています - 列の名前を1つの場所にのみ表示するようにagartクエリを完全にリッピングするチュートリアルの次のソースコード - ひどいです。 –