0

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...

  1. What did i do wrong?

  2. 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;
     }
    }
    
joostmakaay
4372 gold badges7 silver badges14 bronze badges
asked Dec 19, 2013 at 12:37
4
  • 1
    please google how to get the Stacktrace in the Logcat and post it Commented Dec 19, 2013 at 12:38
  • From a quick inspection of your code it seems as though you are getting a class cast exception from Ausgabe.setText((CharSequence)Eingabe); .. should be Ausgabe.setText(Eingabe.getText()); Commented Dec 19, 2013 at 12:42
  • "adb shell logcat > c:/main.log " use this cmd you can get the mainlog and filter it by "exception" and you will find what happened by the stacktrace Commented Dec 19, 2013 at 12:44
  • Post your logcat also Commented Dec 19, 2013 at 12:45

5 Answers 5

5

Change

Ausgabe.setText((CharSequence) Eingabe);

to

Ausgabe.setText(Eingabe.getText().toString());

Hope this helps.

answered Dec 19, 2013 at 12:42
Sign up to request clarification or add additional context in comments.

Comments

2

try this

Ausgabe.setText(Eingabe.getText().toString());
Dave Newton
161k27 gold badges264 silver badges311 bronze badges
answered Dec 19, 2013 at 12:41

Comments

2

The Problem is here:

Ausgabe.setText((CharSequence) Eingabe);

So you must change it with:

Ausgabe.setText(Eingabe.getText().toString());
answered Dec 19, 2013 at 12:44

Comments

1

You follow these instruction.

Change this line.

Ausgabe.setText((CharSequence) Eingabe);

To

Ausgabe.setText(Eingabe.getText().toString());
Tunaki
138k46 gold badges372 silver badges446 bronze badges
answered Mar 5, 2016 at 8:43

1 Comment

I removed the link to your blog, which is unrelated to the question. Excessive promotion of a specific product/resource may be perceived by the community as spam. Take a look at the help center, specially What kind of behavior is expected of users?'s last section: Avoid overt self-promotion. You might also be interested in How do I advertise on Stack Overflow?.
0
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 :)

answered Jan 23, 2018 at 7:03

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.