teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

10

___

2017/02/10 19:53

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -1,7 +1,3 @@
1
- ###ListViewでの遷移について
2
- Web上のJson形式のファイルを受け取ってそれをlistviewで表示するアプリを作りました。次に遷移するようにしようとしたところ値は持っていってるはずなのですが、
3
- クリックすると
4
-
5
1
  > D/AndroidRuntime: Shutting down VM
6
2
  E/AndroidRuntime: FATAL EXCEPTION: main
7
3
  Process: com.list, PID: 2942
@@ -25,155 +21,4 @@
25
21
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) 
26
22
  at android.app.ActivityThread.-wrap12(ActivityThread.java) 
27
23
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) 
28
- at android.os.Handler.dispatchMessage(Handler.java:102) 
29
- at android.os.Looper.loop(Looper.java:154) 
30
- at android.app.ActivityThread.main(ActivityThread.java:6077) 
31
- at java.lang.reflect.Method.invoke(Native Method) 
32
- at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) 
33
- at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
34
-
35
-
36
-
37
- というエラーで落ちてしまいます。
38
- 対処法が分かりません。
39
- どのようにすればいいかご教授お願いします。
40
- Main.ActivityのonitemclickのところとSub.Activityです。
41
-
42
- ```Java
43
- package com.list;
44
-
45
- import android.content.Intent;
46
- import android.os.Bundle;
47
- import android.support.v7.app.AppCompatActivity;
48
- import android.view.View;
49
- import android.widget.AdapterView;
50
- import android.widget.ListView;
51
- import android.widget.Toast;
52
-
53
- import com.android.volley.RequestQueue;
54
- import com.android.volley.Response;
55
- import com.android.volley.VolleyError;
56
- import com.android.volley.toolbox.StringRequest;
57
- import com.android.volley.toolbox.Volley;
58
-
59
- import java.util.List;
60
-
61
- /**
62
- * Created by yu on 2017/02/05.
63
- */
64
-
65
- public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
66
- List<json> sweetsList;
67
- ListView lv;
68
- String uri = "URL";
69
-
70
- @Override
71
- protected void onCreate(Bundle savedInstanceState) {
72
- super.onCreate(savedInstanceState);
73
- setContentView(R.layout.activity_main);
74
-
75
- lv = (ListView) findViewById(R.id.listView);
76
- requestData(uri);
77
-
78
- //lv.setAdapter();
79
- lv.setOnItemClickListener(this);
80
- }
81
-
82
- //画面遷移
83
- //ListView lv = (ListView) findViewById(R.id.listView);
84
-
85
- //listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
86
- @Override
87
- public void onItemClick(AdapterView<?> parent, View view, int position, long id)
88
- {
89
-
90
-
91
-
92
- Intent intent = new Intent(getApplication(), SubActivity.class);
93
-
94
- intent.putExtra("ID", id);
95
-
96
- // Activity をスイッチする
97
- startActivity(intent);
98
- //long get_id = id;
99
- }
100
- //});
101
-
102
- public void requestData(String uri) {
103
-
104
- StringRequest request = new StringRequest(uri,
105
-
106
- new Response.Listener<String>(){
107
- @Override
108
- public void onResponse(String response) {
109
- sweetsList = jsonParser.parseData(response);
110
- Adapter adapter = new Adapter(MainActivity.this, sweetsList);
111
- lv.setAdapter(adapter);
112
-
113
- }
114
- },
24
+ at
115
- //エラー関係
116
- new Response.ErrorListener() {
117
- @Override
118
- public void onErrorResponse(VolleyError error) {
119
-
120
- Toast.makeText(MainActivity.this, error.getMessage().toString(), Toast.LENGTH_SHORT).show();
121
- }
122
- });
123
-
124
- RequestQueue queue = Volley.newRequestQueue(this);
125
- queue.add(request);
126
- }
127
-
128
- }
129
- ```
130
- ```Java
131
- package com.list;
132
-
133
- import android.content.Context;
134
- import android.content.Intent;
135
- import android.os.Bundle;
136
- import android.support.v7.app.AppCompatActivity;
137
- import android.widget.ImageView;
138
- import android.widget.ListView;
139
- import android.widget.TextView;
140
-
141
- import com.squareup.picasso.Picasso;
142
-
143
- import java.util.List;
144
-
145
- public class SubActivity extends AppCompatActivity {
146
-
147
- private Context context;
148
- List<json> sList;
149
- ListView lv;
150
-
151
- ImageView imageView;
152
- TextView textView, textView2;
153
-
154
- protected int id;
155
- protected String name;
156
- protected String imgUrl;
157
- protected String description;
158
-
159
- @Override
160
- protected void onCreate(Bundle savedInstanceState) {
161
-
162
- super.onCreate(savedInstanceState);
163
- setContentView(R.layout.activity_sub);
164
-
165
- //MainActivityから受け取る
166
- Intent intent = getIntent();
167
-
168
- Long num = intent.getLongExtra("ID", 0);
169
- Integer id = new Integer(num.toString());
170
-
171
- imageView =(ImageView) findViewById(R.id.imgUrl);
172
- textView = (TextView) findViewById(R.id.tvname);
173
-
174
- textView.setText(Adapter.json[id].getName());
175
- Picasso.with(context).load(Adapter.json[id].getImgUrl()).into(imageView);
176
- }
177
-
178
- }
179
- ```

9

引用文化していなかったので再編集

2017/02/10 19:53

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -1,7 +1,8 @@
1
1
  ###ListViewでの遷移について
2
2
  Web上のJson形式のファイルを受け取ってそれをlistviewで表示するアプリを作りました。次に遷移するようにしようとしたところ値は持っていってるはずなのですが、
3
3
  クリックすると
4
+
4
- >D/AndroidRuntime: Shutting down VM
5
+ > D/AndroidRuntime: Shutting down VM
5
6
  E/AndroidRuntime: FATAL EXCEPTION: main
6
7
  Process: com.list, PID: 2942
7
8
  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.list/

8

sub\.activityの追加Adapterの削除

2017/02/06 10:46

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -127,63 +127,52 @@
127
127
  }
128
128
  ```
129
129
  ```Java
130
+ package com.list;
131
+
132
+ import android.content.Context;
133
+ import android.content.Intent;
134
+ import android.os.Bundle;
135
+ import android.support.v7.app.AppCompatActivity;
136
+ import android.widget.ImageView;
137
+ import android.widget.ListView;
138
+ import android.widget.TextView;
139
+
140
+ import com.squareup.picasso.Picasso;
141
+
142
+ import java.util.List;
143
+
130
- public class Adapter extends ArrayAdapter<json> {
144
+ public class SubActivity extends AppCompatActivity {
131
- public static json[] json;
145
+
132
146
  private Context context;
133
- private List<json> sList;
147
+ List<json> sList;
134
- private LayoutInflater inflater = null;
135
- //public static final String IMAGE_BASEURL = "";
136
- private LruCache<Integer,Bitmap> imageCache;
137
- private RequestQueue queue;
138
- public Adapter(Context context, List<json> list) {
139
- super(context, 0);
140
- this.context = context;
141
- this.sList = list;
148
+ ListView lv;
142
- inflater = LayoutInflater.from(context);
143
- final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
144
- final int cacheSize = maxMemory / 8;
145
- imageCache = new LruCache<>(cacheSize);
146
149
 
147
- queue = Volley.newRequestQueue(context);
148
- }
149
- public class ViewHolder {
150
- TextView _name;
151
- TextView _description;
152
- //TextView _plateform;
153
- ImageView _imgUrl;
150
+ ImageView imageView;
151
+ TextView textView, textView2;
152
+
154
- }
153
+ protected int id;
154
+ protected String name;
155
+ protected String imgUrl;
156
+ protected String description;
157
+
155
158
  @Override
159
+ protected void onCreate(Bundle savedInstanceState) {
160
+
161
+ super.onCreate(savedInstanceState);
162
+ setContentView(R.layout.activity_sub);
163
+
164
+ //MainActivityから受け取る
156
- public int getCount() {
165
+ Intent intent = getIntent();
166
+
167
+ Long num = intent.getLongExtra("ID", 0);
168
+ Integer id = new Integer(num.toString());
169
+
170
+ imageView =(ImageView) findViewById(R.id.imgUrl);
171
+ textView = (TextView) findViewById(R.id.tvname);
172
+
157
- return sList.size();
173
+ textView.setText(Adapter.json[id].getName());
174
+ Picasso.with(context).load(Adapter.json[id].getImgUrl()).into(imageView);
158
175
  }
159
- @Nullable
176
+
160
- @Override
161
- public json getItem(int position) {
162
- return sList.get(position);
163
- }
177
+ }
164
- @Override
165
- public long getItemId(int position) {
166
- return position;
167
- }
168
- @Override
169
- public View getView(int position, View convertView, ViewGroup viewGroup) {
170
- final json s = sList.get(position);
171
- final com.list.Adapter.ViewHolder holder;
172
- if(convertView == null) {
173
- convertView = inflater.inflate(R.layout.list_item_templates,null);
174
- //convertView = inflater.inflate(R.layout.list_item_detail,null);
175
- holder = new com.list.Adapter.ViewHolder();
176
- holder._name = (TextView) convertView.findViewById(R.id.tvname);
177
- holder._description = (TextView) convertView.findViewById(R.id.tvdescription);
178
- //holder._plateform = (TextView) convertView.findViewById(R.id.tvplateform);
179
- convertView.setTag(holder);
180
- }
181
- else {
182
- holder = (com.list.Adapter.ViewHolder) convertView.getTag();
183
- }
184
- holder._name.setText(s.getName().toString());
185
- holder._description.setText(s.getDescription().toString());
186
- //holder._plateform.setText(s.getPlatforms().toString());
187
- Bitmap bitmap = imageCache.get(Integer.parseInt(s.getId()));
188
- holder._imgUrl = (ImageView) convertView.findViewById(R.id.imgUrl);
189
178
  ```

7

Java内の編集

2017/02/06 10:42

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -1,10 +1,10 @@
1
1
  ###ListViewでの遷移について
2
2
  Web上のJson形式のファイルを受け取ってそれをlistviewで表示するアプリを作りました。次に遷移するようにしようとしたところ値は持っていってるはずなのですが、
3
3
  クリックすると
4
- >--------- beginning of crash
4
+ >D/AndroidRuntime: Shutting down VM
5
5
  E/AndroidRuntime: FATAL EXCEPTION: main
6
- Process: com.list, PID: 2415
6
+ Process: com.list, PID: 2942
7
- java.lang.RuntimeException: Unable to start activity ComponentInfo{com.list
7
+ java.lang.RuntimeException: Unable to start activity ComponentInfo{com.list/
8
8
  com.list.SubActivity}: java.lang.NullPointerException: Attempt to read from null array
9
9
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
10
10
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
@@ -17,7 +17,7 @@
17
17
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
18
18
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
19
19
  Caused by: java.lang.NullPointerException: Attempt to read from null array
20
- at com.list.SubActivity.onCreate(SubActivity.java:86)
20
+ at com.list.SubActivity.onCreate(SubActivity.java:54)
21
21
  at android.app.Activity.performCreate(Activity.java:6664)
22
22
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
23
23
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
@@ -30,93 +30,103 @@
30
30
  at java.lang.reflect.Method.invoke(Native Method) 
31
31
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) 
32
32
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
33
- Application terminated.
34
33
 
35
34
 
35
+
36
36
  というエラーで落ちてしまいます。
37
37
  対処法が分かりません。
38
38
  どのようにすればいいかご教授お願いします。
39
39
  Main.ActivityのonitemclickのところとSub.Activityです。
40
40
 
41
41
  ```Java
42
+ package com.list;
43
+
44
+ import android.content.Intent;
45
+ import android.os.Bundle;
46
+ import android.support.v7.app.AppCompatActivity;
47
+ import android.view.View;
48
+ import android.widget.AdapterView;
49
+ import android.widget.ListView;
50
+ import android.widget.Toast;
51
+
52
+ import com.android.volley.RequestQueue;
53
+ import com.android.volley.Response;
54
+ import com.android.volley.VolleyError;
55
+ import com.android.volley.toolbox.StringRequest;
56
+ import com.android.volley.toolbox.Volley;
57
+
58
+ import java.util.List;
59
+
60
+ /**
61
+ * Created by yu on 2017/02/05.
62
+ */
63
+
42
64
  public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
43
- List<json> sList;
65
+ List<json> sweetsList;
44
66
  ListView lv;
45
67
  String uri = "URL";
68
+
46
69
  @Override
47
70
  protected void onCreate(Bundle savedInstanceState) {
48
71
  super.onCreate(savedInstanceState);
49
72
  setContentView(R.layout.activity_main);
73
+
50
74
  lv = (ListView) findViewById(R.id.listView);
51
75
  requestData(uri);
76
+
77
+ //lv.setAdapter();
52
78
  lv.setOnItemClickListener(this);
53
79
  }
80
+
54
81
  //画面遷移
82
+ //ListView lv = (ListView) findViewById(R.id.listView);
83
+
84
+ //listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
55
85
  @Override
56
86
  public void onItemClick(AdapterView<?> parent, View view, int position, long id)
57
87
  {
88
+
89
+
90
+
58
91
  Intent intent = new Intent(getApplication(), SubActivity.class);
92
+
59
93
  intent.putExtra("ID", id);
60
- // clickされたpositionのnameとimageUrlとdescriptionのID
94
+
61
- /*ListView listView = (ListView) parent;
62
-
63
- String item = (String) listView.getItemAtPosition(position);*/
64
- //intent.putExtra("ID", adapter.getItem(position));
65
95
  // Activity をスイッチする
66
96
  startActivity(intent);
67
97
  //long get_id = id;
68
98
  }
99
+ //});
100
+
69
101
  public void requestData(String uri) {
102
+
70
103
  StringRequest request = new StringRequest(uri,
104
+
71
105
  new Response.Listener<String>(){
72
106
  @Override
73
107
  public void onResponse(String response) {
74
- sList = jsonParser.parseData(response);
108
+ sweetsList = jsonParser.parseData(response);
75
- Adapter adapter = new Adapter(MainActivity.this, sList);
109
+ Adapter adapter = new Adapter(MainActivity.this, sweetsList);
76
110
  lv.setAdapter(adapter);
111
+
77
112
  }
78
113
  },
79
114
  //エラー関係
80
115
  new Response.ErrorListener() {
81
116
  @Override
82
117
  public void onErrorResponse(VolleyError error) {
118
+
83
119
  Toast.makeText(MainActivity.this, error.getMessage().toString(), Toast.LENGTH_SHORT).show();
84
120
  }
85
121
  });
122
+
86
123
  RequestQueue queue = Volley.newRequestQueue(this);
87
124
  queue.add(request);
88
125
  }
126
+
89
127
  }
90
-
91
128
  ```
92
129
  ```Java
93
- public class SubActivity extends AppCompatActivity {
94
- List<json> sList;
95
- ListView lv;
96
- String uri = "URL";
97
- ImageView imageView;
98
- TextView textView, textView2;
99
- protected int id;
100
- /*protected String imgUrl;
101
- protected String description;*/
102
- @Override
103
- protected void onCreate(Bundle savedInstanceState) {
104
- super.onCreate(savedInstanceState);
105
- setContentView(R.layout.activity_sub);
106
- List<json> sList;
107
-
108
- Intent intent = getIntent();
109
- Long num = intent.getLongExtra("ID", 0);
110
- Integer id = new Integer(num.toString());
111
-
112
- imageView =(ImageView) findViewById(R.id.imgUrl);
113
- textView = (TextView) findViewById(R.id.tvname);
114
-
115
- textView.setText(Adapter.json[id].getName());
116
- Picasso.with(context).load(Adapter.json[id].getImgUrl()).into(imageView);
117
- }
118
- ```
119
- ```Java
120
130
  public class Adapter extends ArrayAdapter<json> {
121
131
  public static json[] json;
122
132
  private Context context;

6

エラー内容の追記

2017/02/06 10:37

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -1,55 +1,38 @@
1
1
  ###ListViewでの遷移について
2
2
  Web上のJson形式のファイルを受け取ってそれをlistviewで表示するアプリを作りました。次に遷移するようにしようとしたところ値は持っていってるはずなのですが、
3
3
  クリックすると
4
+ >--------- beginning of crash
4
- > W/Bundle: Key ID expected Integer but value was a java.lang.Long.
5
+ E/AndroidRuntime: FATAL EXCEPTION: main
5
- The default value 1 was returned. W/Bundle: Attempt to cast generated internal exception:
6
+ Process: com.list, PID: 2415
6
- java.lang.ClassCastException: java.lang.Long cannot be cast to
7
+ java.lang.RuntimeException: Unable to start activity ComponentInfo{com.list
8
+ com.list.SubActivity}: java.lang.NullPointerException: Attempt to read from null array
9
+ at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
10
+ at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
7
- java.lang.Integer
11
+ at android.app.ActivityThread.-wrap12(ActivityThread.java)
12
+ at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
8
- at android.os.BaseBundle.getInt(BaseBundle.java:873)
13
+ at android.os.Handler.dispatchMessage(Handler.java:102)
14
+ at android.os.Looper.loop(Looper.java:154)
15
+ at android.app.ActivityThread.main(ActivityThread.java:6077)
16
+ at java.lang.reflect.Method.invoke(Native Method)
17
+ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
9
- at android.content.Intent.getIntExtra(Intent.java:6146)
18
+ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
19
+ Caused by: java.lang.NullPointerException: Attempt to read from null array
10
- at com.list.SubActivity.onCreate(SubActivity.java:63)
20
+ at com.list.SubActivity.onCreate(SubActivity.java:86)
11
- at android.app.Activity.performCreate(Activity.java:6664)
21
+ at android.app.Activity.performCreate(Activity.java:6664)
12
- at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
22
+ at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
13
- at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
23
+ at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
14
- at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
24
+ at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) 
15
- at android.app.ActivityThread.-wrap12(ActivityThread.java)
25
+ at android.app.ActivityThread.-wrap12(ActivityThread.java) 
16
- at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
26
+ at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) 
17
- at android.os.Handler.dispatchMessage(Handler.java:102)
27
+ at android.os.Handler.dispatchMessage(Handler.java:102) 
18
- at android.os.Looper.loop(Looper.java:154)
28
+ at android.os.Looper.loop(Looper.java:154) 
19
- at android.app.ActivityThread.main(ActivityThread.java:6077)
29
+ at android.app.ActivityThread.main(ActivityThread.java:6077) 
20
- at java.lang.reflect.Method.invoke(Native Method)
30
+ at java.lang.reflect.Method.invoke(Native Method) 
21
- at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
31
+ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) 
22
- at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) D/AndroidRuntime: Shutting down VM E/AndroidRuntime: FATAL EXCEPTION: main
23
- Process: com.list, PID: 2414
24
- java.lang.RuntimeException: Unable to start activity
25
- ComponentInfo{com.list/com.list.SubActivity}:
26
- java.lang.NullPointerException: Attempt to read from null array
27
- at android.app.ActivityThread.performLaunchActivity(ActivityThread.
28
- java:2646)
29
- at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
30
- at android.app.ActivityThread.-wrap12(ActivityThread.java)
31
- at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
32
- at android.os.Handler.dispatchMessage(Handler.java:102)
33
- at android.os.Looper.loop(Looper.java:154)
34
- at android.app.ActivityThread.main(ActivityThread.java:6077)
35
- at java.lang.reflect.Method.invoke(Native Method)
36
- at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
37
- at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
32
+ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
38
- Caused by: java.lang.NullPointerException: Attempt to read from null array
39
- at com.list.SubActivity.onCreate(SubActivity.java:86)
40
- at android.app.Activity.performCreate(Activity.java:6664)
41
- at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
42
- at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
43
- at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) 
44
- at android.app.ActivityThread.-wrap12(ActivityThread.java) 
45
- at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) 
46
- at android.os.Handler.dispatchMessage(Handler.java:102) 
47
- at android.os.Looper.loop(Looper.java:154) 
48
- at android.app.ActivityThread.main(ActivityThread.java:6077) 
49
- at java.lang.reflect.Method.invoke(Native Method) 
33
+ Application terminated.
50
- at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) 
51
- at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
52
34
 
35
+
53
36
  というエラーで落ちてしまいます。
54
37
  対処法が分かりません。
55
38
  どのようにすればいいかご教授お願いします。

5

sub\.Activity内のコードを一部変更&エラー内容の追記

2017/02/06 10:09

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -50,7 +50,8 @@
50
50
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) 
51
51
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
52
52
 
53
- というエラーで落ちてしまいます。エラー内容は配列がnullだといってるのは分かるのですが対処法が分かりません。
53
+ というエラーで落ちてしまいます。
54
+ 対処法が分かりません。
54
55
  どのようにすればいいかご教授お願いします。
55
56
  Main.ActivityのonitemclickのところとSub.Activityです。
56
57
 
@@ -122,7 +123,8 @@
122
123
  List<json> sList;
123
124
 
124
125
  Intent intent = getIntent();
125
- id = intent.getIntExtra("ID", 0);
126
+ Long num = intent.getLongExtra("ID", 0);
127
+ Integer id = new Integer(num.toString());
126
128
 
127
129
  imageView =(ImageView) findViewById(R.id.imgUrl);
128
130
  textView = (TextView) findViewById(R.id.tvname);

4

xmlを削除

2017/02/06 09:46

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
File without changes

3

エラー内容の追記

2017/02/06 08:00

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -1,7 +1,54 @@
1
1
  ###ListViewでの遷移について
2
2
  Web上のJson形式のファイルを受け取ってそれをlistviewで表示するアプリを作りました。次に遷移するようにしようとしたところ値は持っていってるはずなのですが、
3
3
  クリックすると
4
+ > W/Bundle: Key ID expected Integer but value was a java.lang.Long.
5
+ The default value 1 was returned. W/Bundle: Attempt to cast generated internal exception:
6
+ java.lang.ClassCastException: java.lang.Long cannot be cast to
7
+ java.lang.Integer
8
+ at android.os.BaseBundle.getInt(BaseBundle.java:873)
9
+ at android.content.Intent.getIntExtra(Intent.java:6146)
10
+ at com.list.SubActivity.onCreate(SubActivity.java:63)
11
+ at android.app.Activity.performCreate(Activity.java:6664)
12
+ at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
13
+ at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
14
+ at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
15
+ at android.app.ActivityThread.-wrap12(ActivityThread.java)
16
+ at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
17
+ at android.os.Handler.dispatchMessage(Handler.java:102)
18
+ at android.os.Looper.loop(Looper.java:154)
19
+ at android.app.ActivityThread.main(ActivityThread.java:6077)
20
+ at java.lang.reflect.Method.invoke(Native Method)
21
+ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
22
+ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) D/AndroidRuntime: Shutting down VM E/AndroidRuntime: FATAL EXCEPTION: main
23
+ Process: com.list, PID: 2414
24
+ java.lang.RuntimeException: Unable to start activity
25
+ ComponentInfo{com.list/com.list.SubActivity}:
4
- > java.lang.NullPointerException: Attempt to read from null array
26
+ java.lang.NullPointerException: Attempt to read from null array
27
+ at android.app.ActivityThread.performLaunchActivity(ActivityThread.
28
+ java:2646)
29
+ at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
30
+ at android.app.ActivityThread.-wrap12(ActivityThread.java)
31
+ at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
32
+ at android.os.Handler.dispatchMessage(Handler.java:102)
33
+ at android.os.Looper.loop(Looper.java:154)
34
+ at android.app.ActivityThread.main(ActivityThread.java:6077)
35
+ at java.lang.reflect.Method.invoke(Native Method)
36
+ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
37
+ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
38
+ Caused by: java.lang.NullPointerException: Attempt to read from null array
39
+ at com.list.SubActivity.onCreate(SubActivity.java:86)
40
+ at android.app.Activity.performCreate(Activity.java:6664)
41
+ at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
42
+ at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
43
+ at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) 
44
+ at android.app.ActivityThread.-wrap12(ActivityThread.java) 
45
+ at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) 
46
+ at android.os.Handler.dispatchMessage(Handler.java:102) 
47
+ at android.os.Looper.loop(Looper.java:154) 
48
+ at android.app.ActivityThread.main(ActivityThread.java:6077) 
49
+ at java.lang.reflect.Method.invoke(Native Method) 
50
+ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) 
51
+ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
5
52
 
6
53
  というエラーで落ちてしまいます。エラー内容は配列がnullだといってるのは分かるのですが対処法が分かりません。
7
54
  どのようにすればいいかご教授お願いします。
@@ -83,31 +130,10 @@
83
130
  textView.setText(Adapter.json[id].getName());
84
131
  Picasso.with(context).load(Adapter.json[id].getImgUrl()).into(imageView);
85
132
  }
86
- /*public void requestData(String uri) {
87
- StringRequest request = new StringRequest(uri,
88
- new Response.Listener<String>(){
89
- @Override
90
- public void onResponse(String response) {
91
- sList = jsonParser.parseData(response);
92
- Adapter adapter = new Adapter(SubActivity.this, sList);
93
- lv.setAdapter(adapter);
94
- }
95
- },
96
- //エラー
97
- new Response.ErrorListener() {
98
- @Override
99
- public void onErrorResponse(VolleyError error) {
100
- Toast.makeText(SubActivity.this, error.getMessage().toString(), Toast.LENGTH_SHORT).show();
101
- }
102
- });
103
- RequestQueue queue = Volley.newRequestQueue(this);
104
- queue.add(request);
105
- }
106
- }*/
107
133
  ```
108
134
  ```Java
109
135
  public class Adapter extends ArrayAdapter<json> {
110
- public static json[] json; //追加
136
+ public static json[] json;
111
137
  private Context context;
112
138
  private List<json> sList;
113
139
  private LayoutInflater inflater = null;
@@ -147,84 +173,22 @@
147
173
  @Override
148
174
  public View getView(int position, View convertView, ViewGroup viewGroup) {
149
175
  final json s = sList.get(position);
150
- final jp.ac.dhu.list.Adapter.ViewHolder holder;
176
+ final com.list.Adapter.ViewHolder holder;
151
177
  if(convertView == null) {
152
178
  convertView = inflater.inflate(R.layout.list_item_templates,null);
153
179
  //convertView = inflater.inflate(R.layout.list_item_detail,null);
154
- holder = new jp.ac.dhu.list.Adapter.ViewHolder();
180
+ holder = new com.list.Adapter.ViewHolder();
155
181
  holder._name = (TextView) convertView.findViewById(R.id.tvname);
156
182
  holder._description = (TextView) convertView.findViewById(R.id.tvdescription);
157
183
  //holder._plateform = (TextView) convertView.findViewById(R.id.tvplateform);
158
184
  convertView.setTag(holder);
159
185
  }
160
186
  else {
161
- holder = (jp.ac.dhu.list.Adapter.ViewHolder) convertView.getTag();
187
+ holder = (com.list.Adapter.ViewHolder) convertView.getTag();
162
188
  }
163
189
  holder._name.setText(s.getName().toString());
164
190
  holder._description.setText(s.getDescription().toString());
165
191
  //holder._plateform.setText(s.getPlatforms().toString());
166
192
  Bitmap bitmap = imageCache.get(Integer.parseInt(s.getId()));
167
193
  holder._imgUrl = (ImageView) convertView.findViewById(R.id.imgUrl);
168
- ```
169
- ```xml
170
- activity_main
171
- <?xml version="1.0" encoding="utf-8"?>
172
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
173
- xmlns:tools="http://schemas.android.com/tools"
174
- android:layout_width="match_parent"
175
- android:layout_height="match_parent"
176
- tools:context="jp.ac.dhu.list.MainActivity">
177
- <ListView
178
- android:layout_width="wrap_content"
179
- android:layout_height="wrap_content"
180
- android:id="@+id/listView"
181
- android:layout_alignParentTop="true"
182
- android:layout_alignParentLeft="true"
183
- android:layout_alignParentStart="true" />
184
- </RelativeLayout>
185
- ```
186
- ```xml
187
- activity_sub
188
- <?xml version="1.0" encoding="utf-8"?>
189
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
190
- xmlns:tools="http://schemas.android.com/tools"
191
- android:layout_width="match_parent"
192
- android:layout_height="match_parent"
193
- tools:context="jp.ac.dhu.list.SubActivity">
194
- <ImageView
195
- android:layout_width="70dp"
196
- android:layout_height="70dp"
197
- android:layout_marginLeft="12dp"
198
- android:layout_marginTop="14dp"
199
- android:id="@+id/imgUrl"
200
- android:paddingBottom="10dp"
201
- android:layout_alignParentTop="true"
202
- android:layout_alignParentLeft="true"
203
- android:layout_alignParentStart="true" />
204
- <TextView
205
- android:layout_width="match_parent"
206
- android:layout_height="wrap_content"
207
- android:textSize="18sp"
208
- android:id="@+id/tvname"
209
- android:paddingLeft="4dp"
210
- android:paddingRight="5dp"
211
- android:layout_alignTop="@+id/imgUrl"
212
- android:layout_toRightOf="@+id/imgUrl"
213
- android:layout_toEndOf="@+id/imgUrl" />
214
- <TextView
215
- android:layout_width="wrap_content"
216
- android:layout_height="wrap_content"
217
- android:text="Small Text"
218
- android:lines="1"
219
- android:ellipsize="end"
220
- android:paddingLeft="4dp"
221
- android:paddingRight="5dp"
222
- android:textSize="12sp"
223
- android:id="@+id/tvdescription"
224
- android:layout_below="@+id/tvname"
225
- android:layout_alignLeft="@+id/tvname"
226
- android:layout_alignStart="@+id/tvname"
227
- android:layout_alignParentRight="true"
228
- android:layout_alignParentEnd="true" />
229
- </RelativeLayout>
230
194
  ```

2

エラー内容の追記

2017/02/06 07:54

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -1,7 +1,11 @@
1
1
  ###ListViewでの遷移について
2
- Web上のJson形式のファイルを受け取ってそれをlistviewで表示するアプリを作りました。次に遷移するようにしようとしたところ値は持っていってるはずなのですが、表示などができません。どうすればいいかご教授お願いします。
2
+ Web上のJson形式のファイルを受け取ってそれをlistviewで表示するアプリを作りました。次に遷移するようにしようとしたところ値は持っていってるはずなのですが、
3
+ クリックすると
4
+ > java.lang.NullPointerException: Attempt to read from null array
5
+
6
+ というエラーで落ちてしまいます。エラー内容は配列がnullだといってるのは分かるのですが対処法が分かりません。
7
+ どのようにすればいいかご教授お願いします。
3
8
  Main.ActivityのonitemclickのところとSub.Activityです。
4
- 文字数の都合上sample_list_template.xmlは削除しました。
5
9
 
6
10
  ```Java
7
11
  public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {

1

Sub\.Activityの受け取り部分を書き換えました。

2017/02/05 18:49

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -69,29 +69,17 @@
69
69
  super.onCreate(savedInstanceState);
70
70
  setContentView(R.layout.activity_sub);
71
71
  List<json> sList;
72
- //lv = (ListView) findViewById(R.id.listView);
72
+
73
- //requestData(uri);
74
- //MainActivityから受け取る
75
- Intent intent = getIntent();
73
+ Intent intent = getIntent();
76
- /*Long vacation = intent.getLongExtra("ID", 0);
77
- Integer id = new Integer(vacation.toString());*/
78
74
  id = intent.getIntExtra("ID", 0);
75
+
79
- /*imgUrl = getIntent().getStringExtra("IMGURL");
76
+ imageView =(ImageView) findViewById(R.id.imgUrl);
80
- description = getIntent().getStringExtra("DESCRIPTION");*/
81
- //String selectedname = intent.getStringExtra("Name");
82
- //String selectedimgUrl = intent.getStringExtra("ImgUrl");
83
- //String selecteddescription = intent.getStringExtra("Description");
84
- textView = (TextView)findViewById(R.id.tvname);
77
+ textView = (TextView) findViewById(R.id.tvname);
85
- //textView.setText(tvname);
78
+
86
- imageView = (ImageView)findViewById(R.id.imgUrl);
87
- //imageView.setImageResource();
88
- textView2 = (TextView)findViewById(R.id.tvdescription);
89
- //textView.setText(id);
90
- textView.setText(Adapter.json[id].getName());
79
+ textView.setText(Adapter.json[id].getName());
91
- //imageView.set
92
- textView2.setText(Adapter.json[id].getDescription());
80
+ Picasso.with(context).load(Adapter.json[id].getImgUrl()).into(imageView);
93
81
  }
94
- public void requestData(String uri) {
82
+ /*public void requestData(String uri) {
95
83
  StringRequest request = new StringRequest(uri,
96
84
  new Response.Listener<String>(){
97
85
  @Override
@@ -111,7 +99,7 @@
111
99
  RequestQueue queue = Volley.newRequestQueue(this);
112
100
  queue.add(request);
113
101
  }
114
- }
102
+ }*/
115
103
  ```
116
104
  ```Java
117
105
  public class Adapter extends ArrayAdapter<json> {