My databases (information to display on a table) are connected to buttons. When they are clicked, the table should show info. The database works, but this is the catcher: It works when I had info already entered from testing. But the database crashes if their is nothing to load. Here is the code:
rentD.open();
Log.d(TAG, "OPENING RENT DATABASE...");
String rentData = rentD.getData();
billAmount.setText("Total: " + nf.format(rentD.getAmountTotal()));
Log.d(TAG, "CLOSING RENT DATABASE...");
rentD.close();
Log.d(TAG, "RENT DATABASE CLOSED");
dataResults.setText(rentData);
So every time I click the RENT button, I get a forced close. After further looking, The problem I found have to do with:
billAmount... nf.format(rentD.getAmountTotal()));
which displays a the amount in money format. So if I replace “rentD.getAmountTotal()” with a String variable, the database works perfectly. Here is the error I recieved from LogCat:
10-26 23:53:40.764: DEBUG/DEBUG(14999): OPENING RENT DATABASE...
10-26 23:53:40.764: DEBUG/AndroidRuntime(14999): Shutting down VM
10-26 23:53:40.764: WARN/dalvikvm(14999): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0)
Again, the problem seems to be passing data that doesn’t exist yet into the textview.
My end result is to have the program start with no data in it so the user can get to the activities that will populate the table. Any suggestions?
From your comment, I would suggest you drop the
DecimalFormatfromgetAmountTotal()because it does nothing useful (you’re not using the return value offormat()), and use this instead: