帮忙调试这个程序!!!!谢谢!!!急!

zmrljl 2002-12-16 11:07:31
import java.util.*;
import java.io.*;
public class ReadIniFile {

private static Hashtable has = new Hashtable();
static String head = "#";
public ReadIniFile() {
}
public void ReadFile() throws Exception {
**** ClassLoader classloader = getClass().getClassLoader();
**** PropertyResourceBundle resource =new PropertyResourceBundle(classloader.getResourceAsStream("D://ConnectionPool.ini"));
//InputStream resource = getClass().getResourceAsStream("D://ConnectionPool.ini");
Enumeration enu = resource.getKeys();
while (enu.hasMoreElements()) {
String alias = (String) enu.nextElement();
if (alias.endsWith("jdbcDriver")) {
// String str="jdbcDriver";
puthashtable(alias, "jdbcDriver", resource);
}
}
}
private void puthashtable(String alias,String str,PropertyResourceBundle resource)
throws Exception {
//read from resource
String connectalias = alias.substring(0, alias.length() - str.length());
if (has.get(head + connectalias) == null) {
String jdbcDriver = resource.getString(connectalias + "jdbcDriver");
String jdbcURI = resource.getString(connectalias + "jdbcURI");
String dbusername = resource.getString(connectalias + "dbusername");
String dbpassword = resource.getString(connectalias + "dbpassword");
System.out.println(jdbcDriver+""+jdbcURI+""+dbusername+""+dbpassword+"");
}
}



public static void main(String[] args) throws Exception {
ReadIniFile readIniFile1 = new ReadIniFile();
readIniFile1.ReadFile();


}
}


一到*出跳出了
...全文
26 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
study_body 2002-12-16
  • 打赏
  • 举报
回复
知道哪里错了还不知道如何修改吗?
zmrljl 2002-12-16
  • 打赏
  • 举报
回复
错误是找到了,怎么修改这个程序!
zmrljl 2002-12-16
  • 打赏
  • 举报
回复
那就说明程序没找到ConnectionPool.ini文件???
liujuntao 2002-12-16
  • 打赏
  • 举报
回复
同意楼上的意见,其实,你可以
ClassLoader classloader = getClass().getClassLoader();
System.out.println("Hello");
PropertyResourceBundle resource =new PropertyResourceBundle(classloader.getResourceAsStream("D://ConnectionPool.ini"));
System.out.println("bye");
然后,就知道,是那句话出现问题了的!
study_body 2002-12-16
  • 打赏
  • 举报
回复
import java.util.*;
import java.io.*;
public class t021216 {

private static Hashtable has = new Hashtable();
static String head = "#";
public t021216() {
}
public void ReadFile() throws Exception {
System.out.println("before");
ClassLoader classloader = getClass().getClassLoader();
System.out.println("after");
PropertyResourceBundle resource =new PropertyResourceBundle(classloader.getResourceAsStream("D:/ConnectionPool.ini"));
//InputStream resource = getClass().getResourceAsStream("D://ConnectionPool.ini");
Enumeration enu = resource.getKeys();
while (enu.hasMoreElements()) {
String alias = (String) enu.nextElement();
if (alias.endsWith("jdbcDriver")) {
// String str="jdbcDriver";
puthashtable(alias, "jdbcDriver", resource);
}
}
}
private void puthashtable(String alias,String str,PropertyResourceBundle resource)
throws Exception {
//read from resource
String connectalias = alias.substring(0, alias.length() - str.length());
if (has.get(head + connectalias) == null) {
String jdbcDriver = resource.getString(connectalias + "jdbcDriver");
String jdbcURI = resource.getString(connectalias + "jdbcURI");
String dbusername = resource.getString(connectalias + "dbusername");
String dbpassword = resource.getString(connectalias + "dbpassword");
System.out.println(jdbcDriver+""+jdbcURI+""+dbusername+""+dbpassword+"");
}
}



public static void main(String[] args) throws Exception {
t021216 readIniFile1 = new t021216();
readIniFile1.ReadFile();


}
alphazhao 2002-12-16
  • 打赏
  • 举报
回复
PropertyResourceBundle resource =new PropertyResourceBundle(classloader.getResourceAsStream("D://ConnectionPool.ini"));
是这句的问题拉
你classloader.getResourceAsStream("D://ConnectionPool.ini")返回的是一个为null的InputStream对象,所以会造成空指针错误……
zmrljl 2002-12-16
  • 打赏
  • 举报
回复
java.lang.NullPointerException

at java.io.Reader.<init>(Reader.java:61)

at java.io.InputStreamReader.<init>(InputStreamReader.java:80)

at java.util.Properties.load(Properties.java:189)

at java.util.PropertyResourceBundle.<init>(PropertyResourceBundle.java:96)

at encry.ReadIniFile.ReadFile(ReadIniFile.java:21)

at encry.ReadIniFile.main(ReadIniFile.java:49)

Exception in thread "main"




wojue() :什么意思,怎么改???
wojue 2002-12-16
  • 打赏
  • 举报
回复
是不是**** ClassLoader classloader = getClass().getClassLoader();這句話不對.沒有將一個handle指向創建的對象,沒有實例化
liujuntao 2002-12-16
  • 打赏
  • 举报
回复
把错误提示,贴出来!
zmrljl 2002-12-16
  • 打赏
  • 举报
回复
调通了,但是还不知是为什么???


改动部分:
InputStream is=getClass().getResourceAsStream("D://ConnectionPool.ini");
PropertyResourceBundle resource =new PropertyResourceBundle(is);

不要这句
ClassLoader classloader = getClass().getClassLoader();
zmrljl 2002-12-16
  • 打赏
  • 举报
回复
但是我已经指定路径了,而且这个文件在此目录下是存在的。
alphazhao 2002-12-16
  • 打赏
  • 举报
回复
Parameters:name - the resource name
Returns:an input stream for reading the resource, or null if the resource could not be found
zmrljl 2002-12-16
  • 打赏
  • 举报
回复
没人答吗???
zmrljl 2002-12-16
  • 打赏
  • 举报
回复
漠名奇妙,怎么会返回null呢?

62,616

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧