Шифр Цезаря не отображается в TextView

Есть задача: пользователь вводит слово и мне нужно зашифровать его шифром Цезаря. Для ввода слова предназначен EditText. Отсюда нужно взять слово, которое вводит пользователь, и при нажатии на кнопку нужно отобразить зашифрованное слово в TextView. Но когда дело доходит до вывода textOut1.setText(symbol_right_shift(word.charAt(j), i)); приложение вылетает. Я думаю, проблема в том, что TextView не подходит для всех возможных вариантов шифрования. Но я сделал TextView прокручиваемым. Возможно, у вас есть другие идеи по реализации шифра? нужно очень срочно

XML Code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

   
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="60dp"
        android:paddingTop="150dp"
        android:text="Введите слово для шифрования"
        android:textSize="20sp" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPersonName"
        android:text="Слово" />

    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Зашифровать"
        android:onClick="Encryption"/>

    <TextView
        android:id="@+id/textOut1"
        android:layout_width="match_parent"
        android:layout_height="579dp"
        android:maxLines="5000"
        android:scrollbars="vertical"
        android:text="Зашифрованное слово"
        android:textSize="20sp" />


</LinearLayout>

Main.java code

package com.example.lab5mob;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import java.util.Locale;
import java.util.Scanner;

public class MainActivity extends AppCompatActivity {

EditText editText1;
Button button1;
TextView textOut1;
    static final String alphabet = "abcdefghijklmnopqrstuvwxyz";

    public static char symbol_right_shift(char symbol, int shift){

       if (alphabet.indexOf(symbol) != -1){
        return alphabet.charAt((alphabet.indexOf(symbol) + shift) % alphabet.length());

       }
       else{
           return symbol;
       }

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        editText1 = (EditText) findViewById(R.id.editText1);
        button1 = (Button) findViewById(R.id.button1);
        textOut1 = (TextView) findViewById(R.id.textOut1);
        textOut1.setMovementMethod(new ScrollingMovementMethod());
    }


    public void Encryption(View view) {
        String word = editText1.getText().toString(); //read value from EditText
        word = word.toLowerCase();

         for(int i=0; i <= 26; ++i) {
         for (int j=0; j<word.length(); j++){
             textOut1.setText(symbol_right_shift(word.charAt(j), i));//display this text in a TextView
         }
          textOut1.setText("\n");
        }
    }

}

Ответы (0 шт):