我使用asyncTask通過套接字將圖像從Android發送到PC。Android:AsyncTask byte []問題
我打電話像這樣
new SendImage().execute(data);
,其中數據類型byte[]
和我的代碼是
private class SendImage extends AsyncTask<byte[],Void, Void> {
@Override
protected Void doInBackground(byte[] ... data) {
try{
final DataOutputStream dataOutputStream;
final BufferedOutputStream out = new BufferedOutputStream(RRAWsecurity.socket.getOutputStream());
int count = data.length;
dataOutputStream = new DataOutputStream(RRAWsecurity.socket.getOutputStream());
dataOutputStream.writeInt(count);
dataOutputStream.flush();
out.write(data, 0, count);
out.flush();
}catch(Exception e)
{
e.printStackTrace();
}
return null;
}
}
問題是這一行
out.write(data, 0, count);
錯誤說
The method write(byte[], int, int) in the type BufferedOutputStream is not applicable for the arguments (byte[][], int, int)
我想不通爲什麼它要求2D
陣列?
+1或以下是不同'doInBackground()s'的示例http://www.mcs.csueastbay.edu/~grewe/Book/Android/Source%20Code/Sockets/src/net/learn2develop/Sockets/ SocketsActivity.java – 2013-04-28 19:51:25