上传文件时报空指针异常

Cindy林雨霏 2014-02-10 09:52:25
...全文
1096 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
卤煮确定把文件上传到web服务器了吗
chaluhe003 2014-02-11
  • 打赏
  • 举报
回复
检查是不是null 如果不 是null 在检查 这个文件 是不是个空文件
cao_yunfei 2014-02-10
  • 打赏
  • 举报
回复
CardBinAction 中 insertBin 方法调用insertDB时, FILE文件是否为空?
Cindy林雨霏 2014-02-10
  • 打赏
  • 举报
回复
引用 4 楼 fangmingshijie 的回复:
filepath为空,不会包空指针异常,顶多throws FileNotFoundException异常。另外在另外两个类里面有问题。
可以再详细一点吗
Cindy林雨霏 2014-02-10
  • 打赏
  • 举报
回复
引用 7 楼 sunbo624 的回复:
看FileInputStream代码就知道了 肯定是file为空

    public FileInputStream(File file) throws FileNotFoundException {
        String name = (file != null ? file.getPath() : null);
        SecurityManager security = System.getSecurityManager();
        if (security != null) {
            security.checkRead(name);
        }
        if (name == null) {
            throw new NullPointerException();
        }
        fd = new FileDescriptor();
        fd.incrementAndGetUseCount();
        open(name);
    }
那怎么解决呢
sunbo624 2014-02-10
  • 打赏
  • 举报
回复
看FileInputStream代码就知道了 肯定是file为空

    public FileInputStream(File file) throws FileNotFoundException {
        String name = (file != null ? file.getPath() : null);
        SecurityManager security = System.getSecurityManager();
        if (security != null) {
            security.checkRead(name);
        }
        if (name == null) {
            throw new NullPointerException();
        }
        fd = new FileDescriptor();
        fd.incrementAndGetUseCount();
        open(name);
    }
Cindy林雨霏 2014-02-10
  • 打赏
  • 举报
回复
引用 3 楼 miraclestar 的回复:
多打印log看看 看错误,是说42行有空指针 估计也就是filepath了,打印出来看看就知道了
filepatn为null
  • 打赏
  • 举报
回复
filepath为空,不会包空指针异常,顶多throws FileNotFoundException异常。另外在另外两个类里面有问题。
miracleliu 2014-02-10
  • 打赏
  • 举报
回复
多打印log看看 看错误,是说42行有空指针 估计也就是filepath了,打印出来看看就知道了
Cindy林雨霏 2014-02-10
  • 打赏
  • 举报
回复
引用 1 楼 rui888 的回复:
那看下你的filepath
filepath就是导入的io.file的实例
tony4geek 2014-02-10
  • 打赏
  • 举报
回复
那看下你的filepath
yejia66561 2014-02-10
  • 打赏
  • 举报
回复
肯定是filepath的事,可以先用本地的文件做个测试File file = new File("本地路径")看看对不对。
limin_ding 2014-02-10
  • 打赏
  • 举报
回复
验证一下filepath是否准确(可能为空,或者这个path根本就不存在)
tony4geek 2014-02-10
  • 打赏
  • 举报
回复
你的filepath 这个就是 null 。你应该找找源头filepath

81,094

社区成员

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

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