Answer the question
In order to leave comments, you need to log in
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
Most likely swears at this line
There is no EditText in the markup file
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question