Reputation: 66
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;
}
}
Upvotes: 0
Views: 124
Reputation: 430
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 :)
Upvotes: 0
Reputation: 11
You follow these instruction.
Change this line.
Ausgabe.setText((CharSequence) Eingabe);
To
Ausgabe.setText(Eingabe.getText().toString());
Upvotes: 1
Reputation: 18933
The Problem is here:
Ausgabe.setText((CharSequence) Eingabe);
So you must change it with:
Ausgabe.setText(Eingabe.getText().toString());
Upvotes: 2
Reputation: 28823
Change
Ausgabe.setText((CharSequence) Eingabe);
to
Ausgabe.setText(Eingabe.getText().toString());
Hope this helps.
Upvotes: 5