質問編集履歴
1
重複しているが削除リクエストを送れないため
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
削除
|
test
CHANGED
@@ -1,269 +1 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
android studioを使用してandroid内蔵のカメラで撮影した写真をサーバーのディレクトリに送ろうとした時に以下のエラーメッセージが発生しました。(アプリは起動するのですが画像を送る場面で「問題が発生したため、QRCameraを終了します」と表示されます。)
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
###発生している問題・エラーメッセージ
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
02-08 18:29:06.265 2197-2203/? E/jdwp: Failed sending reply to debugger: Broken pipe
|
12
|
-
|
13
|
-
02-08 18:29:29.398 2197-2197/com.example.qrcamera E/libEGL: call to OpenGL ES API with no current context (logged once per thread)
|
14
|
-
|
15
|
-
02-08 18:29:37.429 2197-2197/com.example.qrcamera E/AndroidRuntime: FATAL EXCEPTION: main
|
16
|
-
|
17
|
-
java.lang.RuntimeException: Unable to resume activity {com.example.qrcamera/com.example.qrcamera.CameraActivity}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2, result=-1, data=null} to activity {com.example.qrcamera/com.example.qrcamera.CameraActivity}: java.lang.NullPointerException
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
略
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2, result=-1, data=null} to activity {com.example.qrcamera/com.example.qrcamera.CameraActivity}: java.lang.NullPointerException
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
略
|
30
|
-
|
31
|
-
at com.example.qrcamera.CameraActivity.onActivityResult(CameraActivity.java:125)
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
略
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
###該当のソースコード
|
42
|
-
|
43
|
-
CameraActivity.java
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
import android.app.Activity;
|
48
|
-
|
49
|
-
import android.content.ContentResolver;
|
50
|
-
|
51
|
-
import android.content.ContentValues;
|
52
|
-
|
53
|
-
import android.content.Context;
|
54
|
-
|
55
|
-
import android.content.Intent;
|
56
|
-
|
57
|
-
import android.database.Cursor;
|
58
|
-
|
59
|
-
import android.graphics.Bitmap;
|
60
|
-
|
61
|
-
import android.net.Uri;
|
62
|
-
|
63
|
-
import android.os.Bundle;
|
64
|
-
|
65
|
-
import android.provider.MediaStore;
|
66
|
-
|
67
|
-
import android.view.View;
|
68
|
-
|
69
|
-
import android.widget.Button;
|
70
|
-
|
71
|
-
import android.widget.ImageView;
|
72
|
-
|
73
|
-
import android.widget.TextView;
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
import java.io.File;
|
78
|
-
|
79
|
-
import java.io.IOException;
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
import okhttp3.MediaType;
|
84
|
-
|
85
|
-
import okhttp3.MultipartBody;
|
86
|
-
|
87
|
-
import okhttp3.OkHttpClient;
|
88
|
-
|
89
|
-
import okhttp3.Request;
|
90
|
-
|
91
|
-
import okhttp3.RequestBody;
|
92
|
-
|
93
|
-
import okhttp3.Response;
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
public class CameraActivity extends Activity {
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
static final int REQUEST_CAPTURE_IMAGE = 100;
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
Button TakeButton, BackButton, StorageButton;
|
110
|
-
|
111
|
-
ImageView imageView1;
|
112
|
-
|
113
|
-
TextView stuText;
|
114
|
-
|
115
|
-
private Bitmap capturedImage;
|
116
|
-
|
117
|
-
private Uri mImageUri;
|
118
|
-
|
119
|
-
//ByteArrayOutputStream jpg;
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
@Override
|
124
|
-
|
125
|
-
public void onCreate(Bundle savedInstanceState) {
|
126
|
-
|
127
|
-
super.onCreate(savedInstanceState);
|
128
|
-
|
129
|
-
setContentView(R.layout.activity_camera);
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
TakeButton = (Button) findViewById(R.id.take_button);
|
134
|
-
|
135
|
-
TakeButton.setOnClickListener(new View.OnClickListener() {
|
136
|
-
|
137
|
-
public void onClick(View view) {
|
138
|
-
|
139
|
-
String filename = System.currentTimeMillis() + ".jpg";
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
ContentValues values = new ContentValues();
|
144
|
-
|
145
|
-
values.put(MediaStore.Images.Media.TITLE, filename);
|
146
|
-
|
147
|
-
values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
|
148
|
-
|
149
|
-
mImageUri = getContentResolver().insert(
|
150
|
-
|
151
|
-
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
Intent intent = new Intent();
|
156
|
-
|
157
|
-
intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
|
158
|
-
|
159
|
-
intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri);
|
160
|
-
|
161
|
-
startActivityForResult(intent, 2);
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
}
|
166
|
-
|
167
|
-
});
|
168
|
-
|
169
|
-
}
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
@Override
|
174
|
-
|
175
|
-
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
176
|
-
|
177
|
-
if (requestCode == 2) {
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
// http://barubora3.net/?p=17
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
//UriからFileへ変換
|
186
|
-
|
187
|
-
String path = mImageUri.getPath();
|
188
|
-
|
189
|
-
File file = new File(path);
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
//ポスト先のURL
|
194
|
-
|
195
|
-
String url = ここはURLを記入しています;
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
//ここでPOSTする内容を設定 "image/jpg"の部分は送りたいファイルの形式に合わせて変更する
|
202
|
-
|
203
|
-
RequestBody requestBody = new MultipartBody.Builder()
|
204
|
-
|
205
|
-
.setType(MultipartBody.FORM)
|
206
|
-
|
207
|
-
.addFormDataPart("file", file.getName(), RequestBody.create(MediaType.parse("image/jpg"), file))
|
208
|
-
|
209
|
-
.build();
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
OkHttpClient client = new OkHttpClient();
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
Request request = new Request.Builder()
|
218
|
-
|
219
|
-
.url(url)
|
220
|
-
|
221
|
-
.post(requestBody)
|
222
|
-
|
223
|
-
.build();
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
String result = "";
|
228
|
-
|
229
|
-
try {
|
230
|
-
|
231
|
-
Response response = client.newCall(request).execute();
|
232
|
-
|
233
|
-
if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
|
234
|
-
|
235
|
-
{
|
236
|
-
|
237
|
-
result = response.body().string();
|
238
|
-
|
239
|
-
}
|
240
|
-
|
241
|
-
} catch (Exception e) {
|
242
|
-
|
243
|
-
}
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
//return result:
|
248
|
-
|
249
|
-
}
|
250
|
-
|
251
|
-
}
|
252
|
-
|
253
|
-
}
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
###試したこと
|
262
|
-
|
263
|
-
「http://barubora3.net/?p=17」を参考に作成したのですが、どのように直したらいいのかわかりません。「protected String doInBackground(String... ImagePath)」がいるのかと思ったのですが「(String... ImagePath)」でどう書けばいいのかわからなくなりました。どうかよろしくお願いします
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
###補足情報(言語/FW/ツール等のバージョンなど)
|
268
|
-
|
269
|
-
この部分で使用したjarファイル:okhttp-3.6.0.jar
|
1
|
+
重複した質問をしているので削除できるまで内容を消しておきます
|