方法抛出NumberFormatException异常,但它不应该这样做,到目前为止一直正常工作。

3

我似乎无法弄清楚为什么在将整数转换为字符串时会抛出NFE错误。

[代码]

 public void setCurrentTransferRate(){
    try{
        long startTime = System.currentTimeMillis();  
        String[] command = {"/bin/sh", "-c", "ifconfig " + interface_name + " | grep -oP     'RX bytes:[0-9]{1,11}'"};
        String[] command1 = {"/bin/sh", "-c", "ifconfig " + interface_name + " | grep -oP 'TX bytes:[0-9]{1,11}'"};
        Process child = Runtime.getRuntime().exec(command);
        Process child1 = Runtime.getRuntime().exec(command1);
        BufferedReader r = new BufferedReader(new InputStreamReader(child.getInputStream()));       //i prwti metrisi twn RX kai TX bytes
        BufferedReader r1 = new BufferedReader(new InputStreamReader(child1.getInputStream()));
        String temp = r.readLine();
        temp = temp.replace("RX bytes:","");   
        String temp1 = r1.readLine();
        temp1 = temp1.replace("TX bytes:","");  
        r.close();              
        r1.close();
        int x = Integer.parseInt(temp);         
        int y = Integer.parseInt(temp1); 
    }catch(IOException e){e.printStackTrace();}        
    catch(InterruptedException e){e.printStackTrace();}
   }[/code]

产生错误的字符串是temp。

我收到了以下错误:

[代码]

 Exception in thread "Thread-0" java.lang.NumberFormatException: For input string:  "3262469144"
  at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
  at java.lang.Integer.parseInt(Integer.java:495)
  at java.lang.Integer.parseInt(Integer.java:527)
  at askisi1.General.setCurrentTransferRate(General.java:187)
  at askisi1.General.<init>(General.java:27) 
  at askisi1.mainThread.run(mainThread.java:17)
  at java.lang.Thread.run(Thread.java:722)[/code]

我需要在这方面得到一双新鲜的眼睛。

天啊,这太容易了...我感到很愚蠢没有注意到它,但我想连续编码几个小时确实会有影响... - Stelios Savva
2个回答

9

4

3262469144对于int类型来说太大了!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接