Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

Java¾²Ì¬±äÁ¿ÒÔ¼°·Ç±ê×¼µ¥Ì¬Ä£Ê½µÄ¿Ó

½ñÌìÓöµ½Ò»¸öºÜ¹îÒìµÄbug£¬µ÷ÊÔÁË°ëÌìҲûÓп´³öÀ´ÓÐʲôÎÊÌ⣬³éÏóһϴúÂëÈçÏ£º
public class Instance
{

public static Instance instance = new Instance();

public static Map<String, String> map = new HashMap<String, String>();

public static Instance instance()
{

return Instance.instance;
}

public static void main(String[] args)
{
Instance.instance().test();
}
public Instance()
{
Instance.map.put("abc", "def");
}

public void test()
{

System.out.println("test called");
}
}

½á¹ûÒ»ÔËÐоͳöÏÂÃæµÄ´íÎó£¬
java.lang.ExceptionInInitializerError
Caused by: java.lang.NullPointerException
 at edu.bupt.test.Instance.<init>(Instance.java:27)
 at edu.bupt.test.Instance.<clinit>(Instance.java:9)
Exception in thread "main"
µ±Ê±Ã»ÓÐ̫עÒâÕâ¸öException£¬ÒòΪ»¹ÓÐÁíÍâÒ»¸öNullException
ºóÀ´×Ðϸ¿´ÁËһ϶ÑÕ»²Å·¢ÏÖ£¬ÕâÊÇÔÚ³õʼ»¯µÄ¹ý³ÌÖгöµÄÎÊÌ⣬
Ê×ÏÈÎÒÃÇÀ´»ØÒäÒ»ÏÂÀàµÄ¼ÓÔعý³Ì
1¡¢¼ÓÔØÀàÎļþ
2¡¢³õÔظ¸Àà
3¡¢³õʼ»¯¾²Ì¬±äÁ¿ºÍstatic´úÂë¿é
4¡¢µ÷Óù¹Ô캯Êý
ºÃÁË£¬ÎÊÌâ¾Í³öÔÚµÚ3²½ÁË£¬ÒòΪÕâÀïÎÒÃÇÓÃÁËÒ»¸ö·Ç±ê×¼µÄµ¥Ì¬Ä£Ê½£¬
Ö±½Ó°Ñ¾²Ì¬±äÁ¿ÔÚstaticÀï³õʼ»¯ÁË¡£ÓÉÓÚµÚÈý²½µÄ³õʼ»¯²½ÖèÊǸù¾ÝÄã
µÄ±äÁ¿µÄ¶¨Òå˳ÐòÀ´³õʼ»¯µÄ£¬ÓÚÊDZ­¾ß²úÉúÁË£º
Ê×ÏÈ£¬ÄãÒª³õʼ»¯static Instance instance£¬ÕâÑùÄã¾ÍÒªµ÷ÓÃInstance
µÄ¹¹Ô캯Êý£¬Õâ¸öʱºò£¬¹¹Ô캯ÊýÀïÒª·ÃÎÊmap±äÁ¿£¬¶øÕâ¸östatic±äÁ¿
»¹Ã»Óгõʼ»¯ÄØ£¬ÓÚÊÇ¿ÕÖ¸Õë¾Í³öÏÖÁË¡£
½áÂÛ£ºÒª×ÐϸÔĶÁÕ»µÄ»°£¬Õâ¸öÎÊÌ⻹ÊǺÜÈÝÒ׶¨Î»µÄ£¬Õâô¿´init´ú±í¹¹Ô캯Êý
¶øcinit´ú±í¾²Ì¬³õʼ»¯º¯Êý£¬Òò´ËÕâ¸ö¹ý³ÌÆäʵÊÇÔÚ¾²Ì¬³õʼ»¯µ÷Óù¹Ô캯Êýʱ
·¢ÉúµÄ£¬È¥¿´Ò»¸ö¹¹Ô캯Êý·ÖÎöһϾ͵õ½½á¹ûÁË¡£
ÁíÍ⾡¿ÉÄܱÜÃâµØʹÓÃÔÚ±äÁ¿¶¨Òåʱ¾Í³õʼ»¯±äÁ¿£¬ÕâÑù»áµ¼ÖÂһЩÎÊÌâµÄ×·²é
±È½ÏÂé·³£¬±ÈÈçÕâ¸öÎÊÌâ¾ÍÊÇÒ»¸öºÜµäÐ͵ÄÀý×Ó£¬½â¾öÎÊÌâµÄ°ì·¨¾ÓÈ»ÊÇÒª½«Á½¸ö
±äÁ¿¶¨Òå˳Ðòµ÷Õûһϣ¬Èç¹ûʹÓÃÁËһЩ´úÂëformat¹¤¾ß£¬±ÈÈçeclipseµÄformat¹¦ÄÜ£¬
ÕâÖÖ¹îÒìµÄbug¾Í»á³öÏÖÁË¡£


Ïà¹ØÎĵµ£º

Java¼¯ºÏ¿ò¼Üͼ


Java¼¯ºÏ¿ò¼Üͼ
¡¡¡¡¼¯ºÏ½Ó¿Ú£º6¸ö½Ó¿Ú£¨¶ÌÐéÏß±íʾ£©£¬±íʾ²»Í¬¼¯ºÏÀàÐÍ£¬ÊǼ¯ºÏ¿ò¼ÜµÄ»ù´¡¡£
¡¡¡¡³éÏóÀࣺ5¸ö³éÏóÀࣨ³¤ÐéÏß±íʾ£©£¬¶Ô¼¯ºÏ½Ó¿ÚµÄ²¿·ÖʵÏÖ¡£¿ÉÀ©Õ¹Îª×Ô¶¨Ò弯ºÏÀà¡£
¡¡¡¡ÊµÏÖÀࣺ8¸öʵÏÖÀࣨʵÏß±íʾ£©£¬¶Ô½Ó¿ÚµÄ¾ßÌåʵÏÖ¡£
¡¡¡¡Ôںܴó³Ì¶ÈÉÏ£¬Ò»µ©ÄúÀí½âÁ˽ӿڣ¬Äú¾ÍÀí½âÁË¿ò¼Ü¡£ËäÈ»Äú×ÜÒª´´½ ......

ÈçºÎÓ¦ÓÃJavaµÄBigDecimalÀà

±¾ÎĽéÉÜJavaµÄBigDecimalÀàµÄÓ¦Óá£JavaÔÚjava.math°üÖÐÌṩµÄAPIÀàBigDecimal£¬ÓÃÀ´¶Ô³¬¹ý16λÓÐЧλµÄÊý½øÐо«È·µÄÔËËã¡£
BigDecimalÀà
Ë«¾«¶È¸¡µãÐͱäÁ¿double¿ÉÒÔ´¦Àí16λÓÐЧÊý¡£ÔÚʵ¼ÊÓ¦ÓÃÖУ¬ÐèÒª¶Ô¸ü´ó»òÕ߸üСµÄÊý½øÐÐÔËËãºÍ´¦Àí¡£JavaÔÚjava.math°üÖÐÌṩµÄAPIÀàBigDecimal£¬ÓÃÀ´¶Ô³¬¹ý16λÓÐЧλµÄÊý½øÐо«È· ......

java ½âѹËõzipÎļþ

²âÊÔ»·¾³£ºwin2000+jdk1.4+jb2006
 import java.io.*;
import java.util.Enumeration;
//import java.util.zip.*;
import org.apache.tools.zip.*;
public class Test {
//½âѹÎļþ
  public static void extZipFileList(String zipFileName, String extPlace) {
    try {
   ......

Java»ñÈ¡ÇëÇó¿Í»§¶ËµÄÕæʵIPµØÖ·

ͨ³£Í¨¹ýrequest.getRemoteAddr()
È¡µÃ¿Í»§¶ËµÄIPµØÖ·£¬×ö¼øȨºÍУÑ飬Âß¼­Ã»ÎÊÌ⣬ÄÇô¿Ï¶¨request.getRemoteAddr()³öÁËÎÊÌ⣬googleÏ£¬·¢ÏÖÓÐÈËÓöµ½ÀàËƵÄÎÊÌâ¡£
×îÖÕ¶¨Î»Îªrequest.getRemoteAddr()ÕâÖÖ·½·¨Ôڴ󲿷ÖÇé¿ö϶¼ÊÇÓÐЧµÄ¡£µ«ÊÇÔÚͨ¹ýÁËApache,SquidµÈ·´Ïò´úÀíÈí¼þ¾Í²»ÄÜ»ñÈ¡µ½¿Í»§¶ËµÄÕæʵIPµØÖ·ÁË¡£
......

JAVA¼¸¸ö³£¼û´íÎó¼òÎö

1£¬¿ÕÖ¸Õë´íÎó java.lang.NullPointerException
ʹÓûù±¾µÄJAVAÊý¾ÝÀàÐÍ£¬±äÁ¿µÄֵҪôÒѾ­ÊÇĬÈÏÖµ£¬Èç¹ûûÓжÔÆäÕý³£¸³Öµ£¬³ÌÐò±ã²»ÄÜͨ¹ý±àÒ룬Òò´ËʹÓûù±¾µÄJAVAÊý¾ÝÀàÐÍ
(double,float,boolean,char,int,long)Ò»°ã²»»áÒýÆð¿ÕÖ¸ÕëÒì³£¡£Óɴ˿ɼû£¬¿ÕÖ¸ÕëÒì³£Ö÷Òª¸úÓë¶ÔÏóµÄ²Ù×÷Ïà¹Ø¡£
ÏÂÃæÏÈÁгöÁË¿ÉÄÜ·¢Éú¿ÕÖ¸Õ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ