Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Eric Conklin
8,350 PointsAdded custom class for storing variables to main java folder and android manifest - still getting class cast exception!
The question above explains it. I asked about it earlier and made a few changes but have the same exact errors as before!
Here is my current activity code:
`` package ericleeconklin.costoflivingcalculator;
import android.content.Intent; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.TextView; import java.lang.Double;
public class EnterIncome extends ActionBarActivity {
public Double myIncome;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_enter_income);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_enter_income, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void getIncome(View view){
String myIncomeString;
TextView incomeView = (TextView)findViewById(R.id.enterIncome);
myIncomeString = incomeView.getText().toString();
myIncome = Double.parseDouble(myIncomeString);
((MyVariables) this.getApplication()).setIncome(myIncome);
Intent myIntent = new Intent(this, EnterExpenses.class);
startActivity(myIntent);
}
} ``
Here is my android manifest:
android:name="android.app.Application"
And finally, here is the custom class, MyVariables:
`` package ericleeconklin.costoflivingcalculator;
import android.app.Application;
/**
-
Created by Eric on 8/12/2015. */ public class MyVariables extends Application { private Double income;
public Double getIncome() { return income; }
public void setIncome(Double income) { this.income = income; }
private Double rentMortgage;
public Double getrentMortgage() { return rentMortgage; }
public void setrentMortgage(Double rentMortgage) { this.rentMortgage = rentMortgage; }
private Double insurance;
public Double getinsurance() { return insurance; }
public void setinsurance(Double insurance) { this.insurance = insurance; }
private Double utilities;
public Double getutilities() { return utilities; }
public void setutilities(Double utilities) { this.utilities = utilities; }
private Double phoneInternet;
public Double getphoneInternet() { return phoneInternet; }
public void setphoneInternet(Double phoneInternet) { this.phoneInternet = phoneInternet; }
private Double food;
public Double getfood() { return food; }
public void setfood(Double food) { this.food = food; }
private Double carPayment;
public Double getcarPayment() { return carPayment; }
public void setcarPayment(Double carPayment) { this.carPayment = carPayment; }
private Double misc;
public Double getmisc() { return misc; }
public void setmisc(Double misc) { this.misc = misc; } } ``