- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试实现一个保存功能来保存游戏的当前状态。这是我的代码:
public class MyGame extends javax.swing.JFrame implements Serializable {
private void saveGame(java.awt.event.ActionEvent evt) {
JFileChooser fileChooser = new JFileChooser();
int user_command = fileChooser.showSaveDialog(this);
if (user_command == JFileChooser.APPROVE_OPTION) {
try {
File file = fileChooser.getSelectedFile();
ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream(file));
MyGame saveFile = this;
outputStream.writeObject(saveFile);
outputStream.close();
} catch (FileNotFoundException e) {
} catch (IOException e) {System.out.println("ioexception");}
}
}
生成的保存文件为 0 字节。我尝试调试该程序,但它在 outputStream.writeObject(saveFile) 行崩溃。我究竟做错了什么?
编辑:报告 IOException
ioexception
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.plaf.synth.SynthLookAndFeel.paintRegion(SynthLookAndFeel.java:386)
at javax.swing.plaf.synth.SynthLookAndFeel.update(SynthLookAndFeel.java:350)
at javax.swing.plaf.synth.SynthRootPaneUI.update(SynthRootPaneUI.java:77)
at javax.swing.JComponent.paintComponent(JComponent.java:752)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5128)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1479)
at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1410)
at javax.swing.RepaintManager.paint(RepaintManager.java:1224)
at javax.swing.JComponent.paint(JComponent.java:1015)
at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:21)
at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)
at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97)
at java.awt.Container.paint(Container.java:1780)
at java.awt.Window.paint(Window.java:3375)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:796)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:713)
at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:693)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:125)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:641)
at java.awt.EventQueue.access$000(EventQueue.java:84)
at java.awt.EventQueue$1.run(EventQueue.java:602)
at java.awt.EventQueue$1.run(EventQueue.java:600)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:611)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.plaf.synth.SynthLookAndFeel.paintRegion(SynthLookAndFeel.java:386)
at javax.swing.plaf.synth.SynthLookAndFeel.update(SynthLookAndFeel.java:350)
at javax.swing.plaf.synth.SynthPanelUI.update(SynthPanelUI.java:94)
at javax.swing.JComponent.paintComponent(JComponent.java:752)
at javax.swing.JComponent.paint(JComponent.java:1029)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5124)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1479)
at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1410)
at javax.swing.RepaintManager.paint(RepaintManager.java:1224)
at javax.swing.JComponent._paintImmediately(JComponent.java:5072)
at javax.swing.JComponent.paintImmediately(JComponent.java:4882)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:785)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:713)
at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:693)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:125)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:641)
at java.awt.EventQueue.access$000(EventQueue.java:84)
at java.awt.EventQueue$1.run(EventQueue.java:602)
at java.awt.EventQueue$1.run(EventQueue.java:600)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:611)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.plaf.synth.SynthLookAndFeel.paintRegion(SynthLookAndFeel.java:386)
at javax.swing.plaf.synth.SynthLookAndFeel.update(SynthLookAndFeel.java:350)
at javax.swing.plaf.synth.SynthPanelUI.update(SynthPanelUI.java:94)
at javax.swing.JComponent.paintComponent(JComponent.java:752)
at javax.swing.JComponent.paint(JComponent.java:1029)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5124)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1479)
at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1410)
at javax.swing.RepaintManager.paint(RepaintManager.java:1224)
at javax.swing.JComponent._paintImmediately(JComponent.java:5072)
at javax.swing.JComponent.paintImmediately(JComponent.java:4882)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:785)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:713)
at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:693)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:125)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:641)
at java.awt.EventQueue.access$000(EventQueue.java:84)
at java.awt.EventQueue$1.run(EventQueue.java:602)
at java.awt.EventQueue$1.run(EventQueue.java:600)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:611)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.plaf.synth.SynthLookAndFeel.paintRegion(SynthLookAndFeel.java:386)
at javax.swing.plaf.synth.SynthLookAndFeel.update(SynthLookAndFeel.java:350)
at javax.swing.plaf.synth.SynthPanelUI.update(SynthPanelUI.java:94)
at javax.swing.JComponent.paintComponent(JComponent.java:752)
at javax.swing.JComponent.paint(JComponent.java:1029)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5124)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1479)
at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1410)
at javax.swing.RepaintManager.paint(RepaintManager.java:1224)
at javax.swing.JComponent._paintImmediately(JComponent.java:5072)
at javax.swing.JComponent.paintImmediately(JComponent.java:4882)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:785)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:713)
at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:693)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:125)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:641)
at java.awt.EventQueue.access$000(EventQueue.java:84)
at java.awt.EventQueue$1.run(EventQueue.java:602)
at java.awt.EventQueue$1.run(EventQueue.java:600)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:611)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.plaf.synth.SynthLookAndFeel.paintRegion(SynthLookAndFeel.java:386)
at javax.swing.plaf.synth.SynthLookAndFeel.update(SynthLookAndFeel.java:350)
at javax.swing.plaf.synth.SynthPanelUI.update(SynthPanelUI.java:94)
at javax.swing.JComponent.paintComponent(JComponent.java:752)
at javax.swing.JComponent.paint(JComponent.java:1029)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5124)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1479)
at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1410)
at javax.swing.RepaintManager.paint(RepaintManager.java:1224)
at javax.swing.JComponent._paintImmediately(JComponent.java:5072)
at javax.swing.JComponent.paintImmediately(JComponent.java:4882)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:785)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:713)
at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:693)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:125)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:641)
at java.awt.EventQueue.access$000(EventQueue.java:84)
at java.awt.EventQueue$1.run(EventQueue.java:602)
at java.awt.EventQueue$1.run(EventQueue.java:600)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:611)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.plaf.synth.SynthLookAndFeel.paintRegion(SynthLookAndFeel.java:386)
at javax.swing.plaf.synth.SynthLookAndFeel.update(SynthLookAndFeel.java:350)
at javax.swing.plaf.synth.SynthPanelUI.update(SynthPanelUI.java:94)
at javax.swing.JComponent.paintComponent(JComponent.java:752)
at javax.swing.JComponent.paint(JComponent.java:1029)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5124)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1479)
at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1410)
at javax.swing.RepaintManager.paint(RepaintManager.java:1224)
at javax.swing.JComponent._paintImmediately(JComponent.java:5072)
at javax.swing.JComponent.paintImmediately(JComponent.java:4882)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:785)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:713)
at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:693)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:125)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:641)
at java.awt.EventQueue.access$000(EventQueue.java:84)
at java.awt.EventQueue$1.run(EventQueue.java:602)
at java.awt.EventQueue$1.run(EventQueue.java:600)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:611)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.plaf.synth.SynthLookAndFeel.paintRegion(SynthLookAndFeel.java:386)
at javax.swing.plaf.synth.SynthLookAndFeel.update(SynthLookAndFeel.java:350)
at javax.swing.plaf.synth.SynthPanelUI.update(SynthPanelUI.java:94)
at javax.swing.JComponent.paintComponent(JComponent.java:752)
at javax.swing.JComponent.paint(JComponent.java:1029)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5124)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1479)
at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1410)
at javax.swing.RepaintManager.paint(RepaintManager.java:1224)
at javax.swing.JComponent._paintImmediately(JComponent.java:5072)
at javax.swing.JComponent.paintImmediately(JComponent.java:4882)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:785)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:713)
at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:693)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:125)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:641)
at java.awt.EventQueue.access$000(EventQueue.java:84)
at java.awt.EventQueue$1.run(EventQueue.java:602)
at java.awt.EventQueue$1.run(EventQueue.java:600)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:611)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.plaf.synth.SynthLookAndFeel.paintRegion(SynthLookAndFeel.java:386)
at javax.swing.plaf.synth.SynthLookAndFeel.update(SynthLookAndFeel.java:350)
at javax.swing.plaf.synth.SynthPanelUI.update(SynthPanelUI.java:94)
at javax.swing.JComponent.paintComponent(JComponent.java:752)
at javax.swing.JComponent.paint(JComponent.java:1029)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5124)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1479)
at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1410)
at javax.swing.RepaintManager.paint(RepaintManager.java:1224)
at javax.swing.JComponent._paintImmediately(JComponent.java:5072)
at javax.swing.JComponent.paintImmediately(JComponent.java:4882)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:785)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:713)
at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:693)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:125)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:641)
at java.awt.EventQueue.access$000(EventQueue.java:84)
at java.awt.EventQueue$1.run(EventQueue.java:602)
at java.awt.EventQueue$1.run(EventQueue.java:600)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:611)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
最佳答案
为您的游戏创建一个 GameState 类(实现可序列化)并保存它。您在尝试序列化 JFrame 时遇到了异常,并且从那个怪物的外观来看,您不会很快找到解决方法。
// GameState.java
class GameState implements Serializable
{
public int score;
public int numFoos;
// etc etc
}
// MyGame.java
public class MyGame extends javax.swing.JFrame
{
private GameState myState;
private void saveGame(java.awt.event.ActionEvent evt)
{
JFileChooser fileChooser = new JFileChooser();
int user_command = fileChooser.showSaveDialog(this);
if (user_command == JFileChooser.APPROVE_OPTION) {
try
{
File file = fileChooser.getSelectedFile();
ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream(file));
outputStream.writeObject(myState);
outputStream.close();
}
catch (FileNotFoundException e) {System.out.println("blaaagrgr");}
catch (IOException e) {System.out.println("ioexception");}
}
}
}
关于java - ObjectOutputStream writeObject() 方法返回空文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13298297/
我正在尝试按照只能处理 GET 查询的指令编写一个最简单的 Java Web 服务器程序。主要思想是从套接字获取一个ObjectOutputStream,使用ObjectInputStream打开本地
我曾经使用带有 Java 的 Android Studio 在 Android 中保存项目。但是现在我想在我用 Flutter SDK(Dart 语言)重写的应用程序中准确地读取这些数据。但似乎编写的
我正在尝试使用 ObjectOutputStream 将几个对象写入文件。之后,我使用 ObjectInputStream 读取该文件。问题是,我只能读取文件中的第一个对象。当我用 Notepad++
我在解决一个实现问题时遇到了麻烦,我有一个类,它的行为类似于列表,但不是将文件保存在某个集合中,而是将它们保存在磁盘上。 当我想向列表中添加一些元素时,就会出现问题。在文件的开头,我有一个 int 告
有没有办法强制 ObjectOutputStream 不依赖以前的写入,应该每次都写入对象属性和完整信息? 我可以从二进制文件中看到,它只写入以前版本的某种增量,如果您尝试加载随机项,它会失败? 最佳
客户端代码: try { Socket socket = new Socket(ip, port); OutputStream output = soc
Socket Client = new Socket("ip", port); private ObjectOutputStream out; out = new ObjectOutputStream
通过 ObjectOutputStream 发送自制对象时,该对象的服务器类和客户端类必须相同吗? 例如,当某个Action只能在服务器上执行时,因为它需要其他几个仅在服务器上可用的类,那么客户端上的
我的项目由两部分组成:服务器端和客户端。当我启动服务器端时,一切正常,但是当我启动客户端时,我会收到此错误: java.io.IOException: stream active at jav
我有这三个类(class): 命令: package pack; public abstract class Command impements java.io.Serializable {
在我的软件中,我需要通过 ObjectOutputStream 在客户端和服务器之间发送消息。 sender方法的核心如下: .... try { objWriter.writeUnshare
我想向文件添加大量数据。我定义了 HYB 类,因为我的对象包含不同类型的数据(String 和 byte[])。我使用 ObjectOutputStream 和 ObjectInputStream 来
我目前正在学习网络,特别是客户端服务器类(class)。我做了很多研究并实现了各种测试程序,但我无法弄清楚为什么/何时需要使用flush()方法。 总是由输入流读入,怎么可能会有数据误留在输出流中呢?
我正在开发 Android 应用程序,我想提交用户名和密码。我现在正在做的是: 为密码创建哈希值 通过 HTTP 请求连接到身份验证服务器 通过 ObjectOutputStream 发送用户名/哈希
我有一个使用 SSLSocket 连接到服务器的客户端。接下来,我尝试使用 ObjectOutputStream oos = new ObjectOutputStream(sslsocket.getO
这个问题在这里已经有了答案: StreamCorruptedException: invalid type code: AC (1 个回答) 关闭 5 年前。 我试图通过单个 发送不同类的多个可序列
我见过一些人问过类似的问题,但任何人发布的唯一答案是你不应该这样做。 但我已经对这两种方式进行了测试 - 它只适用于这种方式。 服务器端 try { // Obtain inp
我正在尝试编写一款地下城大师游戏,英雄将穿过不同的房间并与怪物战斗并获取元素。我想每次英雄达到新级别时都保存它,但即使我已经在英雄及其使用的所有内容上实现了可序列化,我还是收到了IOException
我正在尝试构建一个客户端-服务器 IDE,但在从内存中编译/运行类获取运行时异常的错误日志/异常日志时遇到问题。 我的代码如下所示: public class ServerThread impleme
我在处理之前提出的 question 时遇到了这个问题。 这可能特定于 ObjectInputStream 而不是一般的二进制读取,因此标题可能具有误导性。 从那里开始的问题基本上是这样的:作者已经将
我是一名优秀的程序员,十分优秀!