A
A
Alexander Malakhovskiy2015-07-03 14:10:04
Java
Alexander Malakhovskiy, 2015-07-03 14:10:04

How to call another activity through the intention?

There are several classes you need to call another from 1, but when you press a key, Android Studio throws an error "java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference"
Here is the code:

public class AddNewMember extends Activity implements OnClickListener {

    EditText editText;
    Button addBtn, readBtn;
    SQLControler dbController;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_new_member);

        addBtn = (Button) findViewById(R.id.addmemBtn);
        editText = (EditText) findViewById(R.id.member_et_id);

        dbController = new SQLControler(this);
        try {
            dbController.open();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        addBtn.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.add_bt_id:
                String name = editText.getText().toString();
                dbController.insertData(name);

                Intent intent = new Intent(AddNewMember.this, MainActivity.class)
                        .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
                break;
        }
    }
}
а вот активити в которот есть клавиша
<code>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="10dp">

    <Button
        android:id="@+id/addmemBtn"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="ADD MEMBER" />

    <ListView
        android:id="@+id/memberList_id"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:dividerHeight="2dp" >
    </ListView>

</LinearLayout>     </code>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2015-07-03
@zok1995

Most likely swears at this line
There is no EditText in the markup file

O
Oleg Gamega, 2015-07-03
@gadfi

EditText no

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question