我无法弄清楚为什么我的代码会出现上述错误。每次调用该方法时,我都会创建 FileWriter 和 BufferedWriter 的新实例,但显然流已经关闭。
public static void addSpawn(Location spawn)
{
File spawns = new File("spawns.dat");
FileWriter write = null;
BufferedWriter out = null;
try
{
write = new FileWriter(spawns, true);
out = new BufferedWriter(write);
out.write(locToStr(spawn));
out.newLine();
}
catch(Exception e)
{
System.out.println("Error writing spawn file: " + e.getMessage());
}
finally
{
if(write != null)
{
try
{
write.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
if(out != null)
{
try
{
out.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
} …Run Code Online (Sandbox Code Playgroud) 我正在阅读NeHe的第一个OpenGL编程指南,当它编写完成他的第一个教程的结果时,我很难找到错误.这是发生错误的整个源文件(在Eclipse CDT中创建,'opengl32''glaux''glug32''glu32'成功链接):
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glaux.h>
#define GLEW_STATIC
HGLRC hRC = NULL;
HDC hDC = NULL;
HWND hWnd = NULL;
HINSTANCE hInstance;
bool keys[256];
bool active = TRUE;
bool fullscreen = TRUE;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
GLvoid ResizeGLScene(GLsizei width, GLsizei height)
{
if(height == 0) height = 1;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, (GLfloat) width / (GLfloat) height, 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int InitGL()
{
glShadeModel(GL_SMOOTH);
glClearColor(0, 0, 0, 0);
glClearDepth(1); …Run Code Online (Sandbox Code Playgroud)