これはギャラリーから画像を取得するためのコードです。これは、nullポインタの例外とクラッシュを与えています。私はデバイス自体のコードをテストしていて、ギャラリーでイメージを選択するとクラッシュします。私が間違っているアイデアは?ギャラリーから画像を読み込む際にヌルポインタ例外が発生しました。
AlertDialog.Builder builder = new AlertDialog.Builder(CreatePod.this);
builder.setMessage("Select") .setCancelable(false).setPositiveButton("Gallery", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent gallIntent=new Intent(Intent.ACTION_GET_CONTENT);
gallIntent.setType("image/*");
startActivityForResult(gallIntent, 10);
}
})
protected void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case 10:
if (resultCode == Activity.RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap b = (Bitmap) extras.get("data");
imgView.setImageBitmap(b);
String timestamp = Long.toString(System.currentTimeMillis());
MediaStore.Images.Media.insertImage(getContentResolver(), b, timestamp, timestamp);
HttpResponse httpResponse;
ByteArrayOutputStream bao = new ByteArrayOutputStream();
b.compress(Bitmap.CompressFormat.JPEG, 100, bao);
byte [] ba = bao.toByteArray();
int f = 0;
String ba1=Base64.encodeToString(ba, f);
1.例外のスタックトレースを貼り付けます。デバッグモードでアプリを起動します。 stacktraceを見てください。 – Ivan
しました。 Bundle extras = data.getExtras();を取得します。エキストラをヌルとして。 – Hick