2

我得到了java.lang.NullPointerException at FileUploadBean.uploadFile,不知道为什么,因为我的字符串列表中有数据fileData

Java代码:

private List<String> fileData;

public void uploadFile(FileEntryEvent event) {
    System.out.println("Event: " + event.getSource());
    System.out.println("Test");
    FileEntry fileEntry = (FileEntry) event.getSource();
    FileEntryResults results = fileEntry.getResults();
    for (FileEntryResults.FileInfo fileInfo : results.getFiles()) {
        if (fileInfo.isSaved()) {
            System.out.println("File is saved sucessfully");
            fileData.add("FileName: " + fileInfo.getFileName());
            fileData.add("FileSize: " + fileInfo.getSize());
            fileData.add("FileStatus: " + fileInfo.getStatus());
        }
    }
}

public List<String> getFileData() {
    System.out.println("inside getFileData");
    List<String> data = fileData;
    return fileData;
}

public void setFileData(List<String> fileData) {
    this.fileData = fileData;
}

例外:

    Caused by: java.lang.NullPointerException
        at FileUploadBean.uploadFile(FileUploadBean.java:54)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.el.parser.AstValue.invoke(AstValue.java:264)
        at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
        at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
        at org.icefaces.ace.component.fileentry.FileEntry.broadcast(FileEntry.java:306)
        ... 28 more
4

1 回答 1

0

fileDatanull,因为您还没有创建它。将以下内容添加到您的uploadFile方法中:

fileData = new ArrayList<String>();

PS:setFileData你可能不需要的方法。

于 2012-04-11T22:47:16.930 回答