简体   繁体   English

我刚开始使用android,但在使用reverseWord方法时遇到了麻烦

[英]I just started using android and am having trouble with a reverseWord method

I made a method reverseWord that is supposed to reverse an inputted word and display it. 我做了一个方法reverseWord ,它应该反转输入的单词并显示它。

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);

}

The method works fine until I output the string word or text . 该方法可以正常工作,直到我输出字符串wordtext为止。 Other test outputs work, but when I try to output word or text it crashes. 其他测试输出也可以,但是当我尝试输出wordtext会崩溃。 I think it isn't receiving the input correctly, but I am really not sure. 我认为它没有正确接收输入,但是我不确定。

This is probably a relatively easy fix, so any help would be appreciated. 这可能是一个相对容易的修复,因此将不胜感激。 If you need anymore information to help me, please do not hesitate. 如果您需要其他信息来帮助我,请不要犹豫。

I did not test it all, but your way of reversing the String did not work for me. 我没有全部测试,但是您反转String的方式对我不起作用。

For me this reversed the String and printed it. 对我来说,这将字符串反转并打印出来。

String text = "hello";
String reverse = new StringBuffer(text).reverse().toString();
System.out.println(reverse);

if you put that in your code, it should work 如果您将其放在代码中,它应该可以工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 条件和循环反转我错过了什么? - Conditionals and Loops reverseword what am I missing? 我无法在 Java 中调用我的 output 方法 - I am having trouble calling my output method in Java 我在调用Java中的静态递归方法时遇到麻烦 - I am having trouble calling upon a static recursive method in Java 我无法在 android 上运行我的计算器应用程序 - I am having trouble with running my calculator app on android 我在使用android studio在java中设置TextVIew时遇到了麻烦 - I am having trouble of setting my TextVIew in java using android studio 我在Android应用中制作插页式广告时遇到问题 - I am having trouble creating an Interstitial ad in my android app 我在使用JOptionPane的if / else语句时遇到问题? - I am having trouble with if/else statement using JOptionPane? 我在使用 jdk 动态代理时遇到问题 - I am having trouble in using jdk dynamic proxy 我在快速排序中使用中位数和均值作为 pivot 时遇到问题 - I am having trouble with using Median and Mean as pivot in Quicksort 嘿,我才刚开始在android中进行编码并收到错误Permission Denial:不允许在android中发送广播 - Hey , I am just started to code in android and getting error Permission Denial: not allowed to send broadcast in android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM