質問編集履歴
10
___
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,11 +1,3 @@
|
|
1
|
-
###ListViewでの遷移について
|
2
|
-
|
3
|
-
Web上のJson形式のファイルを受け取ってそれをlistviewで表示するアプリを作りました。次に遷移するようにしようとしたところ値は持っていってるはずなのですが、
|
4
|
-
|
5
|
-
クリックすると
|
6
|
-
|
7
|
-
|
8
|
-
|
9
1
|
> D/AndroidRuntime: Shutting down VM
|
10
2
|
|
11
3
|
E/AndroidRuntime: FATAL EXCEPTION: main
|
@@ -52,306 +44,4 @@
|
|
52
44
|
|
53
45
|
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
|
54
46
|
|
55
|
-
at android.os.Handler.dispatchMessage(Handler.java:102)
|
56
|
-
|
57
|
-
at android.os.Looper.loop(Looper.java:154)
|
58
|
-
|
59
|
-
at android.app.ActivityThread.main(ActivityThread.java:6077)
|
60
|
-
|
61
|
-
at java.lang.reflect.Method.invoke(Native Method)
|
62
|
-
|
63
|
-
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
|
64
|
-
|
65
|
-
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
というエラーで落ちてしまいます。
|
74
|
-
|
75
|
-
対処法が分かりません。
|
76
|
-
|
77
|
-
どのようにすればいいかご教授お願いします。
|
78
|
-
|
79
|
-
Main.ActivityのonitemclickのところとSub.Activityです。
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
```Java
|
84
|
-
|
85
|
-
package com.list;
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
import android.content.Intent;
|
90
|
-
|
91
|
-
import android.os.Bundle;
|
92
|
-
|
93
|
-
import android.support.v7.app.AppCompatActivity;
|
94
|
-
|
95
|
-
import android.view.View;
|
96
|
-
|
97
|
-
import android.widget.AdapterView;
|
98
|
-
|
99
|
-
import android.widget.ListView;
|
100
|
-
|
101
|
-
import android.widget.Toast;
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
import com.android.volley.RequestQueue;
|
106
|
-
|
107
|
-
import com.android.volley.Response;
|
108
|
-
|
109
|
-
import com.android.volley.VolleyError;
|
110
|
-
|
111
|
-
import com.android.volley.toolbox.StringRequest;
|
112
|
-
|
113
|
-
import com.android.volley.toolbox.Volley;
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
import java.util.List;
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
/**
|
122
|
-
|
123
|
-
* Created by yu on 2017/02/05.
|
124
|
-
|
125
|
-
*/
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
|
130
|
-
|
131
|
-
List<json> sweetsList;
|
132
|
-
|
133
|
-
ListView lv;
|
134
|
-
|
135
|
-
String uri = "URL";
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
@Override
|
140
|
-
|
141
|
-
protected void onCreate(Bundle savedInstanceState) {
|
142
|
-
|
143
|
-
super.onCreate(savedInstanceState);
|
144
|
-
|
145
|
-
setContentView(R.layout.activity_main);
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
lv = (ListView) findViewById(R.id.listView);
|
150
|
-
|
151
|
-
requestData(uri);
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
//lv.setAdapter();
|
156
|
-
|
157
|
-
lv.setOnItemClickListener(this);
|
158
|
-
|
159
|
-
}
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
//画面遷移
|
164
|
-
|
165
|
-
//ListView lv = (ListView) findViewById(R.id.listView);
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
//listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
170
|
-
|
171
|
-
@Override
|
172
|
-
|
173
|
-
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
|
174
|
-
|
175
|
-
{
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
Intent intent = new Intent(getApplication(), SubActivity.class);
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
intent.putExtra("ID", id);
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
// Activity をスイッチする
|
192
|
-
|
193
|
-
startActivity(intent);
|
194
|
-
|
195
|
-
//long get_id = id;
|
196
|
-
|
197
|
-
}
|
198
|
-
|
199
|
-
//});
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
public void requestData(String uri) {
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
StringRequest request = new StringRequest(uri,
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
new Response.Listener<String>(){
|
212
|
-
|
213
|
-
@Override
|
214
|
-
|
215
|
-
public void onResponse(String response) {
|
216
|
-
|
217
|
-
sweetsList = jsonParser.parseData(response);
|
218
|
-
|
219
|
-
Adapter adapter = new Adapter(MainActivity.this, sweetsList);
|
220
|
-
|
221
|
-
lv.setAdapter(adapter);
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
}
|
226
|
-
|
227
|
-
|
47
|
+
at
|
228
|
-
|
229
|
-
//エラー関係
|
230
|
-
|
231
|
-
new Response.ErrorListener() {
|
232
|
-
|
233
|
-
@Override
|
234
|
-
|
235
|
-
public void onErrorResponse(VolleyError error) {
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
Toast.makeText(MainActivity.this, error.getMessage().toString(), Toast.LENGTH_SHORT).show();
|
240
|
-
|
241
|
-
}
|
242
|
-
|
243
|
-
});
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
RequestQueue queue = Volley.newRequestQueue(this);
|
248
|
-
|
249
|
-
queue.add(request);
|
250
|
-
|
251
|
-
}
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
}
|
256
|
-
|
257
|
-
```
|
258
|
-
|
259
|
-
```Java
|
260
|
-
|
261
|
-
package com.list;
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
import android.content.Context;
|
266
|
-
|
267
|
-
import android.content.Intent;
|
268
|
-
|
269
|
-
import android.os.Bundle;
|
270
|
-
|
271
|
-
import android.support.v7.app.AppCompatActivity;
|
272
|
-
|
273
|
-
import android.widget.ImageView;
|
274
|
-
|
275
|
-
import android.widget.ListView;
|
276
|
-
|
277
|
-
import android.widget.TextView;
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
import com.squareup.picasso.Picasso;
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
import java.util.List;
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
public class SubActivity extends AppCompatActivity {
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
private Context context;
|
294
|
-
|
295
|
-
List<json> sList;
|
296
|
-
|
297
|
-
ListView lv;
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
ImageView imageView;
|
302
|
-
|
303
|
-
TextView textView, textView2;
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
protected int id;
|
308
|
-
|
309
|
-
protected String name;
|
310
|
-
|
311
|
-
protected String imgUrl;
|
312
|
-
|
313
|
-
protected String description;
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
@Override
|
318
|
-
|
319
|
-
protected void onCreate(Bundle savedInstanceState) {
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
super.onCreate(savedInstanceState);
|
324
|
-
|
325
|
-
setContentView(R.layout.activity_sub);
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
//MainActivityから受け取る
|
330
|
-
|
331
|
-
Intent intent = getIntent();
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
Long num = intent.getLongExtra("ID", 0);
|
336
|
-
|
337
|
-
Integer id = new Integer(num.toString());
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
imageView =(ImageView) findViewById(R.id.imgUrl);
|
342
|
-
|
343
|
-
textView = (TextView) findViewById(R.id.tvname);
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
textView.setText(Adapter.json[id].getName());
|
348
|
-
|
349
|
-
Picasso.with(context).load(Adapter.json[id].getImgUrl()).into(imageView);
|
350
|
-
|
351
|
-
}
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
}
|
356
|
-
|
357
|
-
```
|
9
引用文化していなかったので再編集
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,7 +4,9 @@
|
|
4
4
|
|
5
5
|
クリックすると
|
6
6
|
|
7
|
+
|
8
|
+
|
7
|
-
>D/AndroidRuntime: Shutting down VM
|
9
|
+
> D/AndroidRuntime: Shutting down VM
|
8
10
|
|
9
11
|
E/AndroidRuntime: FATAL EXCEPTION: main
|
10
12
|
|
8
sub\.activityの追加Adapterの削除
test
CHANGED
File without changes
|
test
CHANGED
@@ -256,122 +256,100 @@
|
|
256
256
|
|
257
257
|
```Java
|
258
258
|
|
259
|
+
package com.list;
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
import android.content.Context;
|
264
|
+
|
265
|
+
import android.content.Intent;
|
266
|
+
|
267
|
+
import android.os.Bundle;
|
268
|
+
|
269
|
+
import android.support.v7.app.AppCompatActivity;
|
270
|
+
|
271
|
+
import android.widget.ImageView;
|
272
|
+
|
273
|
+
import android.widget.ListView;
|
274
|
+
|
275
|
+
import android.widget.TextView;
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
import com.squareup.picasso.Picasso;
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
import java.util.List;
|
284
|
+
|
285
|
+
|
286
|
+
|
259
|
-
public class A
|
287
|
+
public class SubActivity extends AppCompatActivity {
|
260
|
-
|
261
|
-
|
288
|
+
|
289
|
+
|
262
290
|
|
263
291
|
private Context context;
|
264
292
|
|
265
|
-
|
293
|
+
List<json> sList;
|
294
|
+
|
266
|
-
|
295
|
+
ListView lv;
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
ImageView imageView;
|
300
|
+
|
267
|
-
|
301
|
+
TextView textView, textView2;
|
268
|
-
|
269
|
-
|
302
|
+
|
270
|
-
|
303
|
+
|
304
|
+
|
271
|
-
pr
|
305
|
+
protected int id;
|
272
|
-
|
306
|
+
|
273
|
-
pr
|
307
|
+
protected String name;
|
308
|
+
|
274
|
-
|
309
|
+
protected String imgUrl;
|
310
|
+
|
311
|
+
protected String description;
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
@Override
|
316
|
+
|
275
|
-
p
|
317
|
+
protected void onCreate(Bundle savedInstanceState) {
|
276
|
-
|
318
|
+
|
319
|
+
|
320
|
+
|
277
|
-
super
|
321
|
+
super.onCreate(savedInstanceState);
|
322
|
+
|
278
|
-
|
323
|
+
setContentView(R.layout.activity_sub);
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
//MainActivityから受け取る
|
328
|
+
|
279
|
-
t
|
329
|
+
Intent intent = getIntent();
|
280
|
-
|
330
|
+
|
331
|
+
|
332
|
+
|
281
|
-
|
333
|
+
Long num = intent.getLongExtra("ID", 0);
|
282
|
-
|
334
|
+
|
283
|
-
|
335
|
+
Integer id = new Integer(num.toString());
|
284
|
-
|
285
|
-
|
336
|
+
|
286
|
-
|
287
|
-
|
337
|
+
|
288
|
-
|
338
|
+
|
289
|
-
image
|
339
|
+
imageView =(ImageView) findViewById(R.id.imgUrl);
|
290
|
-
|
291
|
-
|
292
|
-
|
340
|
+
|
293
|
-
|
341
|
+
textView = (TextView) findViewById(R.id.tvname);
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
textView.setText(Adapter.json[id].getName());
|
346
|
+
|
347
|
+
Picasso.with(context).load(Adapter.json[id].getImgUrl()).into(imageView);
|
294
348
|
|
295
349
|
}
|
296
350
|
|
297
|
-
|
351
|
+
|
298
|
-
|
299
|
-
|
352
|
+
|
300
|
-
|
301
|
-
TextView _description;
|
302
|
-
|
303
|
-
//TextView _plateform;
|
304
|
-
|
305
|
-
ImageView _imgUrl;
|
306
|
-
|
307
|
-
|
353
|
+
}
|
308
|
-
|
309
|
-
@Override
|
310
|
-
|
311
|
-
public int getCount() {
|
312
|
-
|
313
|
-
return sList.size();
|
314
|
-
|
315
|
-
}
|
316
|
-
|
317
|
-
@Nullable
|
318
|
-
|
319
|
-
@Override
|
320
|
-
|
321
|
-
public json getItem(int position) {
|
322
|
-
|
323
|
-
return sList.get(position);
|
324
|
-
|
325
|
-
}
|
326
|
-
|
327
|
-
@Override
|
328
|
-
|
329
|
-
public long getItemId(int position) {
|
330
|
-
|
331
|
-
return position;
|
332
|
-
|
333
|
-
}
|
334
|
-
|
335
|
-
@Override
|
336
|
-
|
337
|
-
public View getView(int position, View convertView, ViewGroup viewGroup) {
|
338
|
-
|
339
|
-
final json s = sList.get(position);
|
340
|
-
|
341
|
-
final com.list.Adapter.ViewHolder holder;
|
342
|
-
|
343
|
-
if(convertView == null) {
|
344
|
-
|
345
|
-
convertView = inflater.inflate(R.layout.list_item_templates,null);
|
346
|
-
|
347
|
-
//convertView = inflater.inflate(R.layout.list_item_detail,null);
|
348
|
-
|
349
|
-
holder = new com.list.Adapter.ViewHolder();
|
350
|
-
|
351
|
-
holder._name = (TextView) convertView.findViewById(R.id.tvname);
|
352
|
-
|
353
|
-
holder._description = (TextView) convertView.findViewById(R.id.tvdescription);
|
354
|
-
|
355
|
-
//holder._plateform = (TextView) convertView.findViewById(R.id.tvplateform);
|
356
|
-
|
357
|
-
convertView.setTag(holder);
|
358
|
-
|
359
|
-
}
|
360
|
-
|
361
|
-
else {
|
362
|
-
|
363
|
-
holder = (com.list.Adapter.ViewHolder) convertView.getTag();
|
364
|
-
|
365
|
-
}
|
366
|
-
|
367
|
-
holder._name.setText(s.getName().toString());
|
368
|
-
|
369
|
-
holder._description.setText(s.getDescription().toString());
|
370
|
-
|
371
|
-
//holder._plateform.setText(s.getPlatforms().toString());
|
372
|
-
|
373
|
-
Bitmap bitmap = imageCache.get(Integer.parseInt(s.getId()));
|
374
|
-
|
375
|
-
holder._imgUrl = (ImageView) convertView.findViewById(R.id.imgUrl);
|
376
354
|
|
377
355
|
```
|
7
Java内の編集
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,13 +4,13 @@
|
|
4
4
|
|
5
5
|
クリックすると
|
6
6
|
|
7
|
-
>
|
7
|
+
>D/AndroidRuntime: Shutting down VM
|
8
8
|
|
9
9
|
E/AndroidRuntime: FATAL EXCEPTION: main
|
10
10
|
|
11
|
-
Process: com.list, PID: 24
|
11
|
+
Process: com.list, PID: 2942
|
12
|
-
|
12
|
+
|
13
|
-
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.list
|
13
|
+
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.list/
|
14
14
|
|
15
15
|
com.list.SubActivity}: java.lang.NullPointerException: Attempt to read from null array
|
16
16
|
|
@@ -36,7 +36,7 @@
|
|
36
36
|
|
37
37
|
Caused by: java.lang.NullPointerException: Attempt to read from null array
|
38
38
|
|
39
|
-
at com.list.SubActivity.onCreate(SubActivity.java:
|
39
|
+
at com.list.SubActivity.onCreate(SubActivity.java:54)
|
40
40
|
|
41
41
|
at android.app.Activity.performCreate(Activity.java:6664)
|
42
42
|
|
@@ -62,7 +62,7 @@
|
|
62
62
|
|
63
63
|
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
|
64
64
|
|
65
|
-
|
65
|
+
|
66
66
|
|
67
67
|
|
68
68
|
|
@@ -80,14 +80,60 @@
|
|
80
80
|
|
81
81
|
```Java
|
82
82
|
|
83
|
+
package com.list;
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
import android.content.Intent;
|
88
|
+
|
89
|
+
import android.os.Bundle;
|
90
|
+
|
91
|
+
import android.support.v7.app.AppCompatActivity;
|
92
|
+
|
93
|
+
import android.view.View;
|
94
|
+
|
95
|
+
import android.widget.AdapterView;
|
96
|
+
|
97
|
+
import android.widget.ListView;
|
98
|
+
|
99
|
+
import android.widget.Toast;
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
import com.android.volley.RequestQueue;
|
104
|
+
|
105
|
+
import com.android.volley.Response;
|
106
|
+
|
107
|
+
import com.android.volley.VolleyError;
|
108
|
+
|
109
|
+
import com.android.volley.toolbox.StringRequest;
|
110
|
+
|
111
|
+
import com.android.volley.toolbox.Volley;
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
import java.util.List;
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
/**
|
120
|
+
|
121
|
+
* Created by yu on 2017/02/05.
|
122
|
+
|
123
|
+
*/
|
124
|
+
|
125
|
+
|
126
|
+
|
83
127
|
public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
|
84
128
|
|
85
|
-
List<json> sList;
|
129
|
+
List<json> sweetsList;
|
86
130
|
|
87
131
|
ListView lv;
|
88
132
|
|
89
133
|
String uri = "URL";
|
90
134
|
|
135
|
+
|
136
|
+
|
91
137
|
@Override
|
92
138
|
|
93
139
|
protected void onCreate(Bundle savedInstanceState) {
|
@@ -96,35 +142,49 @@
|
|
96
142
|
|
97
143
|
setContentView(R.layout.activity_main);
|
98
144
|
|
145
|
+
|
146
|
+
|
99
147
|
lv = (ListView) findViewById(R.id.listView);
|
100
148
|
|
101
149
|
requestData(uri);
|
102
150
|
|
151
|
+
|
152
|
+
|
153
|
+
//lv.setAdapter();
|
154
|
+
|
103
155
|
lv.setOnItemClickListener(this);
|
104
156
|
|
105
157
|
}
|
106
158
|
|
159
|
+
|
160
|
+
|
107
161
|
//画面遷移
|
108
162
|
|
163
|
+
//ListView lv = (ListView) findViewById(R.id.listView);
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
//listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
168
|
+
|
109
169
|
@Override
|
110
170
|
|
111
171
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
|
112
172
|
|
113
173
|
{
|
114
174
|
|
175
|
+
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
|
180
|
+
|
115
181
|
Intent intent = new Intent(getApplication(), SubActivity.class);
|
116
182
|
|
183
|
+
|
184
|
+
|
117
185
|
intent.putExtra("ID", id);
|
118
186
|
|
119
|
-
|
187
|
+
|
120
|
-
|
121
|
-
/*ListView listView = (ListView) parent;
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
String item = (String) listView.getItemAtPosition(position);*/
|
126
|
-
|
127
|
-
//intent.putExtra("ID", adapter.getItem(position));
|
128
188
|
|
129
189
|
// Activity をスイッチする
|
130
190
|
|
@@ -134,22 +194,32 @@
|
|
134
194
|
|
135
195
|
}
|
136
196
|
|
197
|
+
//});
|
198
|
+
|
199
|
+
|
200
|
+
|
137
201
|
public void requestData(String uri) {
|
138
202
|
|
203
|
+
|
204
|
+
|
139
205
|
StringRequest request = new StringRequest(uri,
|
140
206
|
|
207
|
+
|
208
|
+
|
141
209
|
new Response.Listener<String>(){
|
142
210
|
|
143
211
|
@Override
|
144
212
|
|
145
213
|
public void onResponse(String response) {
|
146
214
|
|
147
|
-
sList = jsonParser.parseData(response);
|
215
|
+
sweetsList = jsonParser.parseData(response);
|
148
|
-
|
216
|
+
|
149
|
-
Adapter adapter = new Adapter(MainActivity.this, sList);
|
217
|
+
Adapter adapter = new Adapter(MainActivity.this, sweetsList);
|
150
218
|
|
151
219
|
lv.setAdapter(adapter);
|
152
220
|
|
221
|
+
|
222
|
+
|
153
223
|
}
|
154
224
|
|
155
225
|
},
|
@@ -162,196 +232,146 @@
|
|
162
232
|
|
163
233
|
public void onErrorResponse(VolleyError error) {
|
164
234
|
|
235
|
+
|
236
|
+
|
165
237
|
Toast.makeText(MainActivity.this, error.getMessage().toString(), Toast.LENGTH_SHORT).show();
|
166
238
|
|
167
239
|
}
|
168
240
|
|
169
241
|
});
|
170
242
|
|
243
|
+
|
244
|
+
|
171
245
|
RequestQueue queue = Volley.newRequestQueue(this);
|
172
246
|
|
173
247
|
queue.add(request);
|
174
248
|
|
175
249
|
}
|
176
250
|
|
251
|
+
|
252
|
+
|
177
253
|
}
|
178
254
|
|
179
|
-
|
180
|
-
|
181
255
|
```
|
182
256
|
|
183
257
|
```Java
|
184
258
|
|
185
|
-
public class
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
I
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
pr
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
protecte
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
s
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
}
|
259
|
+
public class Adapter extends ArrayAdapter<json> {
|
260
|
+
|
261
|
+
public static json[] json;
|
262
|
+
|
263
|
+
private Context context;
|
264
|
+
|
265
|
+
private List<json> sList;
|
266
|
+
|
267
|
+
private LayoutInflater inflater = null;
|
268
|
+
|
269
|
+
//public static final String IMAGE_BASEURL = "";
|
270
|
+
|
271
|
+
private LruCache<Integer,Bitmap> imageCache;
|
272
|
+
|
273
|
+
private RequestQueue queue;
|
274
|
+
|
275
|
+
public Adapter(Context context, List<json> list) {
|
276
|
+
|
277
|
+
super(context, 0);
|
278
|
+
|
279
|
+
this.context = context;
|
280
|
+
|
281
|
+
this.sList = list;
|
282
|
+
|
283
|
+
inflater = LayoutInflater.from(context);
|
284
|
+
|
285
|
+
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
|
286
|
+
|
287
|
+
final int cacheSize = maxMemory / 8;
|
288
|
+
|
289
|
+
imageCache = new LruCache<>(cacheSize);
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
queue = Volley.newRequestQueue(context);
|
294
|
+
|
295
|
+
}
|
296
|
+
|
297
|
+
public class ViewHolder {
|
298
|
+
|
299
|
+
TextView _name;
|
300
|
+
|
301
|
+
TextView _description;
|
302
|
+
|
303
|
+
//TextView _plateform;
|
304
|
+
|
305
|
+
ImageView _imgUrl;
|
306
|
+
|
307
|
+
}
|
308
|
+
|
309
|
+
@Override
|
310
|
+
|
311
|
+
public int getCount() {
|
312
|
+
|
313
|
+
return sList.size();
|
314
|
+
|
315
|
+
}
|
316
|
+
|
317
|
+
@Nullable
|
318
|
+
|
319
|
+
@Override
|
320
|
+
|
321
|
+
public json getItem(int position) {
|
322
|
+
|
323
|
+
return sList.get(position);
|
324
|
+
|
325
|
+
}
|
326
|
+
|
327
|
+
@Override
|
328
|
+
|
329
|
+
public long getItemId(int position) {
|
330
|
+
|
331
|
+
return position;
|
332
|
+
|
333
|
+
}
|
334
|
+
|
335
|
+
@Override
|
336
|
+
|
337
|
+
public View getView(int position, View convertView, ViewGroup viewGroup) {
|
338
|
+
|
339
|
+
final json s = sList.get(position);
|
340
|
+
|
341
|
+
final com.list.Adapter.ViewHolder holder;
|
342
|
+
|
343
|
+
if(convertView == null) {
|
344
|
+
|
345
|
+
convertView = inflater.inflate(R.layout.list_item_templates,null);
|
346
|
+
|
347
|
+
//convertView = inflater.inflate(R.layout.list_item_detail,null);
|
348
|
+
|
349
|
+
holder = new com.list.Adapter.ViewHolder();
|
350
|
+
|
351
|
+
holder._name = (TextView) convertView.findViewById(R.id.tvname);
|
352
|
+
|
353
|
+
holder._description = (TextView) convertView.findViewById(R.id.tvdescription);
|
354
|
+
|
355
|
+
//holder._plateform = (TextView) convertView.findViewById(R.id.tvplateform);
|
356
|
+
|
357
|
+
convertView.setTag(holder);
|
358
|
+
|
359
|
+
}
|
360
|
+
|
361
|
+
else {
|
362
|
+
|
363
|
+
holder = (com.list.Adapter.ViewHolder) convertView.getTag();
|
364
|
+
|
365
|
+
}
|
366
|
+
|
367
|
+
holder._name.setText(s.getName().toString());
|
368
|
+
|
369
|
+
holder._description.setText(s.getDescription().toString());
|
370
|
+
|
371
|
+
//holder._plateform.setText(s.getPlatforms().toString());
|
372
|
+
|
373
|
+
Bitmap bitmap = imageCache.get(Integer.parseInt(s.getId()));
|
374
|
+
|
375
|
+
holder._imgUrl = (ImageView) convertView.findViewById(R.id.imgUrl);
|
234
376
|
|
235
377
|
```
|
236
|
-
|
237
|
-
```Java
|
238
|
-
|
239
|
-
public class Adapter extends ArrayAdapter<json> {
|
240
|
-
|
241
|
-
public static json[] json;
|
242
|
-
|
243
|
-
private Context context;
|
244
|
-
|
245
|
-
private List<json> sList;
|
246
|
-
|
247
|
-
private LayoutInflater inflater = null;
|
248
|
-
|
249
|
-
//public static final String IMAGE_BASEURL = "";
|
250
|
-
|
251
|
-
private LruCache<Integer,Bitmap> imageCache;
|
252
|
-
|
253
|
-
private RequestQueue queue;
|
254
|
-
|
255
|
-
public Adapter(Context context, List<json> list) {
|
256
|
-
|
257
|
-
super(context, 0);
|
258
|
-
|
259
|
-
this.context = context;
|
260
|
-
|
261
|
-
this.sList = list;
|
262
|
-
|
263
|
-
inflater = LayoutInflater.from(context);
|
264
|
-
|
265
|
-
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
|
266
|
-
|
267
|
-
final int cacheSize = maxMemory / 8;
|
268
|
-
|
269
|
-
imageCache = new LruCache<>(cacheSize);
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
queue = Volley.newRequestQueue(context);
|
274
|
-
|
275
|
-
}
|
276
|
-
|
277
|
-
public class ViewHolder {
|
278
|
-
|
279
|
-
TextView _name;
|
280
|
-
|
281
|
-
TextView _description;
|
282
|
-
|
283
|
-
//TextView _plateform;
|
284
|
-
|
285
|
-
ImageView _imgUrl;
|
286
|
-
|
287
|
-
}
|
288
|
-
|
289
|
-
@Override
|
290
|
-
|
291
|
-
public int getCount() {
|
292
|
-
|
293
|
-
return sList.size();
|
294
|
-
|
295
|
-
}
|
296
|
-
|
297
|
-
@Nullable
|
298
|
-
|
299
|
-
@Override
|
300
|
-
|
301
|
-
public json getItem(int position) {
|
302
|
-
|
303
|
-
return sList.get(position);
|
304
|
-
|
305
|
-
}
|
306
|
-
|
307
|
-
@Override
|
308
|
-
|
309
|
-
public long getItemId(int position) {
|
310
|
-
|
311
|
-
return position;
|
312
|
-
|
313
|
-
}
|
314
|
-
|
315
|
-
@Override
|
316
|
-
|
317
|
-
public View getView(int position, View convertView, ViewGroup viewGroup) {
|
318
|
-
|
319
|
-
final json s = sList.get(position);
|
320
|
-
|
321
|
-
final com.list.Adapter.ViewHolder holder;
|
322
|
-
|
323
|
-
if(convertView == null) {
|
324
|
-
|
325
|
-
convertView = inflater.inflate(R.layout.list_item_templates,null);
|
326
|
-
|
327
|
-
//convertView = inflater.inflate(R.layout.list_item_detail,null);
|
328
|
-
|
329
|
-
holder = new com.list.Adapter.ViewHolder();
|
330
|
-
|
331
|
-
holder._name = (TextView) convertView.findViewById(R.id.tvname);
|
332
|
-
|
333
|
-
holder._description = (TextView) convertView.findViewById(R.id.tvdescription);
|
334
|
-
|
335
|
-
//holder._plateform = (TextView) convertView.findViewById(R.id.tvplateform);
|
336
|
-
|
337
|
-
convertView.setTag(holder);
|
338
|
-
|
339
|
-
}
|
340
|
-
|
341
|
-
else {
|
342
|
-
|
343
|
-
holder = (com.list.Adapter.ViewHolder) convertView.getTag();
|
344
|
-
|
345
|
-
}
|
346
|
-
|
347
|
-
holder._name.setText(s.getName().toString());
|
348
|
-
|
349
|
-
holder._description.setText(s.getDescription().toString());
|
350
|
-
|
351
|
-
//holder._plateform.setText(s.getPlatforms().toString());
|
352
|
-
|
353
|
-
Bitmap bitmap = imageCache.get(Integer.parseInt(s.getId()));
|
354
|
-
|
355
|
-
holder._imgUrl = (ImageView) convertView.findViewById(R.id.imgUrl);
|
356
|
-
|
357
|
-
```
|
6
エラー内容の追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,101 +4,67 @@
|
|
4
4
|
|
5
5
|
クリックすると
|
6
6
|
|
7
|
-
>
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
java.lang.
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
at android.c
|
18
|
-
|
19
|
-
at
|
20
|
-
|
21
|
-
at android.app.Activity
|
22
|
-
|
23
|
-
at android.app.
|
24
|
-
|
25
|
-
at android.
|
26
|
-
|
27
|
-
at android.
|
28
|
-
|
29
|
-
at android.app.ActivityThread.
|
30
|
-
|
31
|
-
at a
|
32
|
-
|
33
|
-
at android.
|
34
|
-
|
35
|
-
at android.os.
|
36
|
-
|
37
|
-
a
|
38
|
-
|
39
|
-
at
|
40
|
-
|
41
|
-
at
|
42
|
-
|
43
|
-
at
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
at android.a
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
at android.app.ActivityThread.
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
at android.a
|
62
|
-
|
63
|
-
at android.
|
64
|
-
|
65
|
-
at
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
at java.lang.reflect.Method.invoke(Native Method)
|
70
|
-
|
71
|
-
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
|
72
|
-
|
73
|
-
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
|
74
|
-
|
75
|
-
Caused by: java.lang.NullPointerException: Attempt to read from null array
|
76
|
-
|
77
|
-
at com.list.SubActivity.onCreate(SubActivity.java:86)
|
78
|
-
|
79
|
-
at android.app.Activity.performCreate(Activity.java:6664)
|
80
|
-
|
81
|
-
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
|
82
|
-
|
83
|
-
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
|
84
|
-
|
85
|
-
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
|
86
|
-
|
87
|
-
at android.app.ActivityThread.-wrap12(ActivityThread.java)
|
88
|
-
|
89
|
-
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
|
90
|
-
|
91
|
-
at android.os.Handler.dispatchMessage(Handler.java:102)
|
92
|
-
|
93
|
-
at android.os.Looper.loop(Looper.java:154)
|
94
|
-
|
95
|
-
at android.app.ActivityThread.main(ActivityThread.java:6077)
|
96
|
-
|
97
|
-
at java.lang.reflect.Method.invoke(Native Method)
|
98
|
-
|
99
|
-
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
|
100
|
-
|
101
|
-
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
|
7
|
+
>--------- beginning of crash
|
8
|
+
|
9
|
+
E/AndroidRuntime: FATAL EXCEPTION: main
|
10
|
+
|
11
|
+
Process: com.list, PID: 2415
|
12
|
+
|
13
|
+
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.list
|
14
|
+
|
15
|
+
com.list.SubActivity}: java.lang.NullPointerException: Attempt to read from null array
|
16
|
+
|
17
|
+
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
|
18
|
+
|
19
|
+
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
|
20
|
+
|
21
|
+
at android.app.ActivityThread.-wrap12(ActivityThread.java)
|
22
|
+
|
23
|
+
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
|
24
|
+
|
25
|
+
at android.os.Handler.dispatchMessage(Handler.java:102)
|
26
|
+
|
27
|
+
at android.os.Looper.loop(Looper.java:154)
|
28
|
+
|
29
|
+
at android.app.ActivityThread.main(ActivityThread.java:6077)
|
30
|
+
|
31
|
+
at java.lang.reflect.Method.invoke(Native Method)
|
32
|
+
|
33
|
+
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
|
34
|
+
|
35
|
+
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
|
36
|
+
|
37
|
+
Caused by: java.lang.NullPointerException: Attempt to read from null array
|
38
|
+
|
39
|
+
at com.list.SubActivity.onCreate(SubActivity.java:86)
|
40
|
+
|
41
|
+
at android.app.Activity.performCreate(Activity.java:6664)
|
42
|
+
|
43
|
+
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
|
44
|
+
|
45
|
+
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
|
46
|
+
|
47
|
+
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
|
48
|
+
|
49
|
+
at android.app.ActivityThread.-wrap12(ActivityThread.java)
|
50
|
+
|
51
|
+
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
|
52
|
+
|
53
|
+
at android.os.Handler.dispatchMessage(Handler.java:102)
|
54
|
+
|
55
|
+
at android.os.Looper.loop(Looper.java:154)
|
56
|
+
|
57
|
+
at android.app.ActivityThread.main(ActivityThread.java:6077)
|
58
|
+
|
59
|
+
at java.lang.reflect.Method.invoke(Native Method)
|
60
|
+
|
61
|
+
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
|
62
|
+
|
63
|
+
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
|
64
|
+
|
65
|
+
Application terminated.
|
66
|
+
|
67
|
+
|
102
68
|
|
103
69
|
|
104
70
|
|
5
sub\.Activity内のコードを一部変更&エラー内容の追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -102,7 +102,9 @@
|
|
102
102
|
|
103
103
|
|
104
104
|
|
105
|
-
というエラーで落ちてしまいます。
|
105
|
+
というエラーで落ちてしまいます。
|
106
|
+
|
107
|
+
対処法が分かりません。
|
106
108
|
|
107
109
|
どのようにすればいいかご教授お願いします。
|
108
110
|
|
@@ -246,7 +248,9 @@
|
|
246
248
|
|
247
249
|
Intent intent = getIntent();
|
248
250
|
|
249
|
-
|
251
|
+
Long num = intent.getLongExtra("ID", 0);
|
252
|
+
|
253
|
+
Integer id = new Integer(num.toString());
|
250
254
|
|
251
255
|
|
252
256
|
|
4
xmlを削除
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|
3
エラー内容の追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,7 +4,101 @@
|
|
4
4
|
|
5
5
|
クリックすると
|
6
6
|
|
7
|
+
> W/Bundle: Key ID expected Integer but value was a java.lang.Long.
|
8
|
+
|
9
|
+
The default value 1 was returned. W/Bundle: Attempt to cast generated internal exception:
|
10
|
+
|
11
|
+
java.lang.ClassCastException: java.lang.Long cannot be cast to
|
12
|
+
|
13
|
+
java.lang.Integer
|
14
|
+
|
15
|
+
at android.os.BaseBundle.getInt(BaseBundle.java:873)
|
16
|
+
|
17
|
+
at android.content.Intent.getIntExtra(Intent.java:6146)
|
18
|
+
|
19
|
+
at com.list.SubActivity.onCreate(SubActivity.java:63)
|
20
|
+
|
21
|
+
at android.app.Activity.performCreate(Activity.java:6664)
|
22
|
+
|
23
|
+
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
|
24
|
+
|
25
|
+
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
|
26
|
+
|
27
|
+
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
|
28
|
+
|
29
|
+
at android.app.ActivityThread.-wrap12(ActivityThread.java)
|
30
|
+
|
31
|
+
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
|
32
|
+
|
33
|
+
at android.os.Handler.dispatchMessage(Handler.java:102)
|
34
|
+
|
35
|
+
at android.os.Looper.loop(Looper.java:154)
|
36
|
+
|
37
|
+
at android.app.ActivityThread.main(ActivityThread.java:6077)
|
38
|
+
|
39
|
+
at java.lang.reflect.Method.invoke(Native Method)
|
40
|
+
|
41
|
+
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
|
42
|
+
|
43
|
+
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) D/AndroidRuntime: Shutting down VM E/AndroidRuntime: FATAL EXCEPTION: main
|
44
|
+
|
45
|
+
Process: com.list, PID: 2414
|
46
|
+
|
47
|
+
java.lang.RuntimeException: Unable to start activity
|
48
|
+
|
49
|
+
ComponentInfo{com.list/com.list.SubActivity}:
|
50
|
+
|
7
|
-
|
51
|
+
java.lang.NullPointerException: Attempt to read from null array
|
52
|
+
|
53
|
+
at android.app.ActivityThread.performLaunchActivity(ActivityThread.
|
54
|
+
|
55
|
+
java:2646)
|
56
|
+
|
57
|
+
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
|
58
|
+
|
59
|
+
at android.app.ActivityThread.-wrap12(ActivityThread.java)
|
60
|
+
|
61
|
+
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
|
62
|
+
|
63
|
+
at android.os.Handler.dispatchMessage(Handler.java:102)
|
64
|
+
|
65
|
+
at android.os.Looper.loop(Looper.java:154)
|
66
|
+
|
67
|
+
at android.app.ActivityThread.main(ActivityThread.java:6077)
|
68
|
+
|
69
|
+
at java.lang.reflect.Method.invoke(Native Method)
|
70
|
+
|
71
|
+
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
|
72
|
+
|
73
|
+
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
|
74
|
+
|
75
|
+
Caused by: java.lang.NullPointerException: Attempt to read from null array
|
76
|
+
|
77
|
+
at com.list.SubActivity.onCreate(SubActivity.java:86)
|
78
|
+
|
79
|
+
at android.app.Activity.performCreate(Activity.java:6664)
|
80
|
+
|
81
|
+
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
|
82
|
+
|
83
|
+
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
|
84
|
+
|
85
|
+
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
|
86
|
+
|
87
|
+
at android.app.ActivityThread.-wrap12(ActivityThread.java)
|
88
|
+
|
89
|
+
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
|
90
|
+
|
91
|
+
at android.os.Handler.dispatchMessage(Handler.java:102)
|
92
|
+
|
93
|
+
at android.os.Looper.loop(Looper.java:154)
|
94
|
+
|
95
|
+
at android.app.ActivityThread.main(ActivityThread.java:6077)
|
96
|
+
|
97
|
+
at java.lang.reflect.Method.invoke(Native Method)
|
98
|
+
|
99
|
+
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
|
100
|
+
|
101
|
+
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
|
8
102
|
|
9
103
|
|
10
104
|
|
@@ -168,55 +262,13 @@
|
|
168
262
|
|
169
263
|
}
|
170
264
|
|
171
|
-
/*public void requestData(String uri) {
|
172
|
-
|
173
|
-
StringRequest request = new StringRequest(uri,
|
174
|
-
|
175
|
-
new Response.Listener<String>(){
|
176
|
-
|
177
|
-
@Override
|
178
|
-
|
179
|
-
public void onResponse(String response) {
|
180
|
-
|
181
|
-
sList = jsonParser.parseData(response);
|
182
|
-
|
183
|
-
Adapter adapter = new Adapter(SubActivity.this, sList);
|
184
|
-
|
185
|
-
lv.setAdapter(adapter);
|
186
|
-
|
187
|
-
}
|
188
|
-
|
189
|
-
},
|
190
|
-
|
191
|
-
//エラー
|
192
|
-
|
193
|
-
new Response.ErrorListener() {
|
194
|
-
|
195
|
-
@Override
|
196
|
-
|
197
|
-
public void onErrorResponse(VolleyError error) {
|
198
|
-
|
199
|
-
Toast.makeText(SubActivity.this, error.getMessage().toString(), Toast.LENGTH_SHORT).show();
|
200
|
-
|
201
|
-
}
|
202
|
-
|
203
|
-
});
|
204
|
-
|
205
|
-
RequestQueue queue = Volley.newRequestQueue(this);
|
206
|
-
|
207
|
-
queue.add(request);
|
208
|
-
|
209
|
-
}
|
210
|
-
|
211
|
-
}*/
|
212
|
-
|
213
265
|
```
|
214
266
|
|
215
267
|
```Java
|
216
268
|
|
217
269
|
public class Adapter extends ArrayAdapter<json> {
|
218
270
|
|
219
|
-
public static json[] json;
|
271
|
+
public static json[] json;
|
220
272
|
|
221
273
|
private Context context;
|
222
274
|
|
@@ -296,7 +348,7 @@
|
|
296
348
|
|
297
349
|
final json s = sList.get(position);
|
298
350
|
|
299
|
-
final
|
351
|
+
final com.list.Adapter.ViewHolder holder;
|
300
352
|
|
301
353
|
if(convertView == null) {
|
302
354
|
|
@@ -304,7 +356,7 @@
|
|
304
356
|
|
305
357
|
//convertView = inflater.inflate(R.layout.list_item_detail,null);
|
306
358
|
|
307
|
-
holder = new
|
359
|
+
holder = new com.list.Adapter.ViewHolder();
|
308
360
|
|
309
361
|
holder._name = (TextView) convertView.findViewById(R.id.tvname);
|
310
362
|
|
@@ -318,7 +370,7 @@
|
|
318
370
|
|
319
371
|
else {
|
320
372
|
|
321
|
-
holder = (
|
373
|
+
holder = (com.list.Adapter.ViewHolder) convertView.getTag();
|
322
374
|
|
323
375
|
}
|
324
376
|
|
@@ -333,127 +385,3 @@
|
|
333
385
|
holder._imgUrl = (ImageView) convertView.findViewById(R.id.imgUrl);
|
334
386
|
|
335
387
|
```
|
336
|
-
|
337
|
-
```xml
|
338
|
-
|
339
|
-
activity_main
|
340
|
-
|
341
|
-
<?xml version="1.0" encoding="utf-8"?>
|
342
|
-
|
343
|
-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
344
|
-
|
345
|
-
xmlns:tools="http://schemas.android.com/tools"
|
346
|
-
|
347
|
-
android:layout_width="match_parent"
|
348
|
-
|
349
|
-
android:layout_height="match_parent"
|
350
|
-
|
351
|
-
tools:context="jp.ac.dhu.list.MainActivity">
|
352
|
-
|
353
|
-
<ListView
|
354
|
-
|
355
|
-
android:layout_width="wrap_content"
|
356
|
-
|
357
|
-
android:layout_height="wrap_content"
|
358
|
-
|
359
|
-
android:id="@+id/listView"
|
360
|
-
|
361
|
-
android:layout_alignParentTop="true"
|
362
|
-
|
363
|
-
android:layout_alignParentLeft="true"
|
364
|
-
|
365
|
-
android:layout_alignParentStart="true" />
|
366
|
-
|
367
|
-
</RelativeLayout>
|
368
|
-
|
369
|
-
```
|
370
|
-
|
371
|
-
```xml
|
372
|
-
|
373
|
-
activity_sub
|
374
|
-
|
375
|
-
<?xml version="1.0" encoding="utf-8"?>
|
376
|
-
|
377
|
-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
378
|
-
|
379
|
-
xmlns:tools="http://schemas.android.com/tools"
|
380
|
-
|
381
|
-
android:layout_width="match_parent"
|
382
|
-
|
383
|
-
android:layout_height="match_parent"
|
384
|
-
|
385
|
-
tools:context="jp.ac.dhu.list.SubActivity">
|
386
|
-
|
387
|
-
<ImageView
|
388
|
-
|
389
|
-
android:layout_width="70dp"
|
390
|
-
|
391
|
-
android:layout_height="70dp"
|
392
|
-
|
393
|
-
android:layout_marginLeft="12dp"
|
394
|
-
|
395
|
-
android:layout_marginTop="14dp"
|
396
|
-
|
397
|
-
android:id="@+id/imgUrl"
|
398
|
-
|
399
|
-
android:paddingBottom="10dp"
|
400
|
-
|
401
|
-
android:layout_alignParentTop="true"
|
402
|
-
|
403
|
-
android:layout_alignParentLeft="true"
|
404
|
-
|
405
|
-
android:layout_alignParentStart="true" />
|
406
|
-
|
407
|
-
<TextView
|
408
|
-
|
409
|
-
android:layout_width="match_parent"
|
410
|
-
|
411
|
-
android:layout_height="wrap_content"
|
412
|
-
|
413
|
-
android:textSize="18sp"
|
414
|
-
|
415
|
-
android:id="@+id/tvname"
|
416
|
-
|
417
|
-
android:paddingLeft="4dp"
|
418
|
-
|
419
|
-
android:paddingRight="5dp"
|
420
|
-
|
421
|
-
android:layout_alignTop="@+id/imgUrl"
|
422
|
-
|
423
|
-
android:layout_toRightOf="@+id/imgUrl"
|
424
|
-
|
425
|
-
android:layout_toEndOf="@+id/imgUrl" />
|
426
|
-
|
427
|
-
<TextView
|
428
|
-
|
429
|
-
android:layout_width="wrap_content"
|
430
|
-
|
431
|
-
android:layout_height="wrap_content"
|
432
|
-
|
433
|
-
android:text="Small Text"
|
434
|
-
|
435
|
-
android:lines="1"
|
436
|
-
|
437
|
-
android:ellipsize="end"
|
438
|
-
|
439
|
-
android:paddingLeft="4dp"
|
440
|
-
|
441
|
-
android:paddingRight="5dp"
|
442
|
-
|
443
|
-
android:textSize="12sp"
|
444
|
-
|
445
|
-
android:id="@+id/tvdescription"
|
446
|
-
|
447
|
-
android:layout_below="@+id/tvname"
|
448
|
-
|
449
|
-
android:layout_alignLeft="@+id/tvname"
|
450
|
-
|
451
|
-
android:layout_alignStart="@+id/tvname"
|
452
|
-
|
453
|
-
android:layout_alignParentRight="true"
|
454
|
-
|
455
|
-
android:layout_alignParentEnd="true" />
|
456
|
-
|
457
|
-
</RelativeLayout>
|
458
|
-
|
459
|
-
```
|
2
エラー内容の追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,11 +1,19 @@
|
|
1
1
|
###ListViewでの遷移について
|
2
2
|
|
3
|
-
Web上のJson形式のファイルを受け取ってそれをlistviewで表示するアプリを作りました。次に遷移するようにしようとしたところ値は持っていってるはずなのですが、
|
3
|
+
Web上のJson形式のファイルを受け取ってそれをlistviewで表示するアプリを作りました。次に遷移するようにしようとしたところ値は持っていってるはずなのですが、
|
4
|
+
|
5
|
+
クリックすると
|
6
|
+
|
7
|
+
> java.lang.NullPointerException: Attempt to read from null array
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
というエラーで落ちてしまいます。エラー内容は配列がnullだといってるのは分かるのですが対処法が分かりません。
|
12
|
+
|
13
|
+
どのようにすればいいかご教授お願いします。
|
4
14
|
|
5
15
|
Main.ActivityのonitemclickのところとSub.Activityです。
|
6
16
|
|
7
|
-
文字数の都合上sample_list_template.xmlは削除しました。
|
8
|
-
|
9
17
|
|
10
18
|
|
11
19
|
```Java
|
1
Sub\.Activityの受け取り部分を書き換えました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -140,51 +140,27 @@
|
|
140
140
|
|
141
141
|
List<json> sList;
|
142
142
|
|
143
|
-
|
143
|
+
|
144
|
-
|
145
|
-
|
144
|
+
|
146
|
-
|
147
|
-
//MainActivityから受け取る
|
148
|
-
|
149
|
-
Intent intent = getIntent();
|
145
|
+
Intent intent = getIntent();
|
150
|
-
|
151
|
-
/*Long vacation = intent.getLongExtra("ID", 0);
|
152
|
-
|
153
|
-
Integer id = new Integer(vacation.toString());*/
|
154
146
|
|
155
147
|
id = intent.getIntExtra("ID", 0);
|
156
148
|
|
149
|
+
|
150
|
+
|
157
|
-
|
151
|
+
imageView =(ImageView) findViewById(R.id.imgUrl);
|
158
|
-
|
159
|
-
|
152
|
+
|
160
|
-
|
161
|
-
//String selectedname = intent.getStringExtra("Name");
|
162
|
-
|
163
|
-
//String selectedimgUrl = intent.getStringExtra("ImgUrl");
|
164
|
-
|
165
|
-
//String selecteddescription = intent.getStringExtra("Description");
|
166
|
-
|
167
|
-
textView = (TextView)findViewById(R.id.tvname);
|
153
|
+
textView = (TextView) findViewById(R.id.tvname);
|
168
|
-
|
169
|
-
|
154
|
+
|
170
|
-
|
171
|
-
|
155
|
+
|
172
|
-
|
173
|
-
|
156
|
+
|
174
|
-
|
175
|
-
textView2 = (TextView)findViewById(R.id.tvdescription);
|
176
|
-
|
177
|
-
//textView.setText(id);
|
178
|
-
|
179
|
-
textView.setText(Adapter.json[id].getName());
|
157
|
+
textView.setText(Adapter.json[id].getName());
|
180
|
-
|
181
|
-
|
158
|
+
|
182
|
-
|
183
|
-
|
159
|
+
Picasso.with(context).load(Adapter.json[id].getImgUrl()).into(imageView);
|
184
|
-
|
160
|
+
|
185
|
-
}
|
161
|
+
}
|
186
|
-
|
162
|
+
|
187
|
-
public void requestData(String uri) {
|
163
|
+
/*public void requestData(String uri) {
|
188
164
|
|
189
165
|
StringRequest request = new StringRequest(uri,
|
190
166
|
|
@@ -224,7 +200,7 @@
|
|
224
200
|
|
225
201
|
}
|
226
202
|
|
227
|
-
}
|
203
|
+
}*/
|
228
204
|
|
229
205
|
```
|
230
206
|
|