InException in thread "main" java.lang.Nullnonepointerexceptionn at yy.T.main(T.java:35)

当在重启Tomcat容器时 Exception in Thread &HouseKeeper& java.l_小组_ThinkSAAS
当在重启Tomcat容器时 Exception in Thread &HouseKeeper& java.l
当在重启Tomcat容器时 Exception in Thread &HouseKeeper& java.l
使用Proxool连接池, 当在重启Tomcat容器时,出现
Exception in Thread"HouseKeeper"java.lang.NullPointerException
空指针异常错误。
This is because Proxool is not being shutdown properly. If the JVM stops then Proxool recognises that and shuts down gracefully, but if you redeploy Proxool into some environments (for example, a servlet container) then Proxool needs to be explicitly told so by calling ProxoolFacade.shutdown(). If you have a servlet container then you could put it in the servlet's destroy() method. Alternatively, use the ServletConfigurator to both configure and shutdownProxool
解决方法如下:
1. 在Servlet的destroy()方法中显式地proxool关闭连接池:ProxoolFacade.shutdown();
public class ProxoolServlet extends HttpServlet {
public void init() throws ServletException {
public void destroy() {
ProxoolFacade.shutdown();
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
doGet(request,response);
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
public class ProxoolServlet extends HttpServlet {
public void init() throws ServletException {
public void destroy() {
ProxoolFacade.shutdown();
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
doGet(request,response);
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
2. 将该Servlet配置到web.xml中:
&servlet-name&proxoolServlet &/servlet-name&
&servlet-class&xxx.ProxoolServlet&/servlet-class&
&load-on-startup&1&/load-on-startup&
&/servlet&
&servlet-name&proxoolServlet &/servlet-name&
&servlet-class&xxx.ProxoolServlet&/servlet-class&
&load-on-startup&1&/load-on-startup&
&/servlet&
PHP开发框架
缓存Memcache
服务器环境
ThinkSAAS商业授权:
ThinkSAAS为用户提供有偿个性定制开发服务
ThinkSAAS将为商业授权用户提供二次开发指导和技术支持
手机客户端
ThinkSAAS接收任何功能的Iphone(IOS)和Android手机的客户端定制开发服务
让ThinkSAAS更好,把建议拿来。文档分类:
在线文档经过高度压缩,下载原文更清晰。
淘豆网网友近日为您收集整理了关于Java中常见错误和异常解决方法(打印)的文档,希望对您的工作和学习有所帮助。以下是文档介绍:1.java.lang.NullPointerException原因是:有空指针,有地址没赋值2.Exception in thread &main& java.lang.ArithmeticException: / by zero原因是除数是 0 3.ArrayIndexOutOfBoundsException原因是:数组越界4.java.lang.NumberFormatException原因是:数字格式化有问题5.Unhandled exception type Exception原因是:没有进行异常处理6. 进行国际化操作的时候遇到这样的错误: Exception in thread &main&java.util.MissingResourceException: Can't find bundle for base name Message,locale 答:因为在命令提示符中,是没有错误的解决方法是:在 myeclipse 中,会出现这个错误java 国际化之 Can't find bundle for base name1.初步学习最近在学习 ResourseBundl(来源:淘豆网[/p-.html])e 时遇到了“Can't find bundle for base name ”这个错误搞了很久才解决了。原因就是类路径问题要将属性文件放在类路径中!百度里很多都是教程但没有涉及到解决方法! 2.中文显示:测试文件java .lht.ResourseBundleSimport java.util.ResourceBpublic class ResourseBundleDemo {public static void main(String[] args) {ResourceBundle resource = ResourceBundle.getBundle(&test&);System.out.print(resource.getString(&msg0&) + &!&);System.out.println(resource.getString(&msg1&) + &!&); }}test.propertiesmsg0=&Hello World&msg1=&da ji(来源:淘豆网[/p-.html])a hao&开始自己测试的时候:将属性文件放在 bin/下也试过也不行无赖中就在 google 中搜索了一下终于在 sun 的 java 论坛(http://forum.java./thread.jspa?threadID=660477&messageID=4231534)中找到了线索下面是帖子的内容:I've solved the problem the best way possible. Basically what i've done is added a newclass folder named config to the project home dir. Then i added this classfolder to theclasspath in project properties. After doing all of this you only need to reference theproperties file by &Email&.Hope this hel(来源:淘豆网[/p-.html])ps anyone else who is having similiar problems.基本意思就是在 src 下建立 classes(名字无所谓)文件夹将属性文件存放在下面,然后将这个文件夹加入类路径中!运行就可以了:加入类路径的方法:你的工程文件夹-&properties-&选择 Libraries 选项卡-&Add Class Folder将刚才建立的文件夹加入就可以了!结果如下:&Hello World&!&da jia hao&;!2.中文显示在 classes 目录下建立 message_CH.properties 内容如下:ms0=&大家好&同样用上面的测试文件!结果如下:&?ó????&!乱码怎么回事啊!在百度里搜索后找到了答案有以为网友写的很清楚:http://gostar./3885062.html下面引用如下:原理Property 文件中,使用的编码方式根据机器本身的设置可能是 GBK 或者 UTF-8。而在 Java程序中读取 Property 文件的时候使用的(来源:淘豆网[/p-.html])是 Unicode 编码方式,这种编码方式不同会导致中文乱码。因此需要将 Property 文件中的中文字符转化成 Unicode 编码方式才能正常显示中文。解决办法:Java 提供了专门的工具对 Property 文件进行 Unicode 转化,这种工具就是 native2ascii,它在 JDK 安装环境的 bin 目录下。native2ascii 工具将带有本机编码字符(非拉丁 1 和非单一码字符)的文件转换成带有Unicode 编码字符的文件。假设需要转化的属性文件为:D:/src/resources.properties(含有中文字符)转化后的属性文件为:D:/classes/resources.properties(中文字符统一转化为 Unicode)那么使用如下命令JAVA_HOME/bin/native2ascii -encoding GBK D:/src/resources.propertiesD:/classes/resources.properties就能将含有中文字符(来源:淘豆网[/p-.html])的属性文件转化成单一 Unicode 编码方式的属性文件。中文乱码自然会被解决。通过上面的方法我将生成的文件打开一看内容如下:ch=&/u/u597d&再运行结果如下:&大家好&(2)另一种解决办法:Can't find bundle for base nameStruts2国际化异常处理这是找不到指定文件;你必须把.properties 文件,放在与这个调用文件.java 相同的目录里;Hello.java 在 workspace\test\\lj\guojiehua 下hello_en_US.properties 必须在 workspace\test\src .properties 必须在 workspace\test\src 下其实原因是我虽然在 build path 里面加了\pruway\source\source\config,但是系统编译的时候,在 classes 里面应该会自动产生 resource_en_US.properties,可是实际情况是 cla(来源:淘豆网[/p-.html])sses包下面没有产生,故我删掉重加,再编译结果发现通过了。。就是说,只要你 buildpath 路径对了,该路径下也有 resoucebudle 需要的类,那么系统会自动在 classes 里面自动编译产生这些类的。所以,先检查 classes 里,有没有生成对应的 resource_en_US.properties,如果没有,那么检查 build path 路径下有没有对应的 properties 类,如果有,那么证明系统编译没有编译完整,删掉 path,重新 add foler,加入,再编译,检查 classes 下有无。如果都有,那么证明成功。10.java.lang.IllegalThreadStateException解决办法:不能启动两次线程11.java.lang.NoSuchMethodError答:必须有一个 public static void main(String[] args){ //这里是入口 } 作为入口点,启动 java 虚拟机时虚拟机会找这个方法, 如果没(来源:淘豆网[/p-.html])有就报 exception in thread“main”java.lang.nosuchmethoderror12..UnknownHostException:错程序是这样的:解答方式:import .InetApublic class a{public static void main(String args[]) throws Exception {// Address locAdd =InetAddress remAdd =locAdd = InetAddress.getLocalHost() ;// 得到本机remAdd = InetAddress.getByName(&/&) ;System.out.println(&本机的IP地址:& + locAdd.getHostAddress()) ;System.out.println(&MLDNJAVA 的 IP 地址: & +remAdd.getHostAddress()) ;System(来源:淘豆网[/p-.html]).out.println(&本机是否可达:& + locAdd.isReachable(5000)) ;}//5000代表代数};运行后结果为:如果注释掉 remAdd = InetAddress.getByName(&/&) ;运行结果又是这样的:上述程序的解决办法是:将remAdd = InetAddress.getByName(&/&) ;改成程序运行结果如下:完成实验要求,但是这里就有一个问题了,为什么去掉 http//和后面的/的就运行的了呢?(2)但是对于这个极其相似的程序却可以运行出结果:import .InetApublic class b {public static void main(String args[])throws Exception{InetAddress address=InetAddress.getByName(&&);System.out.println(&ip: &+address.getHostAddress());System.o(来源:淘豆网[/p-.html])ut.println(&host: &+address.getHostName());System.out.println(&canonical host name:&+address.getCanonicalHostName());byte[] bytes=address.getAddress();for(byte b:bytes){if(b&=0)System.out.print(b);else System.out.print(256+b);}}}运行结果为:13.运行下列程序出现了这样的错误,这是线程的知识,一个线程如果启动了,再启动一个的时候就会报错:java.lang.IllegalThreadStateException程序如下:class thrund extends Thread{private Spublic thrund(String name){this.name=}public void run(){ //线程完成的动作for(int(来源:淘豆网[/p-.html]) j=0;j&4;j++){System.out.println(name+&第&+j+&个&);}}};public class a {public static void main(String agrs[]){thrund th1=new thrund(&线程A&);//实例化一个线程对象th1.start(); //调用线程主体th1.start(); //调用线程主体}};运行结果如下:14.The public type abc must be defined in its own file 这样的警告是出现在我下面这样的程序中的:所以我在百度上输入这样的问题:java 程序中两个类为什么不能同时有 public(其中有一个是主方法)?得到的回答是这样的:因为一个 GM 规定一个类中只能有一个 PUBLIC 的而且源文件的名字只能和PUBLKIC 属性的类去一个名字。另一种回答是这样的:同个源文件有多个公共类,编译器就找不到应该执行的 main方法了15.运行下列泛型程序时,出现一下错误:程序:class add&T&{private Tpublic T p(T y){System.out.println(y);}}public class a{public static void main (String args[]){add &String& adder=new add&String&();//System.out.println(&输出属性&+adder.getX());//adder.p(&你好,邱林和&);fun(adder);public static void fun(add&?& temp){System.out.println(&内容&+temp);}}}出现了如下错误:其中这个 void is an invalid type for the variable fun 这个错误的解释时:第一步:检查拼写是否错误; 第二步:检查 void actionPerformed(ActionEvent ae){}函数的位置,不能让它嵌套在别的函数里。我不知道为什么,但我这样改对了。通过这个观察上述代码确实发现这个 fun 方法被包含在了主方法中,所以导致这个错误,改成下列程序后,程序运行结果如下:public class a{public static void main (String args[]){add &String& adder=new add&String&();//System.out.println(&输出属性&+adder.getX());//adder.p(&你好,邱林和&);fun(adder);}//一开始这个}被放在了fun函数下面,所以导致了这个错误。public static void fun(add&?& temp){System.out.println(&内容&+temp);}}运行结果如下:16.错误:java:Syntax error on token &;&, , expected17.解释是这样的:int b=3; b=b-2; 应为这 2 行代码写的地方还处在声明定义阶段处。 就好象你脑子里想象着我有 3 块钱(第一行),但是又立马用这想象的 3 快去买物品(第二行)所以卖东西的人肯定会说你(报错).
就是说,b=b-2 这行代码处的位置还处于声明阶段,没有在内存中给他划分空间,你是不能操作的。要么声明为静态的,提前划分空间17,运行以下程序时,报错:程序为:public class a{public static void main(String args[]){Runtime run= Runtime.getRuntime();System.out.println(&JVM 最大内存量:&+run.maxMemory());Process pro= //声明一个Process对象,接收启动的进程try{pro=run.exec(&Thunder.exe&); //调用本机程序,必须进行异常处理}catch(Exception e){ //打印异常信息e.printStackTrace();}try{Thread.sleep(5000);}catch(Exception e){e.printStackTrace();}pro.destroy(); //结束此进程}}运行结果为:这一句有问题,pro=run.exec(&Thunder.exe&); //调用本机程序,必须进行异常处理,里面的Thunder.exe改成”notepad“就有用,不知道为什么?18. java.lang.ArrayStoreException当运行下列程序时出现了这样的错误:import java.util.ArrayLimport java.util.Cimport java.util.Iimport java.util.Lpublic class a{public static void main(String args[]){List&Integer& al= //定义 List 对象Collection&Integer& cl= //定义 Collention 对象al=new ArrayList&Integer&(); //实例化 List 对象,只能是 Integercl=new ArrayList&Integer&(); //实例化 Collection 对象,只能是Integeral.add(0, 34); //在指定位置增加元素al.add(1,343);System.out.println(al);cl.add(5654);cl.add(3434);System.out.println(cl);al.addAll(cl); //从 Collection 继承的方法,增加一组对象String str[]=al.toArray(new String[] {}); //指定的泛型类型System.out.print(&指定数组类型&); //信息输出for(int i=0;i&str.i++){ //输出字符串数组中的内容System.out.print(str[i]+&、&);}System.out.print(&\n 返回对象数组:&);//信息输出Object obj[]=al.toArray(); //直接返回对象数组for(int i=0;i&obj.i++){ //循环输出对象数组内容String temp=(String) obj[i]; //每一个对象都是 String 类型播放器加载中,请稍候...
该用户其他文档
下载所得到的文件列表Java中常见错误和异常解决方法(打印).doc
文档介绍:
1.java.lang.NullPointerException原因是:有空指针,有地址没赋值2.Exception in thread &main& java.lang.ArithmeticException: / by zero原因是除数是 0 3.ArrayIndexOutOfBoundsException原因是:数组越界4.java.lang.NumberFormatException原因是:数字格式化有问题5.Unhandled exception type Exception原因是:没有进行异...
内容来自淘豆网转载请标明出处.Exception in thread &main& java.lang.NullPointerException有关问题求教
&来源:读书人网&【读书人网():综合教育门户网站】
Exception in thread main java.lang.NullPointerException问题求教!下面是源代码出现的异常是Exception
Exception in thread &main& java.lang.NullPointerException问题求教!下面是源代码出现的异常是Exception in thread &main& java.lang.NullPointerExceptionat com.qq.server.db.Text10.&init&(Text10.java:58)at com.qq.server.db.Text10.main(Text10.java:39)58行是 jp2.add(jb2);,39行是Text10 text= new
Text10();求教这问题怎么解决??package com.qq.server.import javax.swing.*;import javax.xml.soap.Timport java.awt.*;import java.awt.event.*;import java.util.*;import java.sql.*;//完成一个迷你版的用户信息管理系统public class Text10
extends JFrame implements ActionListener{JPanel jp1,jp2;JLabel jl1; &
JButton jb1,jb2,jb3,jb4; &
JTJScrollPJTextFVector rowData, columnN//rowData用户来存放行数据//后者用来存放列明//操作需要定义的变量PreparedStatement ps=Connection ct =ResultSet rs=String url=&jdbc:sqlserver://127.0.0.1:1433;databaseName=QQ&;String user=&sa&;String passwd=&322008&;/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubText10 text= new
Text10();} public Text10(){&
jp1=new JPanel(); jtf=new JTextField(10); jb1 = new JButton(&查询&); jb1.addActionListener(this); jl1 = new JLabel(&请输入名字:&);&
jp1.add(jl1); jp1.add(jtf); jp1.add(jb1);&
jb2= new JButton(&添加&); jb3= new JButton(&修改&); jb4= new JButton(&注销&);& &
jp2.add(jb2); jp2.add(jb3); jp2.add(jb4);&
//中间//设置列名
columnNames=
new Vector();
columnNames.add(&号码&);
columnNames.add(&昵称&);
columnNames.add(&性别&);
columnNames.add(&密码&);
columnNames.add(&状态&);
rowData= new Vector();
//从读取数据
//1.加载驱动Class.forName(&com.microsoft.sqlserver.jdbc.SQLServerDriver&);ct=DriverManager.getConnection(url,user,passwd);ps=ct.prepareStatement(&select * from personalinfo &);rs=ps.executeQuery();while(rs.next()){Vector hang = new Vector();hang.add(rs.getString(1));hang.add(rs.getString(2));hang.add(rs.getString(3));hang.add(rs.getString(4));hang.add(rs.getString(5));rowData.add(hang);}
}catch(Exception e){
e.printStackTrace();
if(rs!=null)
rs.close();
if(ps!=null)
ps.close();
if(ct!=null)
ct.close();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
JTable( rowData,columnNames);
jsp= new JScrollPane(jt);
this.add(jsp);
this.add(jp1,&North&);
this.add(jp2,&South&);
this.setVisible(true);
this.setSize(500, 400);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}[解决办法]jp2 没有new 所以是nulljp2.add(jb2);jp2.add(jb3);jp2.add(jb4);

我要回帖

更多关于 java.lang.thread 的文章

 

随机推荐