-4

I am getting a the error in the onClick method when the EditText object is referenced.

public class messageActivity extends AppCompatActivity {

  EditText editText;
  Button button;
  Logic logic;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_message);

    editText = (EditText) findViewById(R.id.editText);
    button = (Button) findViewById(R.id.button6);

    button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            logic.message(editText.getText().toString());
        }
    });
  }
}

Here is the XML for the EditText widget in my activity:

<EditText
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/editText"
      android:layout_below="@+id/textView3"
      android:layout_centerHorizontal="true"
      android:layout_marginTop="83dp"
      android:inputType="textShortMessage"
      android:editable="false" />
Jernej K
  • 1,602
  • 2
  • 25
  • 38
thefreebird777
  • 99
  • 1
  • 1
  • 8
  • where do you initialize your Logic variable? this would seem to be the null pointer here. please post your logcat – kandroidj Apr 25 '16 at 22:12

1 Answers1

1

I am suspecting that Logic is one of your classes? You are getting NullPointerException because the variable logic is not initialized with a value - you need to instantiate logic before you do logic.message.

ishmaelMakitla
  • 3,784
  • 3
  • 26
  • 32