I try add method in another class which need help me processing errors. And when I need get toast, I get error. How can I decide this situation? Please, help me and explain me how use contexts. Thank you.
This my error:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference
And this my code:
public class DataHelper extends BaseAppCompatActivity {
protected Intent intent;
/**
* Выводит сумму услуги
* @param price цена
* @param discount скидка
* @return
*/
public static Double Sum (double price, double discount){
Double sum = null;
if (price == 0 && discount == 0){
return null;
} else if (price == discount){
sum = price;
} else if (price > discount || price < discount){
sum = price - discount;
}
return sum;
}
/**
* Обработка ошибок
* @param errorCode код ошибки
* @param errorDescription описание ошибки
*/
public void processingError(String errorCode, String errorDescription){
switch (errorCode){
case "inside":
Toast.makeText(getApplicationContext(), errorDescription, Toast.LENGTH_SHORT).show();
break;
case "method_not_found":
Toast.makeText(getApplicationContext(), errorDescription, Toast.LENGTH_SHORT).show();
break;
case "method_access_denied":
intent = new Intent(this, AuthorizationActivity.class);
startActivity(intent);
finish();
Toast.makeText(getApplicationContext(), errorDescription, Toast.LENGTH_SHORT).show();
break;
case "bad_authorization":
intent = new Intent(this, AuthorizationActivity.class);
startActivity(intent);
finish();
Toast.makeText(getApplicationContext(), errorDescription, Toast.LENGTH_SHORT).show();
break;
case "bad_client_secret_or_id":
intent = new Intent(this, AuthorizationActivity.class);
startActivity(intent);
finish();
Toast.makeText(getApplicationContext(), errorDescription, Toast.LENGTH_SHORT).show();
break;
case "app_access_denied":
intent = new Intent(this, AuthorizationActivity.class);
startActivity(intent);
finish();
Toast.makeText(getApplicationContext(), errorDescription, Toast.LENGTH_SHORT).show();
break;
case "wrong_params":
Toast.makeText(getApplicationContext(), errorDescription, Toast.LENGTH_SHORT).show();
break;
case "wrong_param_value":
Toast.makeText(getApplicationContext(), errorDescription, Toast.LENGTH_SHORT).show();
break;
case "object_not_found":
Toast.makeText(getApplicationContext(), errorDescription, Toast.LENGTH_SHORT).show();
break;
}
}
}