Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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ѧϰÍøÕ¾
Java´úÂë²éѯվµã S+\s4hh@k  
1. java2s http://www.java2s.com/ PeYmf1ox  
Õâ¸öÍøÕ¾·Ç³£ºÃ£¬·Ö³ÉÈý´óÀ࣬·Ö±ðÊÇExample¡¢Products¡¢ Articles£¬Ã¿¸ö´óÀàÏÂÓÖ·Ö±ðÉèÐí¶àСÀ࣬»¹ÓÐËÑË÷¹¦ÄÜ£¬ÕâÑù²éÕÒÆðÀ´·Ç³£·½±ã¡£¡£±ÈÈ磬Èç¹ûҪѧϰSWT/JFace£¬Ö»Òª°ÑExampleϵÄSWT JFace Eclipse ......

Java IO InputStreamReader

      ºÜ¶àµÄÎı¾Îļþ»áÓв»Í¬µÄ±àÂë¸ñʽ£¬Ôì³ÉÕâÖÖ±àÂë²îÒìµÄ¿ÉÄÜÊÇϵͳµÄ²îÒ죬¿ÉÄÜÊÇÔÚ±£´æÎļþʱ²ÉÓÃÌض¨µÄ×Ö·û¼¯±àÂëÀ´±£´æ¡£ÕâʱÎÒÃÇÀûÓÃJavaÓïÑÔÀ´´ò¿ªÕâЩÎı¾Ê±£¬Èç¹û²»Ê¹ÓÃÕýÈ·µÄ×Ö·û¼¯½âÂëÆ÷´ò¿ª£¬¿Ï¶¨»á³öÏÖÂÒÂë¡£ºÃÔÚjava.io°üÌṩÁËÒ»¸öjava.io.InputStreamReaderÀàÀ´Ö§³ÖÖ¸¶¨Îı¾× ......

JavaÃæÊÔ±ÊÊÔÌâ´ó»ã×Ü(Ò»)

µÚÒ»£¬Ì¸Ì¸final, finally, finalizeµÄÇø±ð¡£
¡¡¡¡×î³£±»Îʵ½¡£¡¡¡¡
¡¡¡¡µÚ¶þ£¬Anonymous Inner Class (ÄäÃûÄÚ²¿Àà) ÊÇ·ñ¿ÉÒÔextends(¼Ì³Ð)ÆäËüÀ࣬ÊÇ·ñ¿ÉÒÔimplements(ʵÏÖ)interface(½Ó¿Ú)?¡¡¡¡
¡¡¡¡µÚÈý£¬Static Nested Class ºÍ Inner ClassµÄ²»Í¬£¬ËµµÃÔ½¶àÔ½ºÃ(ÃæÊÔÌâÓеĺÜÁýͳ)¡£¡¡¡¡
¡¡¡¡µÚËÄ£¬&ºÍ&am ......

JavaÓïÑÔ»ù´¡ÖªÊ¶

JavaÓïÑÔ»ù´¡ÖªÊ¶
³ÌÐòÔ±¶Ô³ÌÐòÖеĸ÷¸öÔªËؼÓÒÔÃüÃûʱʹÓõÄÃüÃû¼ÇºÅ³ÆΪ±êʶ·û£¨identifier£©¡£
JavaÓïÑÔÖУ¬±êʶ·ûÊÇÒÔ×Öĸ£¬Ï»®Ïߣ¨_£©,ÃÀÔª·û($)¿ªÊ¼µÄÒ»¸ö×Ö·ûÐòÁУ¬ºóÃæ¿ÉÒÔ¸ú×Öĸ£¬Ï»®Ïߣ¬ÃÀÔª·û£¬Êý×Ö¡£
ÀýÈ磬identifier£¬userName£¬User_Name£¬_sys_val£¬ $changeΪºÏ·¨µÄ±êʶ·û£¬¶ø2mail room#£¬class Ϊ· ......

javaÅжÏ×ÓÍøÑÚÂë

String[] ips = ipValue.split("\\.");
String binaryVal = "";
for (int i = 0; i < ips.length; i++)
{
String binaryStr = Integer.toBinaryString(Integer.parseInt(ips[i]));


Integer times = 8 - binaryStr.length();
......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ