I\'m getting error when runtime my project.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.olympic/com.prima.olympic.ProductD
Your String checkOrigin is null thus giving you a NullPointerException. This is what is causing it:
String checkOrigin = i.getStringExtra("from_activity");
if(checkOrigin.equals("shoppinglist")){
btnAddtoShoppingList.setVisibility(View.GONE);
btnDeleteShoppingList.setVisibility(View.VISIBLE);
}
The String checkOrigin is null because you are not receiving any value from your Intent. This might be because you forgot to pass a value from your previous Activity.
However, you can check to see if your String is null and if it is, then those actions won't be performed. You would do this by the following:
String checkOrigin = i.getStringExtra("from_activity");
if(checkOrigin != null && checkOrigin.equals("shoppinglist")){
btnAddtoShoppingList.setVisibility(View.GONE);
btnDeleteShoppingList.setVisibility(View.VISIBLE);
}
Therefore, if checkOrigin is null, then those actions won't be performed.
But I would recommend checking the Activity that you are receiving the Intent from to make sure that you are sending and receiving the Intent correctly.
If you want to read more about NullPointerExceptions, have a look at this question and its answers for more detail.