Java Android:获取生成的变量及其值?

Java Android:获取生成的变量及其值?,java,android,Java,Android,我正在做一个应用程序,加密纯文本,然后通过电子邮件发送。我在“encrypt”方法中创建的cText变量(由用户输入的passT和keyT创建)在方法末尾返回。然而,我很好奇,我将如何将它合并到我的onCreate方法中,以便将其新的加密内容包含到电子邮件中?以下是我所拥有的,但我只得到了错误: public class ScreenNext extends Activity { int key = 0; static char ch; protected void onCreate(Bun

我正在做一个应用程序,加密纯文本,然后通过电子邮件发送。我在“encrypt”方法中创建的
cText
变量(由用户输入的passT和keyT创建)在方法末尾返回。然而,我很好奇,我将如何将它合并到我的onCreate方法中,以便将其新的加密内容包含到电子邮件中?以下是我所拥有的,但我只得到了错误:

public class ScreenNext extends Activity {

int key = 0;
static char ch;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_screen_next)

    EditText emailT;//Import  EditTexts (Key and Email)  
    Button send = (Button) findViewById(R.id.bSend);//Import button1 (Send)
    final EditText passT = (EditText) findViewById(R.id.etTogg);//passT variable for Password Text for EditText field
    final EditText keyT = (EditText) findViewById(R.id.etKey);
    final EditText passT = (EditText) findViewById(R.id.etTogg);//passT variable for Password Text for EditText field

    send.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            String keyText = keyT.getText().toString();
            String passText = passT.getText().toString();
            String EmailAdd = emailT.getText().toString();

            //This must be fixed
            //String cipherText = cText.getText().toString();


            Intent email = new Intent(Intent.ACTION_SEND);//The intent
            email.setType("plain/text");
            email.putExtra(Intent.EXTRA_EMAIL, new String[]{EmailAdd.toString()});
            email.putExtra(Intent.EXTRA_SUBJECT, "Your encrypted Password");//Subject is hard coded for convenience sake
            email.putExtra(Intent.EXTRA_TEXT, cText.toString());//Here we add encrypted Password that has just been generated
            startActivity(email);//Start the activity
        }

    });

}//End onCreate
...
}
以及我的加密方法:

public static String message(String choice, String subKey, String message) {
int Option = Integer.parseInt(choice);//Must pareseInt
int key = Integer.parseInt(subKey);
message = message.toLowerCase();


ScreenNext subcipher_1 = null;
String CipherTxt = subcipher_1.encrypt(message, key);
return CipherTxt;
}


public static String encrypt(String Txt, int key) {

//local var cipherText of type string is init empty
String CipherTxt = "";//May be able to remove this'un 
String cText="";
//enhanced for loop 
// start at 0, go until "as long as input text" 
for (int i = 0; i < Txt.length(); i++) {
    //get a char from the string at index i (start at 0 work through to end of string)
    // and store in local var extractedChar for type char
    char extractedChar = Txt.charAt(i);
    /* enhanced for loop 
     * start at 0, go until end of user entered cipherKeyValue
     * either set to lowercase a or add one to the char
     * uses the checkifz method
     */
    for (int j = 0; j < key; j++) {
        ScreenNext subcipher_1 = null;
        if (subcipher_1.checkIfZ(extractedChar) == true) {
            extractedChar = 'a';
        } else {
            extractedChar++;
        }
        CipherTxt= new StringBuilder().append(extractedChar).toString();
    }
    //add extracted char to builder object
    //change object builder to string and assing to cipherText of type String
    //create new object builder from StringBuilder class
    cText = cText.concat(CipherTxt);
}
//Pass the cipherText value out of the method to whom ever called it

return cText;
}
公共静态字符串消息(字符串选择、字符串子键、字符串消息){
int Option=Integer.parseInt(选项);//必须是pareseInt
int key=Integer.parseInt(子键);
message=message.toLowerCase();
ScreenNext子ipher_1=null;
字符串CipherText=子iPhone_1.加密(消息,密钥);
返回密文;
}
公共静态字符串加密(字符串Txt,整数密钥){
//字符串类型的本地变量密文为init空
字符串CipherText=“;//可能能够删除此'un'
字符串cText=“”;
//增强for循环
//从0开始,直到“只要输入文本”
对于(int i=0;i

非常感谢您的帮助。

如果您想在
活动的多个部分中使用
cText
变量,则需要将其置于方法之外,使其成为成员变量,最好是这样

public class ScreenNext extends Activity {

int key = 0;
static char ch;
String cText;
但在使用它或对其应用任何方法之前,您可能需要对其进行初始化或检查
null
。将变量放在这里可以为它提供类作用域,因此可以在此
活动中的任何位置访问它。您不能在
onCreate()
中再次“使用”它,因为一旦
onCreate()
方法完成,就不会再次调用它。我假设您在您的
onClick()
中讨论,它是在
onCreate()
中设置的,但在单击
按钮时将被调用。我对你问题的措辞有点困惑,所以如果这不是你想要的,那就解释清楚一点