質問編集履歴

3

コードの修正

2016/11/19 06:47

投稿

edoooooo
edoooooo

スコア476

test CHANGED
File without changes
test CHANGED
@@ -442,37 +442,7 @@
442
442
 
443
443
  //もしデータがdoGetDemoであることが確認できたら、その後に誰々さんようこそは重複登録ができなくなった後でやる。
444
444
 
445
- //だからこのコードはいらない
445
+
446
-
447
- /**
448
-
449
- NCMBObject obj = new NCMBObject("TestClass");
450
-
451
- obj.setObjectId("getTestObjectId");
452
-
453
- obj.fetchInBackground(new FetchCallback<NCMBObject>() {
454
-
455
-
456
-
457
- @Override
458
-
459
- public void done(NCMBObject object, NCMBException e) {
460
-
461
- if (e != null) {
462
-
463
- //エラー時の処理
464
-
465
- } else {
466
-
467
- //取得成功時の処理
468
-
469
- }
470
-
471
- }
472
-
473
- });
474
-
475
- **/
476
446
 
477
447
 
478
448
 

2

コードの追加

2016/11/19 06:47

投稿

edoooooo
edoooooo

スコア476

test CHANGED
File without changes
test CHANGED
@@ -136,4 +136,344 @@
136
136
 
137
137
 
138
138
 
139
+ ```しっかりエラーがなく実行できたログイン、新規登録のコードです。
140
+
141
+ ```java
142
+
143
+ package ncmbdataquick.mbaas.com.nifty.datastorequickstart;
144
+
145
+
146
+
147
+ import android.app.Activity;
148
+
149
+ import android.app.AlertDialog;
150
+
151
+ import android.content.Intent;
152
+
153
+ import android.os.Bundle;
154
+
155
+ import android.view.View;
156
+
157
+ import android.view.Menu;
158
+
159
+ import android.view.MenuItem;
160
+
161
+ import android.widget.Button;
162
+
163
+
164
+
165
+ import com.nifty.cloud.mb.core.DoneCallback;
166
+
167
+ import com.nifty.cloud.mb.core.FindCallback;
168
+
169
+ import com.nifty.cloud.mb.core.NCMB;
170
+
171
+ import com.nifty.cloud.mb.core.NCMBException;
172
+
173
+ import com.nifty.cloud.mb.core.NCMBObject;
174
+
175
+ import com.nifty.cloud.mb.core.NCMBQuery;
176
+
177
+
178
+
179
+ import java.util.List;
180
+
181
+
182
+
183
+ public class MainActivity extends Activity {
184
+
185
+
186
+
187
+ @Override
188
+
189
+ protected void onCreate(Bundle savedInstanceState) {
190
+
191
+ super.onCreate(savedInstanceState);
192
+
193
+ setContentView(R.layout.activity_main);
194
+
195
+
196
+
197
+
198
+
199
+ //**************** APIキーの設定とSDKの初期化 **********************
200
+
201
+ NCMB.initialize(this, "");
202
+
203
+
204
+
205
+
206
+
207
+ Button newUserAddButton = (Button) findViewById(R.id.NewUserAdd);
208
+
209
+ newUserAddButton.setOnClickListener(new View.OnClickListener() {
210
+
211
+
212
+
213
+ //ここに新規登録へのボタンを押した時を作る
214
+
215
+ @Override
216
+
217
+ public void onClick(View v) {
218
+
219
+
220
+
221
+ // ボタン1が押された場合
222
+
223
+ if (v.getId() == R.id.NewUserAdd) {
224
+
225
+
226
+
227
+ Button sendButton = (Button) findViewById(R.id.NewUserAdd);
228
+
229
+ Intent intent = new Intent(getApplication(), ActivitySecond.class);
230
+
231
+ startActivity(intent);
232
+
233
+ }
234
+
235
+ }
236
+
237
+ });
238
+
239
+ //この下にもう一つのリスナー
240
+
241
+
242
+
243
+ Button toLoginButton=(Button)findViewById(R.id.LoginCheckAnswer);
244
+
245
+ toLoginButton.setOnClickListener(new View.OnClickListener() {
246
+
247
+
248
+
249
+ //ここにログインへのボタンを押した時を作る
250
+
251
+ @Override
252
+
253
+ public void onClick(View v) {
254
+
255
+ if (v.getId() == R.id.LoginCheckAnswer) {
256
+
257
+ Intent intent = new Intent(getApplication(), ActivityThird.class);
258
+
259
+ startActivity(intent);
260
+
261
+ }
262
+
263
+ }
264
+
265
+ });
266
+
267
+ //この上に
268
+
269
+ }
270
+
271
+
272
+
273
+
274
+
275
+
276
+
277
+ @Override
278
+
279
+ public boolean onCreateOptionsMenu (Menu menu){
280
+
281
+ // Inflate the menu; this adds items to the action bar if it is present.
282
+
283
+ getMenuInflater().inflate(R.menu.menu_main, menu);
284
+
285
+ return true;
286
+
287
+ }
288
+
289
+
290
+
291
+ @Override
292
+
293
+ public boolean onOptionsItemSelected (MenuItem item){
294
+
295
+ // Handle action bar item clicks here. The action bar will
296
+
297
+ // automatically handle clicks on the Home/Up button, so long
298
+
299
+ // as you specify a parent activity in AndroidManifest.xml.
300
+
301
+ int id = item.getItemId();
302
+
303
+
304
+
305
+ //noinspection SimplifiableIfStatement
306
+
307
+ if (id == R.id.action_settings) {
308
+
309
+ return true;
310
+
311
+ }
312
+
313
+
314
+
315
+ return super.onOptionsItemSelected(item);
316
+
317
+ }
318
+
319
+
320
+
321
+ //トップ画面のいらないであろうボタン
322
+
323
+ public void doStartDemo(View view) {
324
+
325
+ final NCMBObject obj = new NCMBObject("TestClass");
326
+
327
+ obj.put("message", "Hello, NCMB!");
328
+
329
+ obj.saveInBackground(new DoneCallback() {
330
+
331
+ @Override
332
+
333
+ public void done(NCMBException e) {
334
+
335
+ if (e != null) {
336
+
337
+ //保存失敗
338
+
339
+ new AlertDialog.Builder(MainActivity.this)
340
+
341
+ .setTitle("Notification from Nifty")
342
+
343
+ .setMessage("Error:" + e.getMessage())
344
+
345
+ .setPositiveButton("OK", null)
346
+
347
+ .show();
348
+
349
+
350
+
351
+ } else {
352
+
353
+ //保存成功
354
+
355
+ new AlertDialog.Builder(MainActivity.this)
356
+
357
+ .setTitle("Notification from Nifty")
358
+
359
+ .setMessage("Save successfull! with ID:" + obj.getObjectId())
360
+
361
+ .setPositiveButton("OK", null)
362
+
363
+ .show();
364
+
365
+
366
+
367
+ }
368
+
369
+ }
370
+
371
+ });
372
+
373
+
374
+
375
+ }
376
+
377
+
378
+
379
+
380
+
381
+ //get(検索)
382
+
383
+ //トップ画面のいらないだろうボタン
384
+
385
+ public void doGetDemo(View view) {
386
+
387
+ //TestClassを検索するためのNCMBQueryインスタンスを作成
388
+
389
+ NCMBQuery<NCMBObject> query = new NCMBQuery<>("TestClass");
390
+
391
+ //keyというフィールドがvalueとなっているデータを検索する条件を設定
392
+
393
+ query.whereEqualTo("message", "Hello, NCMB!");
394
+
395
+ //データストアからデータを検索
396
+
397
+ query.findInBackground(new FindCallback<NCMBObject>() {
398
+
399
+ @Override
400
+
401
+ public void done(List<NCMBObject> results, NCMBException e) {
402
+
403
+ if (e != null) {
404
+
405
+
406
+
407
+
408
+
409
+ } else {
410
+
411
+
412
+
413
+ new AlertDialog.Builder(MainActivity.this)
414
+
415
+ .setTitle("Notification from Nifty")
416
+
417
+ .setMessage("Get successfull!"+results)
418
+
419
+ .setPositiveButton("OK", null)
420
+
421
+ .show();
422
+
423
+ //検索成功時の処理
424
+
425
+ }
426
+
427
+
428
+
429
+
430
+
431
+
432
+
433
+ }
434
+
435
+ });
436
+
437
+ }
438
+
439
+ }
440
+
441
+
442
+
443
+ //もしデータがdoGetDemoであることが確認できたら、その後に誰々さんようこそは重複登録ができなくなった後でやる。
444
+
445
+ //だからこのコードはいらない
446
+
447
+ /**
448
+
449
+ NCMBObject obj = new NCMBObject("TestClass");
450
+
451
+ obj.setObjectId("getTestObjectId");
452
+
453
+ obj.fetchInBackground(new FetchCallback<NCMBObject>() {
454
+
455
+
456
+
457
+ @Override
458
+
459
+ public void done(NCMBObject object, NCMBException e) {
460
+
461
+ if (e != null) {
462
+
463
+ //エラー時の処理
464
+
465
+ } else {
466
+
467
+ //取得成功時の処理
468
+
469
+ }
470
+
471
+ }
472
+
473
+ });
474
+
475
+ **/
476
+
477
+
478
+
139
479
  ```

1

接続が上手くいかずエラーの出るコードをのせました。

2016/11/19 06:46

投稿

edoooooo
edoooooo

スコア476

test CHANGED
File without changes
test CHANGED
@@ -17,3 +17,123 @@
17
17
  この前に作ったログインアプリのコードの一部を使ったのですが、なぜなのでしょうか?
18
18
 
19
19
  前にはできました。
20
+
21
+
22
+
23
+ 接続が上手くいかないコードです。
24
+
25
+ ```java
26
+
27
+ package com.example.kanehiro.memo;
28
+
29
+
30
+
31
+ import android.content.Intent;
32
+
33
+ import android.os.Bundle;
34
+
35
+ import android.support.v7.app.AppCompatActivity;
36
+
37
+ import android.view.View;
38
+
39
+ import android.widget.Button;
40
+
41
+
42
+
43
+ import com.nifty.cloud.mb.core.DoneCallback;
44
+
45
+ import com.nifty.cloud.mb.core.FindCallback;
46
+
47
+ import com.nifty.cloud.mb.core.NCMB;
48
+
49
+ import com.nifty.cloud.mb.core.NCMBException;
50
+
51
+ import com.nifty.cloud.mb.core.NCMBObject;
52
+
53
+ import com.nifty.cloud.mb.core.NCMBQuery;
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+ public class MainActivity extends AppCompatActivity {
62
+
63
+
64
+
65
+ @Override
66
+
67
+ protected void onCreate(Bundle savedInstanceState) {
68
+
69
+ super.onCreate(savedInstanceState);
70
+
71
+ setContentView(R.layout.activity_main);
72
+
73
+
74
+
75
+
76
+
77
+ //**************** APIキーの設定とSDKの初期化 **********************
78
+
79
+ NCMB.initialize(this, "");
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+ Button newUserAddButton = (Button) findViewById(R.id.button);
90
+
91
+ newUserAddButton.setOnClickListener(new View.OnClickListener() {
92
+
93
+
94
+
95
+ //ここに新規登録へのボタンを押した時を作る
96
+
97
+ @Override
98
+
99
+ public void onClick(View v) {
100
+
101
+
102
+
103
+ // ボタン1が押された場合
104
+
105
+ if (v.getId() == R.id.button) {
106
+
107
+
108
+
109
+ Button sendButton = (Button) findViewById(R.id.button);
110
+
111
+ Intent intent = new Intent(getApplication(), ActivitySecond.class);
112
+
113
+ startActivity(intent);
114
+
115
+ }
116
+
117
+ }
118
+
119
+ });
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+
128
+
129
+ }
130
+
131
+
132
+
133
+
134
+
135
+ }
136
+
137
+
138
+
139
+ ```