How I can solve this error help?
Asked
Active
Viewed 39 times
-2
-
1Does this answer your question? [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – kg99 Dec 17 '20 at 07:32
2 Answers
-1
seems like btnDish
is null. Are you assigning it a value somewhere in code above?
You should be doing something like
btnDish = findViewById(R.id.btnDish)
btnDish.setOnClickListner {
//do stuff here
}

georkost
- 588
- 6
- 12
-
-
what should I do here? I just want to open the next activity by clicking button – safeer ahmad Dec 17 '20 at 07:52
-
no, i am not assigning it a value, I just declared it and set OnCLickListnere on btnDish just to open the next Activity – safeer ahmad Dec 17 '20 at 07:54
-
You need to assign `btnDish` the actual value before using it, thats line 1 of my code snippet. – georkost Dec 17 '20 at 08:01
-1
Button button = (Button) findViewById(R.id.button_send);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(FirstActivity.this,SecondActivity.class);
startActivity(intent);
}
});

Aditya Kamath
- 2,217
- 2
- 17
- 19

developer
- 30
- 6
-
-
error occurred because you are using btn.findViewById(); replace "." with "=" i.e btn=findViewById(R.id.btnid); – developer Dec 17 '20 at 10:48
-
Hi developer, please edit the question and add your answer there. It's pretty common only to share the code, but it's important to provide a description if you want to get positive results. – Federico Navarrete Dec 21 '20 at 08:17