Thursday, 8 August 2013

Android Application Crashes when Creating custom class object

Android Application Crashes when Creating custom class object

I'm working on my first android app and I'm having trouble creating an
object of a class I have programmed in java using the onCreate function of
an activity. The activity starts great when I do not instantiate the
object, but when I attempt to create the object the app crashes when
switching to the activity. The onCreate function looks like this...
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_entry);
// Show the Up button in the action bar.
setupActionBar();
ForceTable testTable = new ForceTable();
Double factor = testTable.returnValue(forceTypes.newtons,
forceTypes.newtons);
}
ForceTable is the class I have programmed, its code looks this...
public class ForceTable {
private double[][] forceTable;
protected enum forceTypes {newtons(0), pounds(1), kilopond(2);
public int num;
private forceTypes(int num)
{
this.num = num;
}
};
protected final class values{
private final static double zeroZero = 1.00;
private final static double zeroOne = 4.44872162;
private final static double zeroTwo = 9.80665;
private final static double oneZero = .224808943;
private final static double oneOne = 1.00;
private final static double oneTwo = 2.20462262;
private final static double twoZero = .10197164;
private final static double twoOne = .45359237;
private final static double twoTwo = 1.00;
}
public ForceTable()
{
this.makeTable();
}
private void makeTable()
{
forceTable[0][0] = values.zeroZero;
forceTable[0][1] = values.zeroOne;
forceTable[0][2] = values.zeroTwo;
forceTable[1][0] = values.oneZero;
forceTable[1][1] = values.oneOne;
forceTable[1][2] = values.oneTwo;
forceTable[2][0] = values.twoZero;
forceTable[2][1] = values.twoOne;
forceTable[2][2] = values.twoTwo;
}
public double returnValue(forceTypes ifYouHave, forceTypes thenYouHave){
double factor = forceTable[thenYouHave.num][ifYouHave.num];
return factor;
}
}
It's been a very long time since I have programmed in Java, and since the
activity starts fine without instantiating it must be my Java code for
ForceTable. Anybody notice something wrong? There's a good chance it's
something easy that I'm not brushed up on...

No comments:

Post a Comment