通过拆分将数组转换为整数

时间:2016-04-15 15:49:13

标签: java android

我收到错误:

FATAL EXCEPTION:主要在java.lang.Integer.invalidInt

这个块:

int f = Integer.parseInt(c[1]); 
limitter.setProgress(f); 
limit.setText(f + " A");

主要代码:

byte[] encodedBytes = new byte[readBufferPosition];
System.arraycopy(readBuffer, 0, encodedBytes, 0, encodedBytes.length);
final String data = new String(encodedBytes, "US-ASCII");

readBufferPosition = 0;

handler.post(new Runnable()
{
    public void run()
    {
        String[] c = data.split("limit");
        int x = c.length;

        if(x>1){

            int f = Integer.parseInt(c[1]);
            limitter.setProgress(f);
            limit.setText(f + " A");
        }

有什么问题?

这是堆栈跟踪:

FATAL EXCEPTION: main
   at java.lang.Integer.invalidInt(Integer.java:138)
   at java.lang.Integer.parse(Integer.java:375)
   at java.lang.Integer.parseInt(Integer.java:366)
   at java.lang.Integer.parseInt(Integer.java:332)
   at com.tos.hidro.Terminal$2$1.run(Terminal.java:207)
   at android.os.Handler.handleCallback(Handler.java:608)
   at android.os.Handler.dispatchMessage(Handler.java:92)
   at android.os.Looper.loop(Looper.java:156)
   at android.app.ActivityThread.main(ActivityThread.java:4987)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
   at dalvik.system.NativeStart.main(Native Method)

0 个答案:

没有答案