Я попытался отправить объект с моего телефона Android на свой компьютер, но я продолжаю получать эту ошибку, которая не может распознать класс этого объекта. Это странно, потому что, когда я пытался отправить ocject с компьютера на себя, он работал так же. Оба пакета имеют класс User, и он реализует Serializable. скажите, пожалуйста, почему это происходит.Отправка пользовательского объекта из приложения android (клиента) на компьютер (сервер)
компьютер (сервер):
private ServerSocket server;
private ObjectInputStream input;
private Socket connection;
private User message;
public void brains() throws IOException {
while (true) {
System.out.println("waiting for connection...");
try {
server = new ServerSocket(4567, 100);
connection = server.accept();
System.out.println("you are now conected");
} catch (IOException ioException) {
ioException.printStackTrace();
}
System.out.println("Setting up Streams..");
input = new ObjectInputStream(connection.getInputStream());
try {
message = (User) input.readObject();
} catch (ClassNotFoundException ex) {
System.out.println("I dont know wtf");
}
System.out.print("the user ");
message.printUserName();
System.out.print(", used your app at ");
message.printTime();
System.out.println("");
System.out.println("Shutting down!");
try {
input.close();
connection.close();
server.close();
} catch (IOException ioException) {
ioException.printStackTrace();
}
}
}
телефон (клиент):
private User user;
private Socket connection;
private ObjectOutputStream output;
public void run() {
try{
connection = new Socket (InetAddress.getByName(ip), 4567);
output = new ObjectOutputStream(connection.getOutputStream()) ;
user = new User("bla bla", "14:09");
output.writeObject(user);
output.flush();
}catch(Exception e){
System.out.print(e);
}finally{
try{
output.close();
connection.close();
}
catch(Exception e){
System.out.print(e);
}
}
}
это журнал консоли:
waiting for connection...
you are now conected
Setting up Streams..
Dont recognize the class
the user Exception in thread "main" java.lang.NullPointerException
at whosUsing.whosUsing.brains(whosUsing.java:34)
at whosUsing.test.main(test.java:9)
сделать оба класса пользователя существуют в том же пакете? см. Http://stackoverflow.com/questions/2916107/readobject-method-throws-classnotfoundexception – coderatchet