编译时错误, expected,请指教!!!

phay 2005-05-14 10:23:26
Vector columnNames = new Vector();
String[] tableHeader = {
new String("名字"),
new String("大小"),
new String("类型"),
new String("修改日期")
};

columnNames.addElement(tableHeader);
...全文
1816 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
helpall 2005-05-14
  • 打赏
  • 举报
回复
不好意思,借phay (初学者) 的宝地回答lvy1984(可爱小甜甜) 的问题. :-)
helpall 2005-05-14
  • 打赏
  • 举报
回复
上数第三行,"提问"按纽.
phay 2005-05-14
  • 打赏
  • 举报
回复
十分感谢,就是这个,我自己不知什么时候才能想到呢,动手编程太少了,谢谢指教!!:)
lvy1984 2005-05-14
  • 打赏
  • 举报
回复
我没看到发新帖的地方在哪?按什么发新帖哦?
helpall 2005-05-14
  • 打赏
  • 举报
回复
问题找到.
是因为你的addElement没有放在任何方法内. 其他注释掉的行也应该放在一个方法内.
可以这样解决:
{
columnNames.addElement(tableHeader);
}

phay 2005-05-14
  • 打赏
  • 举报
回复
注册了就可以到各个分版面发帖了,
lvy1984 2005-05-14
  • 打赏
  • 举报
回复
我想问下,怎样才能发帖子提问题哈?
phay 2005-05-14
  • 打赏
  • 举报
回复
好的,如下
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;

public class FileTable extends JTable {
/* String[] columnNames = {
"名称","大小","类型","修改日期"
};*/
Vector columnNames = new Vector(4,1);
String[] tableHeader = {
new String("名字"),
new String("大小"),
new String("类型"),
new String("修改日期")
};

// tableHeader[0] = "名字" ;
// tableHeader[1] = "大小" ;
// tableHeader[2] = "大小" ;
// tableHeader[3] = "修改日期";
/* columnNames.addElement(name);
columnNames.addElement(size);
columnNames.addElement(type);
columnNames.addElement(modify);*/


Vector subFilesInfo = new Vector(5,10);
columnNames.addElement(tableHeader);
public FileTable() {
setModel( new DefaultTableModel(subFilesInfo,columnNames));
}


//完成更新table的功能 参数path为当前文件目录(一定为文件夹)的路径信息
public void updateTable(String path) {
File currentFile = new File(path);
File[] subFiles;
subFiles = currentFile.listFile();
String[] fileInfo = {
new String(),
new String(),
new String(),
new String()
};
String fileName,fileSize,fileModifyTime,fileType;
int i = subFiles.length;
for ( int i = 0; i < subFilesNum ; i ++){
if (!subFiles[i].isDirectory())
{
fileName = subFiles[i].getName();
fileSize = new Long(subFiles[i].length()).toString();
fileModifyTime = new Date(subFiles[i].lastModified()).toString();
int length = fileName.length();
for (int j = 0; j < length; j++){
if(fileName.charAt(j-1) == '.') {
fileType = fileName.substring(j,length - 1);
break;
} else {
fileType = new String("");
}
fileInfo[0] = fileName;
fileInfo[1] = fileType;
fileInfo[2] = fileSize;
fileInfo[3] = fileModifyTime;
}
subFilesInfo.addElement(fileInfo);
}
}
}
}
helpall 2005-05-14
  • 打赏
  • 举报
回复
把你的全部代码贴出来.

我是把你的代码放在我的类里编译的.
phay 2005-05-14
  • 打赏
  • 举报
回复
我用的JCreator, 编译时错误信息就这么多:
<identifier> expected,
我的为什么出错阿,
helpall 2005-05-14
  • 打赏
  • 举报
回复
我把你的代码编译了一下,没有问题.
helpall 2005-05-14
  • 打赏
  • 举报
回复
能把具体出错信息拷贝在这吗?
phay 2005-05-14
  • 打赏
  • 举报
回复
最后以行
helpall 2005-05-14
  • 打赏
  • 举报
回复
没有看出什么问题啊. 具体的错误信息?哪一行?

62,616

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧