2011-03-16 2 views
1

안녕
자바로 프로그램을 작성했습니다.
프로그램의 일부에서는 웹 페이지에서 문자열 번호를 추출하여 정수로 변환합니다. 이것은 문제없이 리눅스에서 작동합니다. Netbeans의 Run/Debug 옵션에서 프로그램을 실행하면 Windows에서 제대로 작동합니다.
하지만 Windows에서 실행하면 JRE가 작동하지 않습니다! (해당 번호를 잘못 추출합니다).Windows에서 실행되는 자바 프로그램의 문제점 JRE

subcatPagesCount=0; 
subcatPagesCount=Integer.parseInt(cutstring(CM.getResult(),"(صفحه 1 از ",")").trim()); 
lblPagesCount.setText(""+subcatPagesCount); 

와 "cutstring"방법은 다음과 같습니다 :

private String cutstring(String in,String from,String to){ 
    int st=in.indexOf(from)+from.length(); 
    return in.substring(st,in.indexOf(to,st)); 
} 

이 예외 :

java.lang.NumberFormatException: For input string: "tml PUBLIC "-//W3C//DTD XHTM 
L 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd 
"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Typ 
e" content="text/html;charset=UTF-8" /><title>کامپیوتر :: کامپیوت 
ر و قطعات - istgah.com </title><meta name="keywords" content=",istgah,ا 
یستگاه,نیازمندیها , آگهی , تبلیغات , ایران" /><m 
eta name="description" content="┌⌐╪º┘à┘╛█î┘ê╪¬╪▒ :: ┌⌐╪º┘à┘╛█î┘ê╪¬╪▒ ┘ê ┘é╪╖╪╣╪ 
º╪¬ - istgah.com" /><base href="http://www.istgah.com/" /><link rel="stylesheet" 
type="text/css" href="layout/templates/istblue/css/firev4.css" /><link rel="sty 
lesheet" type="text/css" href="layout/templates/istblue/css/style2.css" /></head 
><body> <div style="width:980px; float:right; " dir="rtl" > <div style="widt 
h:213px; height:89px; float:right; " dir="rtl" >   <a href="http://www.is 
tgah.com/" >  <img border="0" alt="istgah.com" width="213" height="39" ali 
gn="top" src="layout/blue/hr_top_right.gif" />  <img border="0" alt="istgah. 
com" width="187" height="50" align="top" src="layout/blue/hr_top_right2.gif" /> 
    </a> <div style="display:none;">  <img border="0" alt="" width="0" hei 
ght="0" align="top" src="layout/blue/hr_top_right_back.gif" /> </div> 
</div> <div align="right" style="width:767px; height:39px; float:left; backgr 
ound-image:url(layout/blue/hr_top_right_back.gif); " dir="rtl" > 
<div style="width:360px; float:right; padding-top:17px; " >    <a hre 
f="http://www.istgah.com">╪╡┘?╪¡┘ç ╪º╪╡┘ä┘è</a> |     <a href="http: 
//www.istgah.com/province/">استانها</a> |     <a href="http: 
//www.istgah.com/advertise/">نسخه قديم</a> |    <a href="http: 
//www.istgah.com/user/">ثبت‌نام</a> |    <a href="http://www.is 
tgah.com/contactus/">تماس باما</a>    </div>   <div ali 
gn="left" style="width:90px; float:right; padding-top:17px; " >   <font 
color="blue" > </font>   </div>   <div align="left" style="width:3 
00px; float:right; padding-top:17px; " >      ╪º┘à╪▒┘ê╪▓: ΓǬ┌ 
å┘ç╪º╪▒╪┤┘å╪¿┘ç╪î █▓█╡ ╪º╪│┘?┘å╪» █▒█│█╕█╣ΓǼ   </div> </div> <div a 
lign="right" style="width:767px; height:50px; float:left; " dir="rtl" > 
<div style="width:260px; float:right; padding-top:20px; " >    <form 
action="http://www.istgah.com/search/ " method="get">     جستج 
و:      <input name="stext" class="inputbox" size="25" /> 
       <input type="image" src="layout/go.gif" align="top" /> 
    </form>    </div>   <div style="width:500px; float:right; " 
>     <table border="0" width="500px" cellspacing="0" class="mc" dir 
="rtl" > <tr> <td> <a href="http://www.istgah.com/fireview/computer/"> 

..... 

http://www.istgah.com/firekeys/key_3551/" > samsung</a> - <a href="http://www.is 
tgah.com/firekeys/key_136241/" > هارد اکسترنال</a> - <a href="http:/ 
/www.istgah.com/firekeys/key_3066/" > ┘?╪▒┘ê╪┤ ┌⌐╪º┘à┘╛█î┘ê╪¬╪▒</a> - <a href="h 
ttp://www.istgah.com/firekeys/key_1535/" > acer</a> - <a href="http://www.istgah 
.com/firekeys/key_13206/" > رایتر</a> - <a href="http://www.istgah.com/fire 
keys/key_3100/" > ساعت</a> - <a href="http://www.istgah.com/firekeys/key_625 
08/" > مودم adsl</a> - <a href="http://www.istgah.com/firekeys/key_3123/" > 
ضبط</a> - <a href="http://www.istgah.com/firekeys/key_203/" > موبایل</a 
> - <a href="http://www.istgah.com/firekeys/key_1276/" > laptop</a> - <a href="h 
ttp://www.istgah.com/firekeys/key_7199/" > msi</a> - <a href="http://www.istgah. 
com/firekeys/key_2270/" > monitor</a> - <a href="http://www.istgah.com/firekeys/ 
key_321385/" > 5200</a> - <a href="http://www.istgah.com/firekeys/key_807/" > cd 
</a> - <a href="http://www.istgah.com/firekeys/key_1870/" > ups</a> - <a href="h 
ttp://www.istgah.com/firekeys/key_927/" > تلویزیون</a> - <a href="http:/ 
/www.istgah.com/firekeys/key_2079/" > مادربرد</a> - <a href="http://www.i 
stgah.com/firekeys/key_1723/" > sony</a> - <a href="http://www.istgah.com/fireke 
ys/key_532/" > بازی</a> - <a href="http://www.istgah.com/firekeys/key_846/" 
> cool disk</a> - <a href="http://www.istgah.com/firekeys/key_51650/" > ╪º┘ä ╪│█ 
î ╪»█î</a> - <a href="http://www.istgah.com/firekeys/key_51/" > ╪»┘ê╪▒╪¿█î┘å ╪»█ 
î╪¼█î╪¬╪º┘ä</a> - <a href="http://www.istgah.com/firekeys/key_13/" > ┌⌐╪º┘à┘╛█î┘ 
ê╪¬╪▒</a> - <a href="http://www.istgah.com/firekeys/key_1766/" > ╪¿╪º╪¬╪▒█î</a> 
- <a href="http://www.istgah.com/firekeys/key_3454/" > dell</a> - <a href="http: 
//www.istgah.com/firekeys/key_12084/" > mp4</a> - <a href="http://www.istgah.com 
/firekeys/key_3637/" > ram</a> - <a href="http://www.istgah.com/firekeys/key_381 
0/" > کارت کپچر</a> -   <br />  </td></tr>   <tr><t 
d align="center" >   <br />   <form action="http://www.istgah.com/s 
earch/ " method="get">   <b>جستجوگر هوشمند آگهی‌های 
ایستگاه: </b>   <input name="stext" class="inputbox" size="30"/
>    <input type="image" src="layout/go.gif" align="top" />  </for 
m>   <br />   </td></tr> </table>   <div>   <table w 
idth="100%" cellpadding="0" cellspacing="0" class="nls" >    <tr><td 
class="ghd" colspan="3" >تازه‌های کامپیوتر :: کامپیوتر 
┘ê ┘é╪╖╪╣╪º╪¬ (╪╡┘?╪¡┘ç 1 ╪º╪▓ 84" 
     at java.lang.NumberFormatException.forInputString(Unknown Source) 
     at java.lang.Integer.parseInt(Unknown Source) 
     at java.lang.Integer.parseInt(Unknown Source) 
     at istgahrobot.doscan$Scan.run(doscan.java:536) 
     at java.lang.Thread.run(Unknown Source) 

문제가 무엇
이 코드의 일부인가?
감사합니다.

+1

실행 결과는 무엇입니까? – justkt

+0

"parseInt"가 파싱 할 수 없으므로 그 번호 이외의 html 페이지의 "cutstring"추출 된 부분을 "java.lang.NumberFormatException"예외로 throw합니다! – RYN

+0

@Snigger -'from' 및'to' 인수는 무엇입니까? 그리고 좋은 측정을위한 당신의'안에'? – justkt

답변

3

유니 코드를 켜고 JRE를 실행하지 않았을 수 있습니다.

-Dfile.encoding=UTF8 

을 또는 JAVA_TOOL_OPTIONS environment variable-Dfile.encoding=UTF8에 설정하십시오 file.encoding 옵션을 사용하여 코드를 실행 해보십시오.

자세한 내용은 Setting the default Java character encoding?을 참조하십시오.

+0

고맙습니다. 문제를 해결했습니다. – RYN

+1

@Snigger -'file.encoding' 옵션을 설정하면 코드가 실행되는 방식이 바뀌므로 다른 버그가 있음을 의미합니다. 코드에서 명시 적으로 문자 인코딩을 지정하지 않은 곳에서'InputStreamReader'의 사용법을 확인하십시오. 'file.encoding' 변경은 지원되지 않으며 다른 문제가 발생할 수 있습니다 : http://bugs.sun.com/view_bug.do?bug_id=4163515 – McDowell

관련 문제