lishunli / nutz

Automatically exported from code.google.com/p/nutz
0 stars 0 forks source link

按照Nutz.Dao 入门介绍进行测试,遇到NullPointerException #42

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
我的dao test代码如下:
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://localhost:3306/test");
dataSource.setUsername("root");
dataSource.setPassword("1234");
Dao dao = new NutDao(dataSource);
Person p = new Person();
p.setName("aaa");
p.setAge(20);
dao.insert(p); 

执行完后,数据库中记录确实已插入,但会报错:
Exception in thread "main" java.lang.ExceptionInInitializerError
    at org.nutz.dao.sql.SqlImpl.getInt(SqlImpl.java:164)
    at org.nutz.dao.impl.NutDao.count(NutDao.java:198)
    at org.nutz.dao.impl.NutDao.count(NutDao.java:191)
    at com.zgw.demo.NutzDaoTest.main(NutzDaoTest.java:34)
Caused by: java.lang.NullPointerException
    at org.nutz.castor.Castors.findCastorsInClassPath(Castors.java:51)
    at org.nutz.castor.Castors.<init>(Castors.java:130)
    at org.nutz.castor.Castors.<clinit>(Castors.java:68)
    ... 4 more

windows 系统 IDE:myeclipse 
从源码编译的JDK1.5的jar包
数据库:mysql

Original issue reported on code.google.com by zgw06...@gmail.com on 25 Sep 2009 at 5:54

GoogleCodeExporter commented 9 years ago
这个问题很奇怪,我从未遇到这个问题,能把 Exception 
的堆栈给全吗?
我稍后尝试重现这个问题。

Original comment by zozoh...@gmail.com on 25 Sep 2009 at 4:24

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
控制台错误信息就是这些,我在nutz原文件的src目录下新增一t
est包,将相关测试类移到该包
下,测试就可以了。
=================================
49:private static String[] findCastorsInClassPath(String path) {
50:     File dir = Files.findFile(path);
51:     int pos = dir.getAbsolutePath().length() - path.length();

之前我是新建一工程(nutz_test),导入自编译jdk1.5的jar包,��
�述49行方法参数path
为:org/nutz/castor/castor,执行完50行后,dir为空。故报空指针异常
。估计得修改path的值。

Original comment by zgw06...@gmail.com on 27 Sep 2009 at 6:23

GoogleCodeExporter commented 9 years ago
应该不会出现这个问题
你 Eclipse 工程的 properties > libraries 下面的项目是怎样的?

Original comment by zozoh...@gmail.com on 29 Sep 2009 at 6:57

GoogleCodeExporter commented 9 years ago
包结构见图

Original comment by zgw06...@gmail.com on 30 Sep 2009 at 6:31

Attachments:

GoogleCodeExporter commented 9 years ago
有可能你编译的 Jar 文件中少了一些 class , 尤其是 
org.nutz.castor 下面的Class
附上我的例子工程,用 psql, 你可以换成 mysql 的 JDBC 再试试

Original comment by zozoh...@gmail.com on 1 Oct 2009 at 11:55

Attachments:

GoogleCodeExporter commented 9 years ago
用这个nutz 
jar包,eclipse依赖的jdk得为1.6,似乎jar包存放路径不能包含中�
��

Original comment by zgw06...@gmail.com on 9 Oct 2009 at 2:30

GoogleCodeExporter commented 9 years ago
put it to FAQ

Original comment by zozoh...@gmail.com on 2 Nov 2009 at 3:34

GoogleCodeExporter commented 9 years ago

Original comment by wendal1985@gmail.com on 16 Mar 2010 at 11:27

GoogleCodeExporter commented 9 years ago

Original comment by wendal1985@gmail.com on 13 May 2010 at 10:42