Exception in thread Thread-0 java.lang.NullPointerException
Exception in thread "Thread-0" java.lang.NullPointerException
package server; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.net.ServerSocket; import java.net.Socket; import publiClass.Datas; import publiClass.SysConstants; import publiClass.Tools; //启动线程 public class Serveryancheng extends Thread{public static void main(String[] args) {//启动服务线程System.out.println("服务器启动成功");new Serveryancheng().start(); }public void run(){//服务器socket初始化ServerSocket serversocket = null;Socket socket =null;ObjectOutputStream oos = null;ObjectInputStream ois= null;try {serversocket =new ServerSocket(Integer.parseInt(Tools.getVlaue(SysConstants.SYS_LISTENERPORT)));//设置死循环,设置监听while(true){......此处省略很多字......}} catch (NumberFormatException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (ClassNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace(); }finally {try {//关闭流oos.close();ois.close();socket.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace(); } }System.out.println("服务器终止"); //处理客户端发送的请求方法 //向客户端发送响应} } SysConstants.SYS_LISTENERPORT为监听端口。Tools.getVlaue为取出.properties表中的与SysConstants.SYS_LISTENERPORT对应的port值。Integer.parseInt 运行ServerSocket(Integer.parseInt(Tools.getVlaue(SysConstants.SYS_LISTENERPORT)));之后就出现错误: 服务器启动成功 Exception in thread "Thread-0" java.lang.NullPointerExceptionat server.Serveryancheng.run(Serveryancheng.java:75)
空指针异常
恩,我也知道是空指针异常,但是就是不知道为什么会异常。
抱歉,刚开始没有看全,错误提示75行,如果你注释掉75看可以吗?
恩,不行哦!
不可以?又报的什么错误啊
错误往下走到} catch (IOException e) {
serversocket =new ServerSocket(Integer.parseInt(Tools.getVlaue(SysConstants.SYS_LISTENERPORT)));这里获得服务器的端口号没啊,打印下看看
怎么说呢,我在这句代码前打点,这个时候是看不到的,但是我再往下的时候程序跳进了properties.class中,而SysConstants.SYS_LISTENERPORT这个对应的port的取值在sys.properties中。
哦,你说你的程序是在运行ServerSocket(Integer.parseInt(Tools.getVlaue(SysConstants.SYS_LISTENERPORT)));之后就出现错误的,那么你要确定是否取到端口号的值了,如果有值,你说然后程序跳进了properties.class中,那你要确定properties.class这里面有没有错
哦,可properties.class不是底层类来的么?
啊哦,那你就确定你是否获得端口号了没啊,建议你可以先不加断点,直接打印下,看看有没有值
昨天我调试的时候是可以用的,程序都可以走,今天打开电脑的时候就用不了了,无语得!我研究下
- 提问者评价
-
不管怎么样虽然没解决,但是还是非常感谢你!我自己再研究下
分享
莫说me | 五级 采纳率45%
擅长: JAVA相关 其他编程语言 移动开发
其他类似问题
- 2009-07-14Exception in thread "main" jav...20
- 2012-08-14Java运行错误:Exception in thread "...6
- 2007-11-06Exception in thread "main" jav...29
- 2007-12-15Exception in thread "AWT-Event...19
- 2010-05-07Exception in thread "main" jav...17
为您推荐:
其他4条回答
分享
75行就是这个东西,oos.close(); 在这个程序里有两个main()方法,一个是线程的,另一个是主界面的!
分享
75行就是这个东西,oos.close();在这个程序里有两个main()方法,一个是线程的,另一个是主界面的!
oos没初始化?new一个先
上面有个:ObjectOutputStream oos = null; ObjectInputStream ois= null; 我不知道这么写对不对,我也很有疑问。
oos = new ObjectOutputStream(socket.getOutputStream());
额...报错了! 加进去后是: ois cannot be resolved to avariable oos cannot be resolved to a variable
里面,前面的代码保持不变。 放在while(true){ socket=serversocket,accecpt(); oos = new ObjectOutputStream(socket.getOutputStream())
不明白!
分享
不为空,我在.properties文件里面给port赋了一个端口值
Exception in thread Thread-0 java.lang.NullPointerException相关推荐
- eclipse问题(!MESSAGE Unhandled event loop exception !STACK 0 java.lang.NullPointerException at org.e)
问题: !MESSAGE Unhandled event loop exception !STACK 0 java.lang.NullPointerException at org.eclipse.s ...
- java textarea append_JavaFX TextArea.append()导致java.lang.NullPointerException
我正在读取一个串口并将其写入文本区域作为滚动值.我创建了SerialPortReader类,它运行良好.我的主代码只是调用"updateTextArea()"来告诉类textare ...
- 【已解决】关于IDEA中 Driver 出现Exception in thread quot;mainquot; java.lang.NullPointerException问题
在学习hive过程中,按照mapreduce编程规范,分别编写Mapper,Reducer,Driver,在编写Driver后运行报错了,花了两天,找到了解决方案(裂开.JPG). 代码: packa ...
- 一次空指针异常Exception in thread “main“ java.lang.NullPointerException
今天在学习JDBC的时候遭遇了一次空指针异常,报错内容 Exception in thread "main" java.lang.NullPointerException at c ...
- 空指针异常Exception in thread “main“ java.lang.NullPointerException
目录 例子: 实体类: 主程序 解决方法: map=new HashMap()和map=null的区别 引入:JVM内存机制 引入:HashMap结构 例子: 实体类: public class C ...
- Exception in thread Spider-0 java.lang.NullPointerException - Gecco爬虫心得
使用Gecco爬虫时偶尔遇到如下莫名其妙的异常而停止: Exception in thread "Spider-0" java.lang.NullPointerException ...
- Exception in thread “HiveServer2-Handler-Pool: Thread-67“ java.lang.OutOfMemoryError: Java heap spac
错误信息提示如下 Exception in thread "HiveServer2-Handler-Pool: Thread-67" java.lang.OutOfMemoryEr ...
- 严重: Servlet.service() for servlet jsp threw exception java.lang.NullPointerException
在用maven管理的项目开发过程中,服务器我们用的是tomcat,有时候我们依赖的jar包会和tomcat自带的jar包起冲突,但是不加呢,jsp页面的<script>标签又会报红,虽然不 ...
- threw ‘java.lang.NullPointerException‘ exception // toString()
Method threw 'java.lang.NullPointerException' exception. Cannot evaluate org.json.JSONObject.toStrin ...
- Method threw ‘java.lang.NullPointerException‘ exception. Cannot evaluate com.sun.proxy.xxx
我在debug的时候发现会出现 Method threw 'java.lang.NullPointerException' exception. Cannot evaluate com.sun.pro ...
最新文章
- node 压缩模块速成
- 网络表述学习经典论文——DeepWalk
- javaScript中变量作用域
- css写出三角形(兼容IE)
- ubuntu ifconfig_Ubuntu 设置固定 IP 最简单的方法!
- Kubernetes详解(十八)——Pod就绪性探针实战
- 技巧~向URL地址添加参数
- Hybrid APP的离线存储总结
- MFC Windows 程序设计[二十一]之树形控件
- 0204UNIFORM SIZE=10M?index?insert分裂
- 《项目》 之 ESP8266 心知天气 + 时钟 + WS2812点阵屏 + B站粉丝计数
- Aras innovator: 如何制作一个itemtype的BOM结构
- python数据挖掘课后题答案_中国大学MOOC《数据挖掘与python实践》章节答案
- 移动硬盘加密后在linux中如何使用方法,移动硬盘上的文件加密方法
- win7 64位搭建scrapy
- bernoulli_Python-Bernoulli发行
- git push.default Update were rejected because a pushed branch tip is behand remote
- 软件工程学习笔记(三)软件需求工程
- python 生孩子朋友圈_生孩子发朋友圈的开心的句子
- Linux系统通过firewall限制或开放IP及端口
热门文章
- 凝思系统激活序列号_安装凝思linux操作系统.doc
- Ubuntu下多网卡配置RTNETLINK answers: File exists的解决方案
- FlashFXP绿色版
- 【英语:基础高阶_全场景覆盖表达】K3.口语陈述的思维拓展
- 计算机研究生复试面试题目
- 【ORM】TypeORM 与 Prisma 的详细对比
- 【GDOI2014模拟】​Pty爬山
- 详细剖析市面手机基带/射频/处理器配置, 比较各家手机性能
- ArcGIS API For JavaScript官方文档之Dojo
- iDB-数据库自动化运维平台