-3

This will be my second question along these lines as the previous post seems to have pretty much stopped drawing attention, so sorry for the spam. Anyways, last time I posted because I was getting a runtime crash as well as various errors within my code, and someone managed to help me beyond the errors in the code. However, after fixing the code I'm still getting crashes. Included is the code I have for my project and the log cat file at the bottom.

A quick overview of what its supposed to do: I'm trying to make a few edit text fields add up into a TextView field so that users can type in numbers in the edit text columns and see the result in the textview.

package com.example.gideon.timemanagement;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.widget.EditText;
import android.text.TextWatcher;
import android.widget.TextView;



public abstract class Customize extends AppCompatActivity implements TextWatcher {


EditText a;
EditText b;
TextView ht;


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

    EditText a = (EditText) findViewById(R.id.exerciseHours);
    EditText b = (EditText) findViewById(R.id.sleepHours);
    TextView ht = (TextView) findViewById(R.id.healthTotal);
}

private TextWatcher Ht = new TextWatcher() {

    @Override
    public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

    }

    @Override
    public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

    }

    @Override
    public void afterTextChanged(Editable editable) {


        if (!a.getText().toString().equals("") && !b.getText().toString().equals("")) {
            ht.setText(String.valueOf(Integer.valueOf(a.getText().toString()) + Integer.valueOf(b.getText().toString())));

        }
    }
};

02-10 18:53:40.167 23713-23713/com.example.gideon.timemanagement I/zygote: Not late-enabling -Xcheck:jni (already on) 02-10 18:53:40.174 23713-23713/com.example.gideon.timemanagement W/zygote: Unexpected CPU variant for X86 using defaults: x86 02-10 18:53:40.393 23713-23713/com.example.gideon.timemanagement I/InstantRun: starting instant run server: is main process 02-10 18:53:40.532 23713-23731/com.example.gideon.timemanagement D/OpenGLRenderer: HWUI GL Pipeline 02-10 18:53:40.662 23713-23731/com.example.gideon.timemanagement I/zygote: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColor ay retrieved: 0 02-10 18:53:40.662 23713-23731/com.example.gideon.timemanagement I/OpenGLRenderer: Initialized EGL, version 1.4 02-10 18:53:40.662 23713-23731/com.example.gideon.timemanagement D/OpenGLRenderer: Swap behavior 1 02-10 18:53:40.662 23713-23731/com.example.gideon.timemanagement W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without... 02-10 18:53:40.662 23713-23731/com.example.gideon.timemanagement D/OpenGLRenderer: Swap behavior 0 02-10 18:53:40.682 23713-23731/com.example.gideon.timemanagement D/EGL_emulation: eglCreateContext: 0xb1eabb60: maj 3 min 0 rcv 3 02-10 18:53:40.726 23713-23731/com.example.gideon.timemanagement D/EGL_emulation: eglMakeCurrent: 0xb1eabb60: ver 3 0 (tinfo 0xb1eef120) 02-10 18:53:40.728 23713-23731/com.example.gideon.timemanagement E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf 02-10 18:53:40.728 23713-23731/com.example.gideon.timemanagement E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf 02-10 18:53:40.728 23713-23731/com.example.gideon.timemanagement E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008824 02-10 18:53:40.728 23713-23731/com.example.gideon.timemanagement E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008824 02-10 18:53:40.759 23713-23731/com.example.gideon.timemanagement D/EGL_emulation: eglMakeCurrent: 0xb1eabb60: ver 3 0 (tinfo 0xb1eef120)

ADM
  • 20,406
  • 11
  • 52
  • 83
GidKort
  • 1
  • 1

1 Answers1

2

Inside oncreate, remove EditText and Textview definitions because already you declare them as member variables in the class

add TextChangedListener on your editText

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

 a = (EditText) findViewById(R.id.exerciseHours);
 b = (EditText) findViewById(R.id.sleepHours);
 ht = (TextView) findViewById(R.id.healthTotal);
 a.addTextChangedListener(this);
 b.addTextChangedListener(this);
 }

Also remove abstract from class definition

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
sasikumar
  • 12,540
  • 3
  • 28
  • 48