Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
来源:互联网 发布:手机屏幕恶作剧软件 编辑:程序博客网 时间:2024/05/28 05:14
连接数据库中出现的错误,虽然解决了,但不知道具体原因,望各位大神能解答下。
下面是解决过程;
====================错误代码========================================
try{
Class.forName("com.mysql.jdbc.Driver");
String url=***; //***为省略内容
String user=***; //***为省略内容
String password=***; //***为省略内容
conn=DriverManager.getVonnection(url,user,password);
}catch(ClassNotFoundException e){
e.printStackTrace();
}catch (SQLException e){
e.printStackTrace();
}
return conn;
}
=================方法===========================
测试结果nullpointerexception
把return conn;移到try{}catch{}块的try{}块中就没有问题了。
具体如下
================正确代码=========================
try{
***
conn=DriverManager.getVonnection(url,user,password);
return conn;
}catch(ClassNotFoundException e){
e.printStackTrace();
}catch (SQLException e){
e.printStackTrace();
}
}
=================================================
这就没问题了
可为什么这样不明白
- Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
- Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
- Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
- Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
- Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
- Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
- 异常Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
- Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
- String报错Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
- Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError:
- Exception in thread "AWT-EventQueue-0" java.lang.StackOverflowError
- 异常Exception in thread "AWT-EventQueue-XX" java.lang.StackOverflowError
- 解决办法:matlab Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap
- Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/jdesktop/swingworker/SwingWorker
- 点击Jbtton后 Exception in thread "AWT-EventQueue-0" java.lang.NullPointerExc
- jogl 拒绝访问Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError:
- Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: com/lowagie/text/pdf/FontMapp
- Exception in thread "AWT-EventQueue-0" java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogge
- expect example
- [Oracle]-[SORT AGGREGATE]-count与索引
- 游戏软件开发基础
- 站点报错“服务器内部错误”/http500如何查看真实报错?
- 内核模块开发中makefile的制作(多文件)
- Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
- 一个关于oracle日志中一个小点的总结
- 南山中学2013级学生手机管理办法
- ungetc()函数的用法
- 黑马程序员--.NET笔记--面向对象基础、构造方法
- 谈谈iOS Animation
- 存储过程和函数
- json如何转为字符串
- 基于cocos2d-x引擎的游戏框架设计