11

I dont know why it isn't working. It doesnt matter what I write on the edit text it always says the same thing: "THE NAME "+NAME+"ALREADY EXIST". I just dont know what the problem is.

public class AddScreen extends AppCompatActivity {
EditText first_name,last_name;
String first,last;
Button add;
Context ctx=this;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_screen);
    first_name=(EditText)findViewById(R.id.firstname);
    last_name=(EditText)findViewById(R.id.lastname);
    add=(Button)findViewById(R.id.save);
    first = first_name.getText().toString();
    last = last_name.getText().toString();

    add.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            DataBaseOperation DB = new DataBaseOperation(ctx);
            Cursor CR=  DB.getInformation(DB);
            CR.moveToFirst();
            boolean status= false;
            String NAME="";
            do {
                if(first.equals(CR.getString(0)) && (last.equals(CR.getString(1))))
                {
                    status=true;
                    NAME=CR.getString(0)+" "+CR.getString(1);
                }
            }while (CR.moveToNext());
            if(status)
            {
                Toast.makeText(getBaseContext(),"THE NAME  "+NAME+"ALREADY EXIST",Toast.LENGTH_LONG).show();
                finish();
            }
            else
            {
                DB.putInformation(DB, first, last);
                Toast.makeText(getBaseContext(),"NEW PLAYER CREATED",Toast.LENGTH_LONG).show();
                finish();

            }
        }

    });
}

its like status is always true.I think the problem is in this line

if(first.equals(CR.getString(0)) && (last.equals(CR.getString(1))))

because it always true. this is the logcat

09-23 22:55:12.457    4417-4431/? W/EGL_emulation﹕ eglSurfaceAttrib not implemented
09-23 22:55:12.457    4417-4431/? W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa2ae4340, error=EGL_SUCCESS
09-23 22:55:12.555    4417-4431/? W/EGL_emulation﹕ eglSurfaceAttrib not implemented
09-23 22:55:12.555    4417-4431/? W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xb3f1eba0, error=EGL_SUCCESS
09-23 22:55:12.633    1508-2592/? E/Surface﹕ getSlotFromBufferLocked: unknown buffer: 0xabfb40d0
09-23 22:55:12.634    4417-4431/? E/Surface﹕ getSlotFromBufferLocked: unknown buffer: 0xabfb4a00
09-23 22:55:15.904    4417-4431/? E/Surface﹕ getSlotFromBufferLocked: unknown buffer: 0xabfb60c0
BlueWizard
  • 372
  • 4
  • 19
Nadav Barak
  • 177
  • 1
  • 3
  • 14

0 Answers0