Java 我刚开始使用安卓系统,在使用reverseWord方法时遇到了麻烦
我制作了一个方法Java 我刚开始使用安卓系统,在使用reverseWord方法时遇到了麻烦,java,android,Java,Android,我制作了一个方法reverseeword,该方法可以反转输入的单词并显示它 public void reverseEncrypt(View v) { // Get the input EditText input = (EditText) findViewById(R.id.editText); TextView output = (TextView) findViewById(R.id.tv_result); TextView output2 = (T
reverseeword
,该方法可以反转输入的单词并显示它
public void reverseEncrypt(View v)
{
// Get the input
EditText input = (EditText) findViewById(R.id.editText);
TextView output = (TextView) findViewById(R.id.tv_result);
TextView output2 = (TextView) findViewById(R.id.tv_test);
output2.setText("Test is complete");
// Reverse word
String text = input.getText().toString();
String word = " ";
for (int i = text.length(); i > 0; i--)
{
word += text.substring(i,i-1);
}
output2.setText(text);
// Output result
output.setText("Result: " + word);
}
在我输出字符串word
或text
之前,该方法工作正常。其他测试输出工作正常,但当我试图输出word
或text
时,它崩溃了。我认为它没有正确接收输入,但我真的不确定
这可能是一个相对容易的解决方案,因此任何帮助都将不胜感激。如果您需要更多信息来帮助我,请不要犹豫 我并没有全部测试,但你颠倒字符串的方法对我不起作用 对我来说,这倒过来的字符串和打印它
String text = "hello";
String reverse = new StringBuffer(text).reverse().toString();
System.out.println(reverse);
如果你把它放在你的代码中,它应该可以工作为什么不给我们看崩溃日志呢?请…Android Studio应该在控制台中有崩溃日志。。。假设手机连接时应用程序崩溃。同时在问题中发布日志查看日志。Android将所有内容都记录到这个日志中。Android Studio支持显示你的logcat日志谢谢你,善良的陌生人。我不知道有反向方法或StringBuffer类。