java.lang.NullPointerException Ignoring exception during close for [email protected]

1.问题描述:在调试mapreduce辅助排序(二次排序)的过程中,运行程序总是报错

Ignoring exception during close for [email protected]
java.lang.NullPointerException
at org.apache.hadoop.io.WritableComparator.compare(WritableComparator.java:157)
at org.apache.hadoop.mapred.MapTask$MapOutputBuffer.compare(MapTask.java:1269)
at org.apache.hadoop.util.QuickSort.sortInternal(QuickSort.java:74)
at org.apache.hadoop.util.QuickSort.sort(QuickSort.java:63)
at org.apache.hadoop.mapred.MapTask$MapOutputBuffer.sortAndSpill(MapTask.java:1602)
at org.apache.hadoop.mapred.MapTask$MapOutputBuffer.flush(MapTask.java:1491)
at org.apache.hadoop.mapred.MapTask$NewOutputCollector.close(MapTask.java:723)
at org.apache.hadoop.mapred.MapTask.closeQuietly(MapTask.java:2021)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:797)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:341)
at org.apache.hadoop.mapred.LocalJobRunner$Job$MapTaskRunnable.run(LocalJobRunner.java:270)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
8860 [Thread-6] INFO org.apache.hadoop.mapred.LocalJobRunner - map task executor complete.
8872 [Thread-6] WARN org.apache.hadoop.mapred.LocalJobRunner - job_local1887386767_0001
java.lang.Exception: java.lang.NullPointerException
at org.apache.hadoop.mapred.LocalJobRunner$Job.runTasks(LocalJobRunner.java:489)
at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:549)
Caused by: java.lang.NullPointerException
at org.apache.hadoop.io.WritableComparator.compare(WritableComparator.java:157)
at org.apache.hadoop.mapred.MapTask$MapOutputBuffer.compare(MapTask.java:1269)
at org.apache.hadoop.util.QuickSort.sortInternal(QuickSort.java:74)
at org.apache.hadoop.util.QuickSort.sort(QuickSort.java:63)
at org.apache.hadoop.mapred.MapTask$MapOutputBuffer.sortAndSpill(MapTask.java:1602)
at org.apache.hadoop.mapred.MapTask$MapOutputBuffer.flush(MapTask.java:1491)
at org.apache.hadoop.mapred.MapTask$NewOutputCollector.close(MapTask.java:723)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:793)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:341)
at org.apache.hadoop.mapred.LocalJobRunner$Job$MapTaskRunnable.run(LocalJobRunner.java:270)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

2.原因分析:

(1)初步判断是是调用了空指针;

(2)当点击WritableComparator.java:157 会跳转到报错的地方是this.buffer.reset(b1, s1, l1);

public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) {    try {        this.buffer.reset(b1, s1, l1);        this.key1.readFields(this.buffer);        this.buffer.reset(b2, s2, l2);        this.key2.readFields(this.buffer);        this.buffer.reset((byte[])null, 0, 0);    } catch (IOException var8) {        throw new RuntimeException(var8);    }(3)也就是说WritableComparator buffer没有初始化
public class WritableComparator implements RawComparator, Configurable {    private static final ConcurrentHashMap<Class, WritableComparator> comparators = new ConcurrentHashMap();    private Configuration conf;    private final Class<? extends WritableComparable> keyClass;    private final WritableComparable key1;    private final WritableComparable key2;    private final DataInputBuffer buffer;

(4)查找程序中使用到WritableComparator 相关的类的定义是分组类ReducerGroupingComparator  和第一字段的比较类FirstSecondComparator 没有默认的构造函数
public static class ReducerGroupingComparator  extends WritableComparator{//一定要加默认构造函数,且一定要加super,否则会报异常java.lang.NullPointerException Ignoring exception during close for [email protected]    public ReducerGroupingComparator()    {        super(IntPair.class,true);    }    @Override    public int compare(WritableComparable a, WritableComparable b) {        IntPair pairA=(IntPair)a;        IntPair pairB=(IntPair)b;        //年份相同,返回值为0的分为一组        return (int) (pairA.getFirst()-pairB.getFirst());    }}//与FirstSecondComparator中定义的默认对比函数功能相同,这个用于显示设置对比类public  static class FirstSecondComparator extends WritableComparator{    //
//一定要加默认构造函数,且一定要加super,否则会报异常java.lang.NullPointerException Ignoring exception during close for [email protected]
    public FirstSecondComparator()    {        super(IntPair.class,true);    }    @Override    public int compare(WritableComparable a, WritableComparable b) {        IntPair pairA=(IntPair)a;        IntPair pairB=(IntPair)b;        int cmp= (int) (pairA.getFirst()-pairA.getFirst());        if (cmp!=0)        {            return cmp;        }        double A=pairA.getSecond();        double B=pairB.getSecond();        return -((A==B)? 0:(A>B? 1:-1));    }}(5)为什么一定要加这个才不报java.lang.NullPointerException异常?点开super(IntPair.class,true);
会跳转到WritableComparator的构造函数
protected WritableComparator(Class<? extends WritableComparable> keyClass, boolean createInstances) {    this(keyClass, (Configuration)null, createInstances);}在点击this,进一步跳转到另外一个重载构造函数,看到这里大家应该名明白了,上面报异常的地方,就是这些变量没有申请内存空间
protected WritableComparator(Class<? extends WritableComparable> keyClass, Configuration conf, boolean createInstances) {    this.keyClass = keyClass;    this.conf = conf != null ? conf : new Configuration();    if (createInstances) {        this.key1 = this.newKey();        this.key2 = this.newKey();        this.buffer = new DataInputBuffer();    } else {        this.key1 = this.key2 = null;        this.buffer = null;    }

}

自己开发了一个股票智能分析软件,功能很强大,需要的点击下面的链接获取:

https://www.cnblogs.com/bclshuai/p/11380657.html


 

原文地址:https://www.cnblogs.com/bclshuai/p/12329390.html

时间: 2024-10-08 10:41:44

java.lang.NullPointerException Ignoring exception during close for [email protected]的相关文章

hadoop错误Ignoring exception during close for [email&#160;protected] java.io.IOException Spill failed

1.错误    Ignoring exception during close for [email protected] java.io.IOException: Spill failed2.原因     本地磁盘空间不足非hdfs (我是在myeclipse中调试程序,本地tmp目录占满)3.解决     清理.增加空间 如果,您认为阅读这篇博客让您有些收获,不妨点击一下右下角的[推荐]. 如果,您希望更容易地发现我的新博客,不妨点击一下左下角的[关注我]. 如果,您对我的博客所讲述的内容有

?--Porg.springframework.beans.MethodInvocationException: Property &#39;username&#39; threw exception; nested exception is java.lang.NullPointerException

使用BoneCP作为连接池,在启动Tomcat报出以下异常: 一月 02, 2016 2:12:17 下午 org.apache.tomcat.util.digester.SetPropertiesRule begin警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:mynewdpi' did not find a

web 环境项目(intellj部署的tomcat) 重启时报 Exception in thread &quot;HouseKeeper&quot; java.lang.NullPointerException (转)

Exception in thread "HouseKeeper" java.lang.NullPointerException at org.logicalcobwebs.proxool.HouseKeeperController.getHouseKeeperToRun(HouseKeeperController.java:52) at org.logicalcobwebs.proxool.HouseKeeperThread.run(HouseKeeperThread.java:33

(未解决)严重:threw exception java.lang.NullPointerException

问题描述: Servlet.service() for servlet [servlet.AddModuleServlet] in context with path [/PermissionSystem] threw exception java.lang.NullPointerException 添加数据库时,空指针. AddModule.jsp在Module文件夹外则没有问题. 但form中添加路径了啊:<form action="<%=request.getContextPa

HTTP Status 500 - Request processing failed; nested exception is java.lang.NullPointerException

type Exception report message Request processing failed; nested exception is java.lang.NullPointerException description The server encountered an internal error that prevented it from fulfilling this request. exception org.springframework.web.util.Ne

项目启动时出现Exception in thread &quot;HouseKeeper&quot; java.lang.NullPointerException

解决方案: 首先建立一个servlet类: package cn.ydc.framework.util; import java.io.IOException; import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse; i

Servlet.service() for servlet UserServlet threw exception java.lang.NullPointerException 空指针异常

错误付现: 严重: Servlet.service() for servlet UserServlet threw exceptionjava.lang.NullPointerException at com.liuyang.servlet.UserServlet.doGet(UserServlet.java:17) at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) at javax.servlet.http.Http

报错!!!Servlet.service() for servlet [action] in context with path [/myssh] threw exception [java.lang.NullPointerException] with root cause java.lang.NullPointerException

这个为什么报错啊~~ at com.hsp.basic.BasicService.executeQuery(BasicService.java:33) 这个对应的语句是   Query query =this.sessionFactory.getCurrentSession().createQuery(hql); Sep 24, 2017 11:39:50 PM org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.se

structs2中,启动Tomcat时异常:严重: Exception starting filter struts2 java.lang.NullPointerException

structs2中,已搭建好structs2开发环境,程序无任何问题.但是,部署好项目之后,启动Tomcat时Console报错抛出异常: 严重: Exception starting filter struts2 java.lang.NullPointerException 如下图所示: 出现这个错误的原因是:这是struts-2.1.6版本的一个BUG,配置文件中设置了开发者模式,即structs.xml中包含了<constant name="struts.devMode"