0
嗨我的問題在我的android應用程序。我編寫了使用tcp和udp的客戶端。數據由AES加密。但是當我嘗試接收數據報時,我的應用程序返回異常。 這是我的代碼:Android異常損壞的墊塊
protected Void doInBackground(Void... params)
{
try
{
udp = new DatagramSocket(2500);
boolean flagaBYE = true;
String w = "";
while(flagaBYE)
{
byte[] receiveData= new byte[1024];
DatagramPacket pakiet = new DatagramPacket(receiveData, receiveData.length);
udp.receive(pakiet);
String wiadomosc = new String(pakiet.getData(),"utf-8");
publishProgress(wiadomosc);
String szyfr = main.preferences.getString("SZYFR_TCP", "");
if(!szyfr.equals("1"))
{
Encryptor enc = new Encryptor(getKeyBytes(key), getCode());
wiadomosc = enc.decrypt(wiadomosc);
}
我的例外是墊塊損壞 我生成這樣的關鍵:
String key = "tojestkluczwlasnie";
而旁邊解析字符串爲byte []
public static byte[] getKeyBytes(String key) throws UnsupportedEncodingException{
byte[] keyBytes= new byte[16];
byte[] parameterKeyBytes= key.getBytes("UTF-8");
System.arraycopy(parameterKeyBytes, 0, keyBytes, 0, Math.min(parameterKeyBytes.length, keyBytes.length));
return keyBytes;
}
show stacktrace –
怎麼樣?我使用NetBeans和模擬器和ex.message是損壞墊塊 –
請參閱:http://stackoverflow.com/questions/2581837/android-debugging-with-logcat-and-emulator-is-it-possible/4763346#4763346或只需手動啓動ddms –