开发者

Android: Split function not working

开发者 https://www.devze.com 2023-03-06 00:11 出处:网络
I\'m getting a force close message here in my code. Can somebody please explain to me why I am receiving this result.

I'm getting a force close message here in my code. Can somebody please explain to me why I am receiving this result.

package com.example.splitfunction;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class SplitFunction extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TextView tv = new TextView(this);
        String url = "http://mysub.somedomain.com/tabletcms/tablets/youcontent/000002/thumbnails/110/png";
        String[] values;
        int x = 0;

        tv.setText("SPLIT FUNCTION PROGRAM...\n");
        tv.append(url);

        values = url.spli开发者_如何学JAVAt("/");

        while( x < values.length ){
            tv.append("\n" + x + ":> " + values[x]);
            x++;
        }

        setContentView(tv);
    }
}


You need to increment x, otherwise it's an infinite loop:

tv.append("\n" + x + ":> " + values[x++]);

or

    while( x < values.length ){
        tv.append("\n" + x + ":> " + values[x]);
        x++
    }


It would be advisable to post a complete error log in such a case, as it is extremely unspecific "to have a force close". However, you have an infinite while-loop. The value of x is never incremented.


You're getting a infinite loop, because you missed to increment x in your code.

0

精彩评论

暂无评论...
验证码 换一张
取 消