Hey guys I'm a beginner (sort off) in java and i'm having some trouble. I'm trying to get the date I set in the Budget class with a variable in the Finances class but I keep getting a NullPointerException
.
I'm trying to use the dueDate
variable in the finances class but the logCat keeps stating that it's a null object reference
even after I've instantiated it.
public class Budget {
private Date mDate = new Date();
public static double budgetAmount;
private static Budget instance = new Budget();
private Budget(){
}
public double getBudget(){
return budgetAmount;
}
public void setBudget(double budget){
budgetAmount = budget;
}
public static Budget getInstance(){
return instance;
}
public Date getDate() {
return mDate;
}
public void setDate(Date date) {
mDate = date;
}
}
Here is the Financial Class
public class Finances extends Activity{
int amtFood; int amtCar; int amtGas; int amtTvBill; int amtInBill;
int amtTronics; int amtWear; int amtLight; int amtWater; int amtOthers;
Date nowDate;
Date dueDate = new Date();
double MainAmount = Budget.budgetAmount;
static int SpentAmount;
Budget budgetDate;
public Finances(){
HashMap<String,Integer> amtAdd = ExpenditureLab.get(this).getExpendMap();
int food= amtAdd.get("Groceries/Food");
int car = amtAdd.get("Car servicing");
int gas = amtAdd.get("Gas Money");
int tvBill = amtAdd.get("Television Bill");
int inBill = amtAdd.get("Internet Bill");
int tronics = amtAdd.get("Electronics");
int wear = amtAdd.get("Clothes/Wearables");
int light = amtAdd.get("Light Bill");
int water = amtAdd.get("Water Bill");
int others = amtAdd.get("Others");
dueDate = budgetDate.getDate();
}
public void addSpent(int amt){
SpentAmount += amt;
}
}