我正在創建一個從java服務器向android客戶端發送圖像。 這裏是我的Android代碼:將位圖圖像設置爲ImageView時出錯
protected Void doInBackground(Void... arg0) {
try {
socket = new Socket("192.168.237.1", 6666);
dataOutputStream = new DataOutputStream(socket.getOutputStream());
dataInputStream = new DataInputStream(socket.getInputStream());
// dataOutputStream.writeUTF(textOut.getText().toString());
String base64Code = dataInputStream.readUTF();
Log.d("String", ":" + base64Code);
//
byte[] decodedString;
decodedString = Base64.decode(base64Code);
Log.d("Ds",""+decodedString);
Log.d("St--", ":" + decodedString.length);
BitmapFactory.Options options=new BitmapFactory.Options();
options.inMutable=true;
bitmap = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length,options);
Drawable ob=new BitmapDrawable(getResources(),bitmap);
imageView = (ImageView) findViewById(R.id.imageView1);
imageView.setBackgroundDrawable(ob);
/*//imageView.setImageBitmap(bitmap);
ByteArrayInputStream input=new ByteArrayInputStream(decodedString);
bitmap=BitmapFactory.decodeStream(input);
imageView.setImageBitmap(bitmap);*/
Log.d("Bitmap",""+bitmap);
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
Log.d("Error", "" + e);
}
}
我已經編碼在Java usung阿帕奇共同編解碼器的字節數組,在Android的程序解碼。 我得到的錯誤是NullPointeException
在。 這段代碼中的錯誤是什麼?
哇!這工作。非常感謝。 –