你好
我用java写了一个程序。
在程序的一部分中,它从网页中提取一个字符串数字并将其转换为整数。
这在 linux 中没有问题。
在 Windows 中,当我从 Netbeans 的运行/调试选项运行程序时,它可以正常工作;
但是当我从 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)
有什么问题?
谢谢
最佳答案
您可能没有在启用 Unicode 的情况下运行 JRE。尝试使用 file.encoding 选项运行您的代码:
-Dfile.encoding=UTF8
或者设置JAVA_TOOL_OPTIONS environment variable到 -Dfile.encoding=UTF8。
关于java - 在Windows JRE中运行时java程序中的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5329619/
总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
我试图在一个项目中使用rake,如果我把所有东西都放到Rakefile中,它会很大并且很难读取/找到东西,所以我试着将每个命名空间放在lib/rake中它自己的文件中,我添加了这个到我的rake文件的顶部:Dir['#{File.dirname(__FILE__)}/lib/rake/*.rake'].map{|f|requiref}它加载文件没问题,但没有任务。我现在只有一个.rake文件作为测试,名为“servers.rake”,它看起来像这样:namespace:serverdotask:testdoputs"test"endend所以当我运行rakeserver:testid时
作为我的Rails应用程序的一部分,我编写了一个小导入程序,它从我们的LDAP系统中吸取数据并将其塞入一个用户表中。不幸的是,与LDAP相关的代码在遍历我们的32K用户时泄漏了大量内存,我一直无法弄清楚如何解决这个问题。这个问题似乎在某种程度上与LDAP库有关,因为当我删除对LDAP内容的调用时,内存使用情况会很好地稳定下来。此外,不断增加的对象是Net::BER::BerIdentifiedString和Net::BER::BerIdentifiedArray,它们都是LDAP库的一部分。当我运行导入时,内存使用量最终达到超过1GB的峰值。如果问题存在,我需要找到一些方法来更正我的代
我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0
Rails2.3可以选择随时使用RouteSet#add_configuration_file添加更多路由。是否可以在Rails3项目中做同样的事情? 最佳答案 在config/application.rb中:config.paths.config.routes在Rails3.2(也可能是Rails3.1)中,使用:config.paths["config/routes"] 关于ruby-on-rails-Rails3中的多个路由文件,我们在StackOverflow上找到一个类似的问题
我想为Heroku构建一个Rails3应用程序。他们使用Postgres作为他们的数据库,所以我通过MacPorts安装了postgres9.0。现在我需要一个postgresgem并且共识是出于性能原因你想要pggem。但是我对我得到的错误感到非常困惑当我尝试在rvm下通过geminstall安装pg时。我已经非常明确地指定了所有postgres目录的位置可以找到但仍然无法完成安装:$envARCHFLAGS='-archx86_64'geminstallpg--\--with-pg-config=/opt/local/var/db/postgresql90/defaultdb/po
尝试通过RVM将RubyGems升级到版本1.8.10并出现此错误:$rvmrubygemslatestRemovingoldRubygemsfiles...Installingrubygems-1.8.10forruby-1.9.2-p180...ERROR:Errorrunning'GEM_PATH="/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/ruby-1.9.2-p180@global:/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/rub
Rackup通过Rack的默认处理程序成功运行任何Rack应用程序。例如:classRackAppdefcall(environment)['200',{'Content-Type'=>'text/html'},["Helloworld"]]endendrunRackApp.new但是当最后一行更改为使用Rack的内置CGI处理程序时,rackup给出“NoMethodErrorat/undefinedmethod`call'fornil:NilClass”:Rack::Handler::CGI.runRackApp.newRack的其他内置处理程序也提出了同样的反对意见。例如Rack
我需要从一个View访问多个模型。以前,我的links_controller仅用于提供以不同方式排序的链接资源。现在我想包括一个部分(我假设)显示按分数排序的顶级用户(@users=User.all.sort_by(&:score))我知道我可以将此代码插入每个链接操作并从View访问它,但这似乎不是“ruby方式”,我将需要在不久的将来访问更多模型。这可能会变得很脏,是否有针对这种情况的任何技术?注意事项:我认为我的应用程序正朝着单一格式和动态页面内容的方向发展,本质上是一个典型的网络应用程序。我知道before_filter但考虑到我希望应用程序进入的方向,这似乎很麻烦。最终从任何
我想用ruby编写一个小的命令行实用程序并将其作为gem分发。我知道安装后,Guard、Sass和Thor等某些gem可以从命令行自行运行。为了让gem像二进制文件一样可用,我需要在我的gemspec中指定什么。 最佳答案 Gem::Specification.newdo|s|...s.executable='name_of_executable'...endhttp://docs.rubygems.org/read/chapter/20 关于ruby-在Ruby中编写命令行实用程序