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.
精彩评论