-1

The code for the main activity is down below. I started learning the SQL in Android studio. I will answer any further queries.

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    EditText inputField;
    Button insButton,delButton;
    TextView outputField;
    SQLHandler handler;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        inputField=(EditText)findViewById(R.id.input);
        insButton=(Button)findViewById(R.id.insertButton);
        delButton=(Button)findViewById(R.id.deleteButton);
        outputField=(TextView)findViewById(R.id.output);

        showOutput();
    }

    private void showOutput() {
        String text=handler.showName();
        outputField.setText(text);
    }

    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.insertButton:
                USER_DETAILS details=new USER_DETAILS(inputField.getText().toString());
                handler.addName(details);
                inputField.setText("");
                showOutput();
                break;
            case R.id.deleteButton:
                handler.delName(inputField.getText().toString());
                showOutput();
                inputField.setText("");
                break;
        }
    }
}

I have searched but not found any thing in stackoverflow. The error is unable to start the component info and cannot invoke the virtual method. Thank you for time.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

Seems like you forgot to instantiate the DBhandler, if you did add it in the main activity. So the code will be,

 protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
         handler=new SQLHandler(this);
        inputField=(EditText)findViewById(R.id.input);
        insButton=(Button)findViewById(R.id.insertButton);
        delButton=(Button)findViewById(R.id.deleteButton);
        outputField=(TextView)findViewById(R.id.output);
        showOutput();
    }

Change the arguments for the SQLHandler() according to your class.

deepakchethan
  • 5,240
  • 1
  • 23
  • 33