質問編集履歴

1

全コードを載せました

2020/10/29 08:12

投稿

nasu_nasu
nasu_nasu

スコア7

test CHANGED
File without changes
test CHANGED
@@ -42,4 +42,190 @@
42
42
 
43
43
 
44
44
 
45
+ コード全体がこちらです。
46
+
47
+ ```Java
48
+
49
+ package com.example.test3;
50
+
51
+
52
+
53
+ import android.content.Context;
54
+
55
+ import android.content.ContentValues;
56
+
57
+ import android.database.sqlite.SQLiteDatabase;
58
+
59
+ import android.database.sqlite.SQLiteOpenHelper;
60
+
61
+
62
+
63
+ public class TestOpenHelper extends SQLiteOpenHelper {
64
+
65
+
66
+
67
+ public static final int DATABASE_VERSION = 3;
68
+
69
+
70
+
71
+ public static final String DATABASE_NAME = "Plans.db";
72
+
73
+ private static final String TABLE_NAME = "plan";
74
+
75
+ private static final String _ID = "_id";
76
+
77
+ private static final String COLUMN_NAME_TIMES = "time";
78
+
79
+ private static final String COLUMN_NAME_COLOR = "color";
80
+
81
+ private static final String COLUMN_NAME_STAMPS = "stamps";
82
+
83
+
84
+
85
+ private static final String SQL_CREATE_ENTRIES =
86
+
87
+ "CREATE TABLE " + TABLE_NAME + " (" +
88
+
89
+ _ID + " INTEGER PRIMARY KEY," +
90
+
91
+ COLUMN_NAME_TIMES + " TEXT," +
92
+
93
+ COLUMN_NAME_COLOR + " TEXT," +
94
+
95
+ COLUMN_NAME_STAMPS + " INTEGER)";
96
+
97
+
98
+
99
+ private static final String SQL_DELETE_ENTRIES =
100
+
101
+ "DROP TABLE IF EXISTS " + TABLE_NAME;
102
+
103
+
104
+
105
+ TestOpenHelper(Context context){
106
+
107
+ super(context, DATABASE_NAME, null, DATABASE_VERSION);
108
+
109
+ }
110
+
111
+
112
+
113
+ @Override
114
+
115
+ public void onCreate(SQLiteDatabase db){
116
+
117
+ db.execSQL(
118
+
119
+ SQL_CREATE_ENTRIES
120
+
121
+ );
122
+
123
+
124
+
125
+ saveData(db, "0:00", null, 0);
126
+
127
+ saveData(db, "1:00", null, 0);
128
+
129
+ saveData(db, "2:00", null, 0);
130
+
131
+ saveData(db, "3:00", null, 0);
132
+
133
+ saveData(db, "4:00", null, 0);
134
+
135
+ saveData(db, "5:00", null, 0);
136
+
137
+ saveData(db, "6:00", null, 0);
138
+
139
+ saveData(db, "7:00", null, 0);
140
+
141
+ saveData(db, "8:00", null, 0);
142
+
143
+ saveData(db, "9:00", null, 0);
144
+
145
+ saveData(db, "10:00", null, 0);
146
+
147
+ saveData(db, "11:00", null, 0);
148
+
149
+ saveData(db, "12:00", null, 0);
150
+
151
+ saveData(db, "13:00", null, 0);
152
+
153
+ saveData(db, "14:00", null, 0);
154
+
155
+ saveData(db, "15:00", null, 0);
156
+
157
+ saveData(db, "16:00", null, 0);
158
+
159
+ saveData(db, "17:00", null, 0);
160
+
161
+ saveData(db, "18:00", null, 0);
162
+
163
+ saveData(db, "19:00", null, 0);
164
+
165
+ saveData(db, "20:00", null, 0);
166
+
167
+ saveData(db, "21:00", null, 0);
168
+
169
+ saveData(db, "22:00", null, 0);
170
+
171
+ saveData(db, "23:00", null, 0);
172
+
173
+
174
+
175
+ }
176
+
177
+
178
+
179
+ @Override
180
+
181
+ public void onUpgrade(SQLiteDatabase db,
182
+
183
+ int oldVersion, int newVersion){
184
+
185
+ db.execSQL(
186
+
187
+ SQL_DELETE_ENTRIES
188
+
189
+ );
190
+
191
+ onCreate(db);
192
+
193
+ }
194
+
195
+
196
+
197
+ public void onDowngrade(SQLiteDatabase db,
198
+
199
+ int oldVersion, int newVersion){
200
+
201
+ onUpgrade(db, oldVersion, newVersion);
202
+
203
+ }
204
+
205
+
206
+
207
+ public void saveData(SQLiteDatabase db, String times, String color, int stamps){
208
+
209
+ ContentValues values = new ContentValues();
210
+
211
+ values.put("times", times);
212
+
213
+ values.put("color", color);
214
+
215
+ values.put("int", stamps);
216
+
217
+
218
+
219
+ db.insert("plan", null, values);
220
+
221
+ }
222
+
223
+ }
224
+
225
+
226
+
227
+ ```
228
+
229
+
230
+
45
231
  どうすればエラーを解消できますでしょうか?