質問編集履歴
6
詳細の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -164,7 +164,13 @@
|
|
164
164
|
|
165
165
|
//上のコードの塊がこの下の行より下にあったため、このString inputText=mI・・・の行がエラーとなっていました。 そのため上に移動しました。!!!!!!!!!!!
|
166
166
|
|
167
|
+
|
168
|
+
|
169
|
+
その結果、 //ここがNullPointらしいです。!!!!!!!!!!!!!!!!!!!!と書いてある下の行のコードがエラーログの結果の通り、NullPointerとなりました。
|
170
|
+
|
171
|
+
|
172
|
+
|
167
|
-
|
173
|
+
String inputText=mInputMessage.getText().toString();
|
168
174
|
|
169
175
|
|
170
176
|
|
5
変更の説明の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -112,6 +112,16 @@
|
|
112
112
|
|
113
113
|
|
114
114
|
|
115
|
+
|
116
|
+
|
117
|
+
//ここから下のコードをここに移動させました。!!!!!!!!!!!!!
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
115
125
|
// ActivityからFragmentを取得
|
116
126
|
|
117
127
|
FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
|
@@ -140,9 +150,21 @@
|
|
140
150
|
|
141
151
|
if(v.equals(mSendMessage)) {
|
142
152
|
|
153
|
+
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
|
158
|
+
|
143
|
-
|
159
|
+
//ここまでです。!!!!!!!!!!!!!!!!
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
|
144
|
-
|
165
|
+
//上のコードの塊がこの下の行より下にあったため、このString inputText=mI・・・の行がエラーとなっていました。 そのため上に移動しました。!!!!!!!!!!!
|
166
|
+
|
145
|
-
|
167
|
+
String inputText=mInputMessage.getText().toString();
|
146
168
|
|
147
169
|
|
148
170
|
|
4
エラーログの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -335,3 +335,39 @@
|
|
335
335
|
|
336
336
|
|
337
337
|
```
|
338
|
+
|
339
|
+
エラーログです。
|
340
|
+
|
341
|
+
```java
|
342
|
+
|
343
|
+
10-03 12:41:30.515 11248-11248/? E/AndroidRuntime: FATAL EXCEPTION: main
|
344
|
+
|
345
|
+
10-03 12:41:30.515 11248-11248/? E/AndroidRuntime: java.lang.NullPointerException
|
346
|
+
|
347
|
+
10-03 12:41:30.515 11248-11248/? E/AndroidRuntime: at com.example.kanehiro.fragmentapplication.MyFragment2.onClick(MyFragment2.java:57)
|
348
|
+
|
349
|
+
10-03 12:41:30.515 11248-11248/? E/AndroidRuntime: at android.view.View.performClick(View.java:4147)
|
350
|
+
|
351
|
+
10-03 12:41:30.515 11248-11248/? E/AndroidRuntime: at android.view.View$PerformClick.run(View.java:17161)
|
352
|
+
|
353
|
+
10-03 12:41:30.515 11248-11248/? E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:615)
|
354
|
+
|
355
|
+
10-03 12:41:30.515 11248-11248/? E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:92)
|
356
|
+
|
357
|
+
10-03 12:41:30.515 11248-11248/? E/AndroidRuntime: at android.os.Looper.loop(Looper.java:213)
|
358
|
+
|
359
|
+
10-03 12:41:30.515 11248-11248/? E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:4786)
|
360
|
+
|
361
|
+
10-03 12:41:30.515 11248-11248/? E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
|
362
|
+
|
363
|
+
10-03 12:41:30.515 11248-11248/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:511)
|
364
|
+
|
365
|
+
10-03 12:41:30.515 11248-11248/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
|
366
|
+
|
367
|
+
10-03 12:41:30.515 11248-11248/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
|
368
|
+
|
369
|
+
10-03 12:41:30.515 11248-11248/? E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
```
|
3
コードの改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -102,7 +102,7 @@
|
|
102
102
|
|
103
103
|
}
|
104
104
|
|
105
|
-
|
105
|
+
|
106
106
|
|
107
107
|
@Override
|
108
108
|
|
@@ -112,9 +112,35 @@
|
|
112
112
|
|
113
113
|
|
114
114
|
|
115
|
+
// ActivityからFragmentを取得
|
116
|
+
|
117
|
+
FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
|
118
|
+
|
119
|
+
Fragment fragment = fragmentManager.findFragmentById(R.id.send_message);
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
// FragmentのViewを取得
|
124
|
+
|
125
|
+
View view = fragment.getView();
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
//ここがNullPointらしいです。!!!!!!!!!!!!!!!!!!!!
|
132
|
+
|
133
|
+
mInputMessage = (EditText)view.findViewById(R.id.input_message);//ユーザーが入力するフィールド
|
134
|
+
|
135
|
+
mSendMessage = (Button) view.findViewById(R.id.send_message);//SENDボタン
|
136
|
+
|
137
|
+
mMessageLog = (LinearLayout)view.findViewById(R.id.message_log);//入力履歴を表示するレイアウト
|
138
|
+
|
139
|
+
// mMemoMessage = (TextView) view.findViewById(R.id.memo_message);//メモの履歴
|
140
|
+
|
115
141
|
if(v.equals(mSendMessage)) {
|
116
142
|
|
117
|
-
|
143
|
+
|
118
144
|
|
119
145
|
String inputText=mInputMessage.getText().toString();
|
120
146
|
|
@@ -136,35 +162,13 @@
|
|
136
162
|
|
137
163
|
|
138
164
|
|
139
|
-
// ActivityからFragmentを取得
|
140
|
-
|
141
|
-
FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
|
142
|
-
|
143
|
-
Fragment fragment = fragmentManager.findFragmentById(R.id.send_message);
|
144
|
-
|
145
|
-
// FragmentのViewを取得
|
146
|
-
|
147
|
-
View view = fragment.getView();
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
mInputMessage = (EditText)view.findViewById(R.id.input_message);//ユーザーが入力するフィールド
|
152
|
-
|
153
|
-
mSendMessage = (Button) view.findViewById(R.id.send_message);//SENDボタン
|
154
|
-
|
155
|
-
mMessageLog = (LinearLayout)view.findViewById(R.id.message_log);//入力履歴を表示するレイアウト
|
156
|
-
|
157
|
-
// mMemoMessage = (TextView) view.findViewById(R.id.memo_message);//メモの履歴
|
158
|
-
|
159
165
|
|
160
166
|
|
161
167
|
//この次はデータベースや
|
162
168
|
|
163
169
|
mSendMessage.setOnClickListener(this);
|
164
170
|
|
165
|
-
|
166
|
-
|
167
|
-
|
171
|
+
|
168
172
|
|
169
173
|
//--時間を取得
|
170
174
|
|
@@ -198,8 +202,6 @@
|
|
198
202
|
|
199
203
|
mMessageLog.addView(memoMessage, 0);
|
200
204
|
|
201
|
-
|
202
|
-
|
203
205
|
mInputMessage.setText("");
|
204
206
|
|
205
207
|
}
|
@@ -218,6 +220,8 @@
|
|
218
220
|
|
219
221
|
|
220
222
|
|
223
|
+
|
224
|
+
|
221
225
|
```
|
222
226
|
|
223
227
|
fragment_my_fragment2.xmlです。
|
2
コードのレベルアップ
test
CHANGED
File without changes
|
test
CHANGED
@@ -46,8 +46,6 @@
|
|
46
46
|
|
47
47
|
|
48
48
|
|
49
|
-
|
50
|
-
|
51
49
|
//とりあえずここにさらなるステップの変数
|
52
50
|
|
53
51
|
private EditText mInputMessage;
|
@@ -80,15 +78,11 @@
|
|
80
78
|
|
81
79
|
|
82
80
|
|
83
|
-
view.findViewById(R.id.send_message).setOnClickListener(
|
81
|
+
view.findViewById(R.id.send_message).setOnClickListener(this);
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
82
|
+
|
83
|
+
|
84
|
+
|
91
|
-
|
85
|
+
/** @Override
|
92
86
|
|
93
87
|
public void onClick(View v){
|
94
88
|
|
@@ -100,30 +94,30 @@
|
|
100
94
|
|
101
95
|
});
|
102
96
|
|
97
|
+
**/
|
98
|
+
|
99
|
+
|
100
|
+
|
103
101
|
return view;
|
104
102
|
|
105
103
|
}
|
106
104
|
|
107
105
|
|
108
106
|
|
109
|
-
|
110
|
-
|
111
107
|
@Override
|
112
108
|
|
113
109
|
public void onClick(View v) {
|
114
110
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
111
|
//SENDボタンが押された時の処理
|
120
112
|
|
121
|
-
String inputText=mInputMessage.getText().toString();
|
122
|
-
|
123
113
|
|
124
114
|
|
125
115
|
if(v.equals(mSendMessage)) {
|
126
116
|
|
117
|
+
//ここがNullPointらしい !!!!!!!!!!!!!!!!!!!!
|
118
|
+
|
119
|
+
String inputText=mInputMessage.getText().toString();
|
120
|
+
|
127
121
|
|
128
122
|
|
129
123
|
|
@@ -194,19 +188,11 @@
|
|
194
188
|
|
195
189
|
|
196
190
|
|
197
|
-
|
198
|
-
|
199
191
|
TextView memoMessage = new TextView(getActivity());
|
200
192
|
|
201
|
-
|
193
|
+
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
194
|
+
|
208
|
-
|
209
|
-
|
195
|
+
|
210
196
|
|
211
197
|
memoMessage.setText(answer+inputText);
|
212
198
|
|
1
コードの変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -46,6 +46,8 @@
|
|
46
46
|
|
47
47
|
|
48
48
|
|
49
|
+
|
50
|
+
|
49
51
|
//とりあえずここにさらなるステップの変数
|
50
52
|
|
51
53
|
private EditText mInputMessage;
|
@@ -82,10 +84,18 @@
|
|
82
84
|
|
83
85
|
|
84
86
|
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
|
85
91
|
@Override
|
86
92
|
|
87
93
|
public void onClick(View v){
|
88
94
|
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
89
99
|
}
|
90
100
|
|
91
101
|
});
|
@@ -96,17 +106,29 @@
|
|
96
106
|
|
97
107
|
|
98
108
|
|
109
|
+
|
110
|
+
|
99
111
|
@Override
|
100
112
|
|
101
113
|
public void onClick(View v) {
|
102
114
|
|
103
115
|
|
104
116
|
|
117
|
+
|
118
|
+
|
119
|
+
//SENDボタンが押された時の処理
|
120
|
+
|
121
|
+
String inputText=mInputMessage.getText().toString();
|
122
|
+
|
123
|
+
|
124
|
+
|
105
125
|
if(v.equals(mSendMessage)) {
|
106
126
|
|
107
127
|
|
108
128
|
|
129
|
+
|
130
|
+
|
109
|
-
if(
|
131
|
+
if(inputText==null||inputText.length()==0){
|
110
132
|
|
111
133
|
|
112
134
|
|
@@ -148,12 +170,6 @@
|
|
148
170
|
|
149
171
|
|
150
172
|
|
151
|
-
//新しく追加するコード143
|
152
|
-
|
153
|
-
String inputText=mInputMessage.getText().toString();
|
154
|
-
|
155
|
-
//コメントアウトした代わりに追加
|
156
|
-
|
157
173
|
|
158
174
|
|
159
175
|
//--時間を取得
|
@@ -172,16 +188,22 @@
|
|
172
188
|
|
173
189
|
answer=String.format(" %1$d/%2$d %3$d:%4$d ",month,day,hour,minute);
|
174
190
|
|
191
|
+
|
192
|
+
|
175
193
|
//--ここまでは、時間
|
176
194
|
|
177
195
|
|
178
196
|
|
197
|
+
|
198
|
+
|
179
199
|
TextView memoMessage = new TextView(getActivity());
|
180
200
|
|
181
201
|
// TextView memoMessage=(TextView)this.getActivity(); これは、間違えだったやつ
|
182
202
|
|
183
203
|
|
184
204
|
|
205
|
+
|
206
|
+
|
185
207
|
//inputText+answerに変更
|
186
208
|
|
187
209
|
// mMemoMessage.setText(inputText);
|
@@ -198,12 +220,18 @@
|
|
198
220
|
|
199
221
|
}
|
200
222
|
|
223
|
+
|
224
|
+
|
225
|
+
|
226
|
+
|
201
227
|
}
|
202
228
|
|
203
229
|
}
|
204
230
|
|
205
231
|
|
206
232
|
|
233
|
+
|
234
|
+
|
207
235
|
```
|
208
236
|
|
209
237
|
fragment_my_fragment2.xmlです。
|