是不是****     ClassLoader classloader = getClass().getClassLoader();這句話不對.沒有將一個handle指向創建的對象,沒有實例化

解决方案 »

  1.   

    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() :什么意思,怎么改???
      

  2.   

    PropertyResourceBundle resource =new PropertyResourceBundle(classloader.getResourceAsStream("D://ConnectionPool.ini"));
    是这句的问题拉
    你classloader.getResourceAsStream("D://ConnectionPool.ini")返回的是一个为null的InputStream对象,所以会造成空指针错误……
      

  3.   

    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();
      }
      

  4.   

    同意楼上的意见,其实,你可以
     ClassLoader classloader = getClass().getClassLoader();
           System.out.println("Hello");
           PropertyResourceBundle resource =new PropertyResourceBundle(classloader.getResourceAsStream("D://ConnectionPool.ini"));
           System.out.println("bye");
    然后,就知道,是那句话出现问题了的!
      

  5.   

    那就说明程序没找到ConnectionPool.ini文件???
      

  6.   

    漠名奇妙,怎么会返回null呢?
      

  7.   

    Parameters:name - the resource name
    Returns:an input stream for reading the resource, or null if the resource could not be found
      

  8.   

    调通了,但是还不知是为什么???
    改动部分:
     InputStream is=getClass().getResourceAsStream("D://ConnectionPool.ini");
           PropertyResourceBundle resource =new PropertyResourceBundle(is);不要这句
    ClassLoader classloader = getClass().getClassLoader();