android 程序 挂起,android – 程序挂起在ObjectInputStream的readObject方法上.

我希望在我的代码挂起在objectinputstream readObject()函数之后,在建立连接时共享包含Stuff类型的对象(String name,address,title,…和byte [] picture).没有流媒体发生.任何人都可以弄清楚我做错了什么.

private class ConnectedThread extends Thread {

private final BluetoothSocket mmSocket;

private final InputStream mmInStream;

private final OutputStream mmOutStream;

private ObjectOutputStream oos = null;

private ObjectInputStream ois = null;

public ConnectedThread(BluetoothSocket socket) {

Log.d(TAG,"create ConnectedThread");

mmSocket = socket;

Log.d(TAG,"create a");

InputStream tmpIn = null;

Log.d(TAG,"create b");

OutputStream tmpOut = null;

// Get the BluetoothSocket input and output streams

try {

Log.d("connected thread constructor before inputstream","");

tmpIn = socket.getInputStream();

Log.d("connected thread constructor inputstream",tmpIn.toString());

tmpOut = socket.getOutputStream();

Log.d("connected thread constructor outputstream",tmpOut.toString());

} catch (IOException e) {

Log.e(TAG,"temp sockets not created",e);

}

mmInStream = tmpIn;

mmOutStream = tmpOut;

final BufferedOutputStream bufo = new BufferedOutputStream(

mmOutStream);

final BufferedInputStream bufi = new BufferedInputStream(mmInStream);

Log.d(TAG,"attempting to create OOS");

// ********* ObjectOutputStream **********

try {

oos = new ObjectOutputStream(bufo);

} catch (StreamCorruptedException e) {

Log.d(TAG,"Caught Corrupted Stream Exception");

Log.w(TAG,e);

} catch (IOException e) {

Log.d(TAG,"Caught IOException");

Log.w(TAG,e);

}

// ********* ObjectInputStream **********

Thread s = new Thread() {

public void run() {

Log.d(TAG,"attempting to create OIS");

try {

ois = new ObjectInputStream(bufi);

} catch (StreamCorruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

Log.d(TAG,"completed OIS");

if (ois == null) {

Log.d(TAG,"OIS is null");

}

}

};

s.start();

}

public void run() {

Log.i(TAG,"BEGIN mConnectedThread");

我的代码挂在这一点上,永远不会前进.

`// Keep listening to the InputStream while connected

while (true) {

try {

Log.d("Connected thread run ","start while");

try {

Stuff obj_rcv = (Stuff) ois.readObject();

Log.d("BTS","rcv object " + obj_rcv.getName());

Message msg2 = mHandler

.obtainMessage(RemoteBusinessCard.MESSAGE_READ);

Bundle bundle = new Bundle();

bundle.putSerializable("person",obj_rcv);

msg2.setData(bundle);

mHandler.sendMessage(msg2);

} catch (ClassNotFoundException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

} catch (IOException e) {

Log.e(TAG,"disconnected",e);

connectionLost();

break;

}

}

}

/**

* Write to the connected OutStream.

*

* @param buffer

* The bytes to write

*/

public void write(Stuff object) {

try {

Log.d("BTS","inside write before" + object.getName());

oos.writeObject(object);

Log.d("BTS","inside write after" + object.getName());

oos.flush();

oos.close();

} catch (IOException e) {

Log.e(TAG,"Exception during write",e);

}

}

public void cancel() {

try {

mmSocket.close();

} catch (IOException e) {

Log.e(TAG,"close() of connect socket Failed",e);

}

}

}`

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值