{"id":1847,"date":"2022-08-30T15:19:56","date_gmt":"2022-08-30T15:19:56","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/12\/02\/problem-about-objectinputstream-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:19:56","modified_gmt":"2022-08-30T15:19:56","slug":"problem-about-objectinputstream-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/problem-about-objectinputstream-collection-of-common-programming-errors\/","title":{"rendered":"problem about objectinputstream-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/212eb83eaf694896b16169e07d350074?s=32&amp;d=identicon&amp;r=PG&amp;f=1\" \/><br \/>\nakafortes<br \/>\njava android objectinputstream<br \/>\nI have created a java server and an Android client and the client asks data from the server using a custom class &#8220;Message&#8221; I&#8217;ve created. I&#8217;ve made a JAR file with this Message class and used it as an external referance in both the server and the client.Message Class:import java.io.Serializable;public class Message implements Serializable {private static final long serialVersionUID = 1L;public String sender, content, type;public Message(String sender, String type, String content) {this.sender = s<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/AuY9o.png?s=32&amp;g=1\" \/><br \/>\nAndrew Thompson<br \/>\njava serialization io nullpointerexception objectinputstream<br \/>\nI&#8217;m writing a server-client application with Java, on Android and Windows. I want to send the user&#8217;s information (Username and password) to the server for verification. client sends the object containing the information, but the server doesn&#8217;t receive it! here is the Object class:package Model;import java.io.Serializable;public class StringObject implements Serializable {private static final long serialVersionUID = 1L; private String Username=null; private String Password=null;public void setPas<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/6a62362ec20cc0677a03d69669a245f5?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nprmatta<br \/>\njava multithreading executorservice objectinputstream<br \/>\nI have a thread that sits and reads objects off of an ObjectInputStream:public void run() {try {ois = new ObjectInputStream(clientSocket.getInputStream());Object o;while ((o = ois.readObject()) != null) {\/\/do something with object}} catch (Exception ex) {\/\/Log exception} }readObject does not throw InterruptedException and as far as I can tell, no exception is thrown when this thread is interrupted. How do I stop this thread?<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/424b8a32a33d121f2e3f79fdd38ede60?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nMarc-Andre<br \/>\njava objectinputstream objectoutputstream eofexception<br \/>\nI wrote some client &#8211; server program, that shares data but at server side i got EOFException after reciving data. I tried to fix it on my own but it is hard to find own errors.The error is caused by this line: Message command =(Message) serInputStream.readObject();Here is some output from server:java.io.EOFExceptionat Java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:2577) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1315) at java.io.ObjectInputStr<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/ce84c3fb1d8cbce03a2f03f0011f52d3?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nMike Pennington<br \/>\njava sockets networking tcp objectinputstream<br \/>\nI&#8217;m trying to read an object from client program over tcp. As you can see in this line I created objectInput:ObjectInputStream objectInput = new ObjectInputStream(incoming.getInputStream());And then read my input from the other program. It used to work fine until i made minor changes to clean up the program. Personally Assume I added objectInput.clsoe();My question is, After reading the object should I close the objectInputStream or Keep remain without close? Should I close it straight away afte<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/5841fb94408beca0500643d068dcfdc7?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nGreg Butzi<br \/>\njava serialization tcp objectoutputstream objectinputstream<br \/>\nI&#8217;ve serialized some objects so I can convert them to byte arrays for a TCP packet. When I send the objects from the server program to the client program, there are no issues and it works fine. However, even though the code between the server and client is identical, when I try to send objects from the client to the server I get an invalid header.Here are the objects I&#8217;m serializing:public static byte[] serialize(Hand c) throws IOException{ByteArrayOutputStream baos = new ByteArrayOutputStream()<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/01e269c84d1485960c02df06f2e786b4?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nmithun1538<br \/>\njava objectoutputstream objectinputstream eofexception<br \/>\nI have the following code on the applet side:URL servlet = new URL(appletCodeBase, &#8220;FormsServlet?form=requestRoom&#8221;); URLConnection con = servlet.openConnection();con.setDoOutput(true); con.setDoInput(true); con.setUseCaches(false); con.setRequestProperty(&#8220;Content-Type&#8221;, &#8220;application\/octet-stream&#8221;);ObjectOutputStream out = new ObjectOutputStream(con.getOutputStream()); out.writeObject(user);\/\/user is an object of a serializable class out.flush(); out.close();ObjectInputStream in = new ObjectInput<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/2511197166a4f7345d22e91f5d21f92c?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nAlexander Fragotsis<br \/>\njava client-server objectinputstream<br \/>\nmy code is thistry{\/\/Connect to the login serversocket = new Socket(hostName , 15000);out = new ObjectOutputStream(socket.getOutputStream());input = new ObjectInputStream(socket.getInputStream());.. \/\/perform the login , if the login succeed make answ=1;}catch (UnknownHostException e) {System.err.println(&#8220;Unknown host: &#8221; + hostName);StatusLabel.setText(&#8220;Unknown host&#8221;);}catch (ConnectException e) {System.err.println(&#8220;Connection refused by host: &#8221; + hostName);StatusLabel.setText(&#8220;Connection refuse<\/li>\n<\/ul>\n<p id=\"rop\"><small>Originally posted 2013-12-02 20:59:40. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>akafortes java android objectinputstream I have created a java server and an Android client and the client asks data from the server using a custom class &#8220;Message&#8221; I&#8217;ve created. I&#8217;ve made a JAR file with this Message class and used it as an external referance in both the server and the client.Message Class:import java.io.Serializable;public class [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1847","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1847","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1847"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1847\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1847"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1847"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1847"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}