Exception in thread "main" java.lang.Nul?报错-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文

Exception in thread "main" java.lang.Nul?报错

Exception in thread "main" java.lang.NullPointerException
at com.javaeasy.logcarinterface.TrafficRecoderForLog.recordTransport(TrafficRecoderForLog.java:12)
at com.javaeasy.logcarinterface.test.main(test.java:11)


package com.javaeasy.logcarinterface;
import com.javaeasy.transport.Bus;
import com.javaeasy.transport.CarBase;
import com.javaeasy.transport.Bike;


public class test {
	public static void main(String[] args){
	CarBase base=new CarBase(40,"广汽本田","黑色");
	Bus bus=new Bus(30,"一汽迈腾","白色");
	TrafficRecoderForLog.recordTransport(base);
	TrafficRecoderForLog.recordTransport(bus);
	Bike bike=new Bike(10,"Memorid");
	TrafficRecoderForLog.recordTransport(bike);
}
}



明明跟着书一步一步来 为什么会报错?? 对象都已经创建好了啊



展开
收起
爱吃鱼的程序员 2020-06-09 10:20:27 686 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    recordTransport的代码呢?去抛出异常的位置看原因<preclass="brush:java;toolbar:true;auto-links:false;">packagecom.javaeasy.logcarinterface;publicclassTrafficRecoderForLog{publicstaticintcounter=0;publicstaticvoidrecordTransport(RecordeAblerecordeAble){if(recordeAble==null){return;}else{counter++;TrafficStatusForLogstatus=recordeAble.getTransportStatus();System.out.println("以下是经过的弟"+counter+"辆车的信息"+"车速:"+status.getSpeed()+"车名:"+status.getName());}}}



    有可能代码中的status是null,逐步往下追踪

    2020-06-09 10:20:43
    赞同 展开评论 打赏
问答分类:
问答地址:
相关产品:
问答排行榜
最热
最新
相关电子书
更多
Java8简明教...[fredwong].1494561200.pdf
立即下载
EXTENDING SPARK WITH JAVA AGEN
立即下载
低代码开发师(初级)实战教程
立即下载