今天折腾了一个下午,遇到这个 java.io.NotSerializableException: java.nio.HeapByteBuffer异常,尽管也知道 java.nio.HeapByteBuffer没有实现java.io.Serializable,但是我如何查找,都没找到我的程序哪里使用 java.nio.HeapByteBuffer。我的jdk是1.8的。麻烦大神们指教指教。谢谢代码如下:package com.client.tcp;import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.UnknownHostException;import com.MAVLink.MAVLinkPacket;
import com.MAVLink.mavlink.common.msg_altitude;
import com.test.Test;public class Client {
public static void main(String[] args) {
new ClientThread().start();
}
}class ClientThread extends Thread {
private   MAVLinkPacket packet = null;
private   boolean flag = true;
private   msg_altitude msgAltt = new msg_altitude();
private Socket socket = null;
@Override
public void run()
{

try {
socket = new Socket();
InetSocketAddress isa = new InetSocketAddress("127.0.0.1",40000);
socket.connect(isa);
ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());

msgAltt.altitude_amsl = 34.5f;
msgAltt.altitude_local = 34.87f;
msgAltt.altitude_monotonic = 76.54f;
msgAltt.altitude_relative = 100.09f;
msgAltt.altitude_terrain = 23.5f;
msgAltt.bottom_clearance = 567.76f;
packet = msgAltt.pack();

oos.writeObject(packet);
oos.flush();
oos.close();
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}finally
{
if(null != socket)
try {
socket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}