Android:拆分功能不起作用
我在代码中收到强制关闭消息。有人可以向我解释一下为什么我会收到这个结果吗?
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.split("/");
while( x < values.length ){
tv.append("\n" + x + ":> " + values[x]);
x++;
}
setContentView(tv);
}
}
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.split("/");
while( x < values.length ){
tv.append("\n" + x + ":> " + values[x]);
x++;
}
setContentView(tv);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要增加 x,否则它是一个无限循环:
或
You need to increment x, otherwise it's an infinite loop:
or
在这种情况下,建议发布完整的错误日志,因为“强制关闭”是非常不具体的。但是,您有一个无限的 while 循环。
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.您将陷入无限循环,因为您错过了在代码中增加 x 。
You're getting a infinite loop, because you missed to increment x in your code.