init:
deps-jar:
Compiling 1 source file to F:\JavaProject\DrawPad\build\classes
F:\JavaProject\DrawPad\src\DrawPad\DrawPad.java:535: 无法访问的语句
File fileName = fileChooser.getSelectedFile();
1 错误
生成失败(总时间:0 秒)
这个是什么问题啊 谢谢!!
附源码:public void saveFile()
{
fileChooser=new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
int result=fileChooser.showSaveDialog(this);
if(result==JFileChooser.CANCEL_OPTION);
return;
File fileName = fileChooser.getSelectedFile(); fileName.canWrite();
if(fileName==null||fileName.getName().equals(""))
JOptionPane.showMessageDialog(fileChooser,"Invalid File Name",
"Invalid File Name",JOptionPane.ERROR_MESSAGE);
else{
try{
fileName.delete();
FileOutputStream fos=new FileOutputStream(fileName);
output=new ObjectOutputStream(fos);
drawings record;
output.writeInt(index);
for(int i=0;i<index;i++)
{
drawings p=itemList[i];
output.writeObject(p);
output.flush();
}
output.close();
fos.close();
}
catch(IOException ioe)
{
ioe.printStackTrace();
}
}
}
deps-jar:
Compiling 1 source file to F:\JavaProject\DrawPad\build\classes
F:\JavaProject\DrawPad\src\DrawPad\DrawPad.java:535: 无法访问的语句
File fileName = fileChooser.getSelectedFile();
1 错误
生成失败(总时间:0 秒)
这个是什么问题啊 谢谢!!
附源码:public void saveFile()
{
fileChooser=new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
int result=fileChooser.showSaveDialog(this);
if(result==JFileChooser.CANCEL_OPTION);
return;
File fileName = fileChooser.getSelectedFile(); fileName.canWrite();
if(fileName==null||fileName.getName().equals(""))
JOptionPane.showMessageDialog(fileChooser,"Invalid File Name",
"Invalid File Name",JOptionPane.ERROR_MESSAGE);
else{
try{
fileName.delete();
FileOutputStream fos=new FileOutputStream(fileName);
output=new ObjectOutputStream(fos);
drawings record;
output.writeInt(index);
for(int i=0;i<index;i++)
{
drawings p=itemList[i];
output.writeObject(p);
output.flush();
}
output.close();
fos.close();
}
catch(IOException ioe)
{
ioe.printStackTrace();
}
}
}
return;
File fileName = fileChooser.getSelectedFile();
fileName.canWrite();
老兄有几处错误哦,你用我的与你自己的比较一下吧: public void saveFile()
{
fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
int result = fileChooser.showSaveDialog(this);
if (result == JFileChooser.CANCEL_OPTION) {
return;
}
else {
File fileName = fileChooser.getSelectedFile();
fileName.canWrite();
if (fileName == null || fileName.getName().equals("")) {
JOptionPane.showMessageDialog(fileChooser, "Invalid File Name",
"Invalid File Name", JOptionPane.ERROR_MESSAGE);
}
else {
try {
fileName.delete();
FileOutputStream fos = new FileOutputStream(fileName);
output = new ObjectOutputStream(fos);
drawings record;
output.writeInt(index); for (int i = 0; i < index; i++) {
drawings p = itemList[i];
output.writeObject(p);
output.flush();
}
output.close();
fos.close();
}
catch (IOException ioe) {
ioe.printStackTrace(); }
}
}
}
好好看看吧,你怎么if后面都不加这个呀{},写java代码的大忌哦!
{
fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
int result = fileChooser.showSaveDialog(this);
if (result == JFileChooser.CANCEL_OPTION) {
return;
}
else {
File fileName = fileChooser.getSelectedFile();
fileName.canWrite();
if (fileName == null || fileName.getName().equals("")) {
JOptionPane.showMessageDialog(fileChooser, "Invalid File Name",
"Invalid File Name", JOptionPane.ERROR_MESSAGE);
}
else {
try {
fileName.delete();
FileOutputStream fos = new FileOutputStream(fileName);
output = new ObjectOutputStream(fos);
drawings record;
output.writeInt(index); for (int i = 0; i < index; i++) {
drawings p = itemList[i];
output.writeObject(p);
output.flush();
}
output.close();
fos.close();
}
catch (IOException ioe) {
ioe.printStackTrace(); }
}
}
}