首页 新闻 会员 周边

List对象不能实例化是为什么?

0
[待解决问题]

今天在学习文件上传,但是在批量上传包含图片的文件时,程序报错。

package com.control;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.bean.Student;
import com.daoImpl.StuManagerDaoImpl;
import com.opensymphony.xwork2.ActionSupport;

 

public class AddAllStuAction extends ActionSupport{

private List<File> image;
private List<String> imageFileName;
private List<String> imageContentType;


//重写父类的execute方法
public String execute(){
StuManagerDaoImpl dao=new StuManagerDaoImpl();
HttpServletRequest request=ServletActionContext.getRequest();
//因为批量添加传过来的信息很多,所有需要定义一个数组进行接收
String [] sid=request.getParameterValues("sid");
String [] sname=request.getParameterValues("sname");
String [] sage=request.getParameterValues("sage");
//得到上传路径
String path=ServletActionContext.getServletContext().getRealPath("/stuImage");
System.out.println(path);
for(int i=0;i<image.size();i++){
//设置目标路径
File file=new File(path,imageFileName.get(i));
try {
//文件拷贝
FileInputStream fis=new FileInputStream(image.get(i));
FileOutputStream fos=new FileOutputStream(file);
//定义一个数组
byte [] b=new byte[1024];
int len;
while((len=fis.read(b))>0){
fos.write(b,0, len);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//现在实例化学生对象
Student stu=new Student();
stu.setSid(Integer.parseInt(sid[i]));
stu.setSname(sname[i]);
stu.setSage(Integer.parseInt(sage[i]));
stu.setSphoto("stuimage"+"\\"+imageFileName.get(i));
dao.toSaveStu(stu);
}
return SUCCESS;
}

public List<File> getImage() {
return image;
}

public void setImage(List<File> image) {
this.image = image;
}

public List<String> getImageFileName() {
return imageFileName;
}


public void setImageFileName(List<String> imageFileName) {
this.imageFileName = imageFileName;
}

public List<String> getImageContentType() {
return imageContentType;
}

public void setImageContentType(List<String> imageContentType) {
this.imageContentType = imageContentType;
}
}

浏览器访问的时候,点击提交,报空指针异常。哪位大神可以指导下我啊?跪求

忽而今夏颖的主页 忽而今夏颖 | 菜鸟二级 | 园豆:202
提问于:2016-04-29 17:47
< >
分享
所有回答(1)
0

在使用之前要setImage

jello chen | 园豆:7336 (大侠五级) | 2016-04-29 18:07

代码里面写了setImage()方法的,但是一直报错。

支持(0) 反对(0) 忽而今夏颖 | 园豆:202 (菜鸟二级) | 2016-04-29 19:07

@忽而今夏颖: 要调用呀

支持(0) 反对(0) jello chen | 园豆:7336 (大侠五级) | 2016-04-29 22:17
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册