I'm pretty new to Android so please bear with me. :D
Well my program should read in a text and after I press a button it should display it at another position. There are no errors and I can install the app on my smartphone. Suddenly it crashes for no reason...
What did i do wrong?
Is there anyways to find an error without anything wrong? o.O
package com.example.a2;
import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final EditText Eingabe = (EditText) findViewById(R.id.editText1); final EditText Ausgabe = (EditText) findViewById(R.id.editText2); final Button button = (Button) findViewById(R.id.button_send); button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Ausgabe.setText((CharSequence) Eingabe); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; } }
5 Answers 5
Change
Ausgabe.setText((CharSequence) Eingabe);
to
Ausgabe.setText(Eingabe.getText().toString());
Hope this helps.
Comments
try this
Ausgabe.setText(Eingabe.getText().toString());
Comments
The Problem is here:
Ausgabe.setText((CharSequence) Eingabe);
So you must change it with:
Ausgabe.setText(Eingabe.getText().toString());
Comments
You follow these instruction.
Change this line.
Ausgabe.setText((CharSequence) Eingabe);
To
Ausgabe.setText(Eingabe.getText().toString());
1 Comment
Ausgabe.setText((CharSequence) Eingabe);
Change this code with this one
Ausgabe.setText(Eingabe.getText().toString());
This code will help you to get the code from Eingabe editText and then convert it into string and then set this text to Ausgabe edittext field This will help you :)
Ausgabe.setText((CharSequence)Eingabe);.. should beAusgabe.setText(Eingabe.getText());