• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

exceptions work once, then fail/not resetting

dcparham

Lurker
my app inputs 3 #s into inputs named Height, Diameter, # Segments, then puts the result into the Results box. normally there's another equation but this app simply adds inputs 1,2,3 and puts the result into box 4.
--->: here is what happens with the app [code is at the bottom, the xml file, and the java file]:

The app starts, and displays input boxes - box 1-Height, box 2-Diameter, box 3-Segments; there is a Calculate button, then a box 4 that displays the result of the calculation [between the variable input into boxes 1,2,3].

[right now the Height and Diameter are Integer-only inputs, but I would like them to be real #, since the Height and Diameter inputs might be something like 33.5 inches, 122.8 inches, etc]

Anyway, if you run the app and enter nothing into any box, it will throw an error for each input box like this:
> "Height must be >= 0"
> "Diameter must be >= 0"
> "# Segments must be >= 0"

In fact, it throws all 3 errors up at once [the 3rd msg box is larger [#1 and #2 are the same size, and you can see #3 in the background; as you hit OK the msg 1 disappears, then msg 2, then msg 3. when each one's OK is pressed, it reveals the one already displayed in the background]

Now, if you keep only inputbox1 blank, it throws only an error that "Height must be >= 0".
so, input1 is blank, input2 has integer like "120", input3 has integer like "5".

HOWEVER, if i *now clear input #2[diameter]* then it throws *only* input #1 error, "Height must be >= 0".
similarly, if i also clear input #3 [# segments], then it throws only input #1 error again.
so, now, if all 3 inputs are empty, it throws only input #1 error.

HOWEVER[i apologize, this can get confusing if you do not have the droid in your hand] - if i enter zero into any of the fields, it throws an error for that 0, and NOW throws an error for each of the other, still blank, fields.

Can you load the java and xml code [see attached: zipped files] into your simulator? Then after you load data into the inputs, start erasing it and hitting calculate; you'll the problem. I really appreciate your help with this!

Code follows on next post
 
[continued...]
main.xml:

Code:
[/SIZE][/FONT]
[FONT=Times New Roman][COLOR=teal]<?xml[/COLOR] [COLOR=purple]version[/COLOR]=[I][COLOR=blue]"1.0"[/COLOR][/I] [COLOR=purple]encoding[/COLOR]=[I][COLOR=blue]"utf-8"[/COLOR][/I][COLOR=teal]?>[/COLOR][/FONT]
[FONT=Times New Roman][COLOR=teal]<LinearLayout[/COLOR] [COLOR=purple]xmlns:android[/COLOR]=[I][COLOR=blue]"http://schemas.android.com/apk/res/android"[/COLOR][/I][/FONT]
[FONT=Times New Roman][COLOR=purple]android:orientation[/COLOR]=[I][COLOR=blue]"vertical"[/COLOR][/I][/FONT]
[FONT=Times New Roman][COLOR=purple]android:layout_width[/COLOR]=[I][COLOR=blue]"fill_parent"[/COLOR][/I][/FONT]
[FONT=Times New Roman][COLOR=purple]android:layout_height[/COLOR]=[I][COLOR=blue]"fill_parent"[/COLOR][/I][/FONT]
[COLOR=teal][FONT=Times New Roman]>[/FONT][/COLOR]
[FONT=Times New Roman][COLOR=teal]<TextView[/COLOR] [/FONT]
[FONT=Times New Roman][COLOR=purple]android:layout_width[/COLOR]=[I][COLOR=blue]"fill_parent"[/COLOR][/I] [/FONT]
[FONT=Times New Roman][COLOR=purple]android:layout_height[/COLOR]=[I][COLOR=blue]"wrap_content"[/COLOR][/I] [COLOR=purple]android:gravity[/COLOR]=[I][COLOR=blue]"top"[/COLOR][/I] [COLOR=purple]android:text[/COLOR]=[I][COLOR=blue]" Kneewall Segments Calculator"[/COLOR][/I][COLOR=teal]/>[/COLOR][/FONT]
[FONT=Times New Roman][COLOR=teal]<TextView[/COLOR] [/FONT]
[FONT=Times New Roman][COLOR=purple]android:layout_height[/COLOR]=[I][COLOR=blue]"wrap_content"[/COLOR][/I] [/FONT]
[FONT=Times New Roman][COLOR=purple]android:layout_width[/COLOR]=[I][COLOR=blue]"wrap_content"[/COLOR][/I] [/FONT]
[FONT=Times New Roman][COLOR=purple]android:textAppearance[/COLOR]=[I][COLOR=blue]"?android:attr/textAppearanceMedium"[/COLOR][/I] [/FONT]
[FONT=Times New Roman][COLOR=purple]android:id[/COLOR]=[I][COLOR=blue]"@+id/widget28"[/COLOR][/I] [/FONT]
[FONT=Times New Roman][COLOR=purple]android:layout_marginLeft[/COLOR]=[I][COLOR=blue]"10px"[/COLOR][/I] [COLOR=purple]android:text[/COLOR]=[I][COLOR=blue]"HEIGHT [in]"[/COLOR][/I] [COLOR=purple]android:layout_marginTop[/COLOR]=[I][COLOR=blue]"35px"[/COLOR][/I][COLOR=teal]>[/COLOR][/FONT]
[COLOR=teal][FONT=Times New Roman]</TextView>[/FONT][/COLOR]
[FONT=Times New Roman][COLOR=teal]<EditText[/COLOR] [COLOR=purple]android:layout_height[/COLOR]=[I][COLOR=blue]"wrap_content"[/COLOR][/I] [/FONT]
[FONT=Times New Roman][COLOR=purple]android:id[/COLOR]=[I][COLOR=blue]"@+id/amount1"[/COLOR][/I] [/FONT]
[FONT=Times New Roman][COLOR=purple]android:width[/COLOR]=[I][COLOR=blue]"100px"[/COLOR][/I] [/FONT]
[FONT=Times New Roman][COLOR=purple]android:layout_width[/COLOR]=[I][COLOR=blue]"200px"[/COLOR][/I] [COLOR=purple]android:layout_marginLeft[/COLOR]=[I][COLOR=blue]"220px"[/COLOR][/I] [COLOR=purple]android:layout_marginTop[/COLOR]=[I][COLOR=blue]"-45px"[/COLOR][/I] [COLOR=purple]android:inputType[/COLOR]=[I][COLOR=blue]"number"[/COLOR][/I] [COLOR=purple]android:text[/COLOR]=[I][COLOR=blue]" "[/COLOR][/I][COLOR=teal]>[/COLOR][/FONT]
[COLOR=teal][FONT=Times New Roman]<requestFocus></requestFocus>[/FONT][/COLOR]
[COLOR=teal][FONT=Times New Roman]</EditText>[/FONT][/COLOR]
[FONT=Times New Roman][COLOR=teal]<TextView[/COLOR] [/FONT]
[FONT=Times New Roman][COLOR=purple]android:layout_height[/COLOR]=[I][COLOR=blue]"wrap_content"[/COLOR][/I] [/FONT]
[FONT=Times New Roman][COLOR=purple]android:id[/COLOR]=[I][COLOR=blue]"@+id/widget29"[/COLOR][/I] [/FONT]
[FONT=Times New Roman][COLOR=purple]android:layout_width[/COLOR]=[I][COLOR=blue]"wrap_content"[/COLOR][/I] [/FONT]
[FONT=Times New Roman][COLOR=purple]android:textAppearance[/COLOR]=[I][COLOR=blue]"?android:attr/textAppearanceMedium"[/COLOR][/I] [/FONT]
[FONT=Times New Roman][COLOR=purple]android:layout_marginLeft[/COLOR]=[I][COLOR=blue]"10px"[/COLOR][/I] [COLOR=purple]android:text[/COLOR]=[I][COLOR=blue]"WIDTH [in]"[/COLOR][/I] [COLOR=purple]android:layout_marginTop[/COLOR]=[I][COLOR=blue]"20px"[/COLOR][/I][COLOR=teal]>[/COLOR][/FONT]
[COLOR=teal][FONT=Times New Roman]</TextView>[/FONT][/COLOR]
[FONT=Times New Roman][COLOR=teal]<EditText[/COLOR] [COLOR=purple]android:layout_height[/COLOR]=[I][COLOR=blue]"wrap_content"[/COLOR][/I] [/FONT]
[FONT=Times New Roman][COLOR=purple]android:id[/COLOR]=[I][COLOR=blue]"@+id/amount2"[/COLOR][/I] [/FONT]
[FONT=Times New Roman][COLOR=purple]android:width[/COLOR]=[I][COLOR=blue]"100px"[/COLOR][/I] [/FONT]
[FONT=Times New Roman][COLOR=purple]android:layout_width[/COLOR]=[I][COLOR=blue]"200px"[/COLOR][/I] [COLOR=purple]android:layout_marginLeft[/COLOR]=[I][COLOR=blue]"220px"[/COLOR][/I] [/FONT]
[FONT=Times New Roman][COLOR=purple]android:layout_marginTop[/COLOR]=[I][COLOR=blue]"-55px"[/COLOR][/I] [COLOR=purple]android:inputType[/COLOR]=[I][COLOR=blue]"number"[/COLOR][/I] [COLOR=purple]android:text[/COLOR]=[I][COLOR=blue]" "[/COLOR][/I][COLOR=teal]>[/COLOR][/FONT]
[COLOR=teal][FONT=Times New Roman]</EditText>[/FONT][/COLOR]
[FONT=Times New Roman][COLOR=teal]<TextView[/COLOR] [/FONT]
[FONT=Times New Roman][COLOR=purple]android:layout_height[/COLOR]=[I][COLOR=blue]"wrap_content"[/COLOR][/I] [/FONT]
[FONT=Times New Roman][COLOR=purple]android:layout_width[/COLOR]=[I][COLOR=blue]"wrap_content"[/COLOR][/I] [/FONT]
[FONT=Times New Roman][COLOR=purple]android:textAppearance[/COLOR]=[I][COLOR=blue]"?android:attr/textAppearanceMedium"[/COLOR][/I] [/FONT]
[FONT=Times New Roman][COLOR=purple]android:id[/COLOR]=[I][COLOR=blue]"@+id/widget30"[/COLOR][/I] [/FONT]
[FONT=Times New Roman][COLOR=purple]android:layout_marginLeft[/COLOR]=[I][COLOR=blue]"10px"[/COLOR][/I] [COLOR=purple]android:layout_marginTop[/COLOR]=[I][COLOR=blue]"10px"[/COLOR][/I] [COLOR=purple]android:text[/COLOR]=[I][COLOR=blue]"# SEGMENTS"[/COLOR][/I][COLOR=teal]>[/COLOR][/FONT]
[COLOR=teal][FONT=Times New Roman]</TextView>[/FONT][/COLOR]
[FONT=Times New Roman][COLOR=teal]<EditText[/COLOR] [COLOR=purple]android:layout_height[/COLOR]=[I][COLOR=blue]"wrap_content"[/COLOR][/I] [/FONT]
[FONT=Times New Roman][COLOR=purple]android:id[/COLOR]=[I][COLOR=blue]"@+id/amount3"[/COLOR][/I] [/FONT]
[FONT=Times New Roman][COLOR=purple]android:width[/COLOR]=[I][COLOR=blue]"100px"[/COLOR][/I] [/FONT]
[FONT=Times New Roman][COLOR=purple]android:layout_width[/COLOR]=[I][COLOR=blue]"200px"[/COLOR][/I] [/FONT]
[FONT=Times New Roman][COLOR=purple]android:layout_marginLeft[/COLOR]=[I][COLOR=blue]"220px"[/COLOR][/I] [/FONT]
[FONT=Times New Roman][COLOR=purple]android:layout_marginTop[/COLOR]=[I][COLOR=blue]"-45px"[/COLOR][/I] [/FONT]
[FONT=Times New Roman][COLOR=purple]android:inputType[/COLOR]=[I][COLOR=blue]"number"[/COLOR][/I] [COLOR=purple]android:text[/COLOR]=[I][COLOR=blue]" "[/COLOR][/I][COLOR=teal]>[/COLOR][/FONT]
[COLOR=teal][FONT=Times New Roman]</EditText>[/FONT][/COLOR]
[FONT=Times New Roman][COLOR=teal]<Button[/COLOR] [COLOR=purple]android:id[/COLOR]=[I][COLOR=blue]"@+id/calculate"[/COLOR][/I] [/FONT]
[FONT=Times New Roman][COLOR=purple]android:layout_height[/COLOR]=[I][COLOR=blue]"wrap_content"[/COLOR][/I] [/FONT]
[FONT=Times New Roman][COLOR=purple]android:layout_marginLeft[/COLOR]=[I][COLOR=blue]"10px"[/COLOR][/I] [COLOR=purple]android:layout_width[/COLOR]=[I][COLOR=blue]"200px"[/COLOR][/I] [COLOR=purple]android:layout_marginTop[/COLOR]=[I][COLOR=blue]"10px"[/COLOR][/I] [COLOR=purple]android:text[/COLOR]=[I][COLOR=blue]"CALCULATE LENGTH ---&gt;"[/COLOR][/I][COLOR=teal]></Button>[/COLOR][/FONT]
[FONT=Times New Roman][COLOR=teal]<EditText[/COLOR] [/FONT]
[FONT=Times New Roman][COLOR=purple]android:layout_height[/COLOR]=[I][COLOR=blue]"wrap_content"[/COLOR][/I] [/FONT]
[FONT=Times New Roman][COLOR=purple]android:id[/COLOR]=[I][COLOR=blue]"@+id/tt"[/COLOR][/I] [/FONT]
[FONT=Times New Roman][COLOR=purple]android:layout_marginLeft[/COLOR]=[I][COLOR=blue]"220px"[/COLOR][/I] [COLOR=purple]android:layout_marginTop[/COLOR]=[I][COLOR=blue]"-75px"[/COLOR][/I] [COLOR=purple]android:textSize[/COLOR]=[I][COLOR=blue]"16dp"[/COLOR][/I] [COLOR=purple]android:layout_width[/COLOR]=[I][COLOR=blue]"200px"[/COLOR][/I] [COLOR=purple]android:text[/COLOR]=[I][COLOR=blue]" {LENGTH}"[/COLOR][/I][COLOR=teal]></EditText>[/COLOR][/FONT]
[FONT=Times New Roman][COLOR=teal]<AnalogClock[/COLOR] [COLOR=purple]android:layout_height[/COLOR]=[I][COLOR=blue]"wrap_content"[/COLOR][/I] [COLOR=purple]android:id[/COLOR]=[I][COLOR=blue]"@+id/analogClock1"[/COLOR][/I] [COLOR=purple]android:layout_width[/COLOR]=[I][COLOR=blue]"wrap_content"[/COLOR][/I] [COLOR=purple]android:layout_marginLeft[/COLOR]=[I][COLOR=blue]"125px"[/COLOR][/I] [COLOR=purple]android:layout_marginTop[/COLOR]=[I][COLOR=blue]"60px"[/COLOR][/I][COLOR=teal]></AnalogClock>[/COLOR][/FONT]
[COLOR=teal][FONT=Times New Roman]</LinearLayout>[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3]
Code:
 Addition_Copy.java[/SIZE][/FONT]
[FONT=Times New Roman][B][COLOR=purple]package[/COLOR][/B] com.example;[/FONT]
[FONT=Times New Roman][B][COLOR=purple]import[/COLOR][/B] [U]java.text.DecimalFormat[/U];[/FONT]
[FONT=Times New Roman][B][COLOR=purple]import[/COLOR][/B] [U]org.apache.commons.lang.StringUtils[/U];[/FONT]
[FONT=Times New Roman][B][COLOR=purple]import[/COLOR][/B] android.app.Activity;[/FONT]
[FONT=Times New Roman][B][COLOR=purple]import[/COLOR][/B] android.app.AlertDialog;[/FONT]
[FONT=Times New Roman][B][COLOR=purple]import[/COLOR][/B] android.content.DialogInterface;[/FONT]
[FONT=Times New Roman][B][COLOR=purple]import[/COLOR][/B] [U]android.graphics.Color[/U];[/FONT]
[FONT=Times New Roman][B][COLOR=purple]import[/COLOR][/B] android.os.Bundle;[/FONT]
[FONT=Times New Roman][B][COLOR=purple]import[/COLOR][/B] android.widget.EditText;[/FONT]
[FONT=Times New Roman][B][COLOR=purple]import[/COLOR][/B] android.widget.TextView;[/FONT]
[FONT=Times New Roman][B][COLOR=purple]import[/COLOR][/B] android.widget.Button;[/FONT]
[FONT=Times New Roman][B][COLOR=purple]import[/COLOR][/B] [U]android.widget.Toast[/U];[/FONT]
[FONT=Times New Roman][B][COLOR=purple]import[/COLOR][/B] android.view.View;[/FONT]
[FONT=Times New Roman][B][COLOR=purple]public[/COLOR][/B] [B][COLOR=purple]class[/COLOR][/B] AdditionActivity [B][COLOR=purple]extends[/COLOR][/B] Activity[/FONT]
[FONT=Times New Roman]{[COLOR=teal]//Activity BEGIN[/COLOR][/FONT]
[FONT=Times New Roman][B][COLOR=purple]private[/COLOR][/B] EditText [COLOR=blue]amount1[/COLOR];[/FONT]
[FONT=Times New Roman][B][COLOR=purple]private[/COLOR][/B] EditText [COLOR=blue]amount2[/COLOR];[/FONT]
[FONT=Times New Roman][B][COLOR=purple]private[/COLOR][/B] EditText [COLOR=blue]amount3[/COLOR];[/FONT]
[FONT=Times New Roman][B][COLOR=purple]private[/COLOR][/B] TextView [COLOR=blue]tt[/COLOR];[/FONT]
[FONT=Times New Roman][B][COLOR=purple]private[/COLOR][/B] Button [COLOR=blue]calculate[/COLOR];[/FONT]
[FONT=Times New Roman]String [COLOR=blue]strAmount1[/COLOR] = [B][COLOR=purple]new[/COLOR][/B] String([COLOR=blue]""[/COLOR]);[/FONT]
[FONT=Times New Roman][B][COLOR=purple]private[/COLOR][/B] [B][COLOR=purple]double[/COLOR][/B] [COLOR=blue]val1_height[/COLOR]=0;[/FONT]
[FONT=Times New Roman][B][COLOR=purple]private[/COLOR][/B] [B][COLOR=purple]double[/COLOR][/B] [COLOR=blue]val2_width[/COLOR]=0;[/FONT]
[FONT=Times New Roman][B][COLOR=purple]private[/COLOR][/B] [B][COLOR=purple]double[/COLOR][/B] [COLOR=blue]val3_segments[/COLOR]=0;[/FONT]
[FONT=Times New Roman][B][COLOR=purple]private[/COLOR][/B] [B][COLOR=purple]double[/COLOR][/B] [U][COLOR=blue]val4_radius[/COLOR][/U]=0; [COLOR=teal]//test[/COLOR][/FONT]
[FONT=Times New Roman][B][COLOR=purple]private[/COLOR][/B] [B][COLOR=purple]double[/COLOR][/B] [U][COLOR=blue]val5_theta1[/COLOR][/U];[/FONT]
[FONT=Times New Roman][B][COLOR=purple]private[/COLOR][/B] [B][COLOR=purple]double[/COLOR][/B] [U][COLOR=blue]val6_theta2[/COLOR][/U];[/FONT]
[FONT=Times New Roman][B][COLOR=purple]private[/COLOR][/B] [B][COLOR=purple]double[/COLOR][/B] [COLOR=blue]val7_sum[/COLOR];[/FONT]
[FONT=Times New Roman][COLOR=gray]@SuppressWarnings[/COLOR]([COLOR=blue]"unused"[/COLOR])[/FONT]
[FONT=Times New Roman][B][COLOR=purple]private[/COLOR][/B] String [COLOR=blue]result1[/COLOR];[/FONT]
[FONT=Times New Roman][B][COLOR=purple]private[/COLOR][/B] [B][COLOR=purple]int[/COLOR][/B] [COLOR=blue]fixFlag1[/COLOR] = 0;[/FONT]
[FONT=Times New Roman][B][COLOR=purple]boolean[/COLOR][/B] [COLOR=blue]flag[/COLOR] = [B][COLOR=purple]true[/COLOR][/B];[/FONT]
[COLOR=blue][FONT=Times New Roman]/** Called when the activity is first created. */[/FONT][/COLOR]
[COLOR=gray][FONT=Times New Roman]@Override[/FONT][/COLOR]
[FONT=Times New Roman][B][COLOR=purple]public[/COLOR][/B] [B][COLOR=purple]void[/COLOR][/B] onCreate(Bundle savedInstanceState)[/FONT]
[FONT=Times New Roman]{[/FONT]
[FONT=Times New Roman][B][COLOR=purple]super[/COLOR][/B].onCreate(savedInstanceState);[/FONT]
[FONT=Times New Roman]setContentView(R.layout.[I][COLOR=blue]main[/COLOR][/I]);[/FONT]
[FONT=Times New Roman]initControls();[/FONT]
[FONT=Times New Roman]}[/FONT]
[FONT=Times New Roman][B][COLOR=purple]private[/COLOR][/B] [B][COLOR=purple]void[/COLOR][/B] initControls()[/FONT]
[FONT=Times New Roman]{[/FONT]
[FONT=Times New Roman][COLOR=blue]amount1[/COLOR]=(EditText)findViewById(R.id.[I][COLOR=blue]amount1[/COLOR][/I]);[/FONT]
[FONT=Times New Roman][COLOR=blue]amount2[/COLOR]=(EditText)findViewById(R.id.[I][COLOR=blue]amount2[/COLOR][/I]);[/FONT]
[FONT=Times New Roman][COLOR=blue]amount3[/COLOR]=(EditText)findViewById(R.id.[I][COLOR=blue]amount3[/COLOR][/I]);[/FONT]
[FONT=Times New Roman][COLOR=blue]tt[/COLOR]=(TextView)findViewById(R.id.[I][COLOR=blue]tt[/COLOR][/I]);[/FONT]
[FONT=Times New Roman][COLOR=blue]calculate[/COLOR]=(Button)findViewById(R.id.[I][COLOR=blue]calculate[/COLOR][/I]);[/FONT]
[FONT=Times New Roman][COLOR=blue]calculate[/COLOR].setOnClickListener([B][COLOR=purple]new[/COLOR][/B] Button.OnClickListener()[/FONT]
[FONT=Times New Roman]{[B][COLOR=purple]public[/COLOR][/B] [B][COLOR=purple]void[/COLOR][/B] onClick[/FONT]
[FONT=Times New Roman](View v) { calculate();}});[/FONT]
[FONT=Times New Roman]}[/FONT]
[FONT=Times New Roman][B][COLOR=purple]public[/COLOR][/B] [B][COLOR=purple]void[/COLOR][/B] calculate()[COLOR=teal]//was private[/COLOR][/FONT]
[FONT=Times New Roman]{[COLOR=teal]//calculate BEGIN[/COLOR][/FONT]
[FONT=Times New Roman][B][COLOR=purple]try[/COLOR][/B] {[COLOR=teal]//#1.3[/COLOR][/FONT]
[FONT=Times New Roman][COLOR=blue]val1_height[/COLOR]=Double.[I]parseDouble[/I]([COLOR=blue]amount1[/COLOR].getText().toString());[/FONT]
[FONT=Times New Roman]}[COLOR=teal]//try END[/COLOR][/FONT]
[FONT=Times New Roman][B][COLOR=purple]catch[/COLOR][/B](Exception e) { [COLOR=teal]// ... handle errors ... [/COLOR][/FONT]
[COLOR=teal][FONT=Times New Roman]//throw new RuntimeException(e);[/FONT][/COLOR]
[FONT=Times New Roman]}[/FONT]
[FONT=Times New Roman][B][COLOR=purple]try[/COLOR][/B] {[COLOR=teal]//#2.3[/COLOR][/FONT]
[FONT=Times New Roman][COLOR=blue]val2_width[/COLOR]=Double.[I]parseDouble[/I]([COLOR=blue]amount2[/COLOR].getText().toString());[/FONT]
[FONT=Times New Roman]}[COLOR=teal]//try END[/COLOR][/FONT]
[FONT=Times New Roman][B][COLOR=purple]catch[/COLOR][/B](Exception e) { [COLOR=teal]// ... handle errors ... [/COLOR][/FONT]
[COLOR=teal][FONT=Times New Roman]//throw new RuntimeException(e); [/FONT][/COLOR]
[FONT=Times New Roman]}[/FONT]
[FONT=Times New Roman][B][COLOR=purple]try[/COLOR][/B] {[COLOR=teal]//#3.3[/COLOR][/FONT]
[FONT=Times New Roman][COLOR=blue]val3_segments[/COLOR]=Double.[I]parseDouble[/I]([COLOR=blue]amount3[/COLOR].getText().toString());[/FONT]
[FONT=Times New Roman]}[COLOR=teal]//try END[/COLOR][/FONT]
[FONT=Times New Roman][B][COLOR=purple]catch[/COLOR][/B](Exception e) { [COLOR=teal]// ... handle errors ... [/COLOR][/FONT]
[COLOR=teal][FONT=Times New Roman]//throw new RuntimeException(e); [/FONT][/COLOR]
[FONT=Times New Roman]}[/FONT]
[FONT=Times New Roman][B][COLOR=purple]if[/COLOR][/B]([COLOR=blue]val3_segments[/COLOR] == 0)[/FONT]
[FONT=Times New Roman]{[COLOR=teal]//val3 BEGIN[/COLOR][/FONT]
[FONT=Times New Roman][COLOR=blue]fixFlag1[/COLOR] = 1;[/FONT]
[COLOR=teal][FONT=Times New Roman]// prepare the alert box [/FONT][/COLOR]
[FONT=Times New Roman]AlertDialog.Builder alertbox = [B][COLOR=purple]new[/COLOR][/B] AlertDialog.Builder([B][COLOR=purple]this[/COLOR][/B]); [/FONT]
[COLOR=teal][FONT=Times New Roman]// set the message to display [/FONT][/COLOR]
[FONT=Times New Roman]alertbox.setMessage([COLOR=blue]"# Segments must be > 0, please reenter."[/COLOR]); [/FONT]
[COLOR=teal][FONT=Times New Roman]// add a neutral button to the alert box and assign a click listener [/FONT][/COLOR]
[FONT=Times New Roman]alertbox.setNeutralButton([COLOR=blue]"Ok"[/COLOR], [B][COLOR=purple]new[/COLOR][/B] DialogInterface.OnClickListener() { [/FONT]
[COLOR=teal][FONT=Times New Roman]// click listener on the alert box [/FONT][/COLOR]
[FONT=Times New Roman][B][COLOR=purple]public[/COLOR][/B] [B][COLOR=purple]void[/COLOR][/B] onClick(DialogInterface arg0, [B][COLOR=purple]int[/COLOR][/B] arg1) { [/FONT]
[COLOR=teal][FONT=Times New Roman]// the button was clicked [/FONT][/COLOR]
[COLOR=teal][FONT=Times New Roman]//Toast.makeText(getApplicationContext(), "OK button clicked", Toast.LENGTH_LONG).show(); [/FONT][/COLOR]
[FONT=Times New Roman]} [/FONT]
[FONT=Times New Roman]}); [/FONT]
[COLOR=teal][FONT=Times New Roman]// show it [/FONT][/COLOR]
[FONT=Times New Roman]alertbox.show();[/FONT]
[FONT=Times New Roman]}[COLOR=teal]//val3 END[/COLOR][/FONT]
[FONT=Times New Roman][B][COLOR=purple]else[/COLOR][/B] {[COLOR=teal]//else BEGIN[/COLOR][/FONT]
[FONT=Times New Roman][COLOR=blue]fixFlag1[/COLOR] = 0;[/FONT]
[FONT=Times New Roman]}[COLOR=teal]//else END[/COLOR][/FONT]
[FONT=Times New Roman][B][COLOR=purple]if[/COLOR][/B]([COLOR=blue]val2_width[/COLOR] == 0)[/FONT]
[FONT=Times New Roman]{[COLOR=teal]//val2 BEGIN[/COLOR][/FONT]
[FONT=Times New Roman][COLOR=blue]fixFlag1[/COLOR] = 1;[/FONT]
[COLOR=teal][FONT=Times New Roman]// prepare the alert box [/FONT][/COLOR]
[FONT=Times New Roman]AlertDialog.Builder alertbox = [B][COLOR=purple]new[/COLOR][/B] AlertDialog.Builder([B][COLOR=purple]this[/COLOR][/B]); [/FONT]
[COLOR=teal][FONT=Times New Roman]// set the message to display [/FONT][/COLOR]
[FONT=Times New Roman]alertbox.setMessage([COLOR=blue]"Width must be > 0, please reenter."[/COLOR]); [/FONT]
[COLOR=teal][FONT=Times New Roman]// add a neutral button to the alert box and assign a click listener [/FONT][/COLOR]
[FONT=Times New Roman]alertbox.setNeutralButton([COLOR=blue]"Ok"[/COLOR], [B][COLOR=purple]new[/COLOR][/B] DialogInterface.OnClickListener() { [/FONT]
[COLOR=teal][FONT=Times New Roman]// click listener on the alert box [/FONT][/COLOR]
[FONT=Times New Roman][B][COLOR=purple]public[/COLOR][/B] [B][COLOR=purple]void[/COLOR][/B] onClick(DialogInterface arg0, [B][COLOR=purple]int[/COLOR][/B] arg1) { [/FONT]
[COLOR=teal][FONT=Times New Roman]// the button was clicked [/FONT][/COLOR]
[COLOR=teal][FONT=Times New Roman]//Toast.makeText(getApplicationContext(), "OK button clicked", Toast.LENGTH_LONG).show(); [/FONT][/COLOR]
[FONT=Times New Roman]} [/FONT]
[FONT=Times New Roman]}); [/FONT]
[COLOR=teal][FONT=Times New Roman]// show it [/FONT][/COLOR]
[FONT=Times New Roman]alertbox.show();[/FONT]
[FONT=Times New Roman]}[COLOR=teal]//val2 END[/COLOR][/FONT]
[FONT=Times New Roman][B][COLOR=purple]else[/COLOR][/B] {[COLOR=teal]//else BEGIN[/COLOR][/FONT]
[FONT=Times New Roman][COLOR=blue]fixFlag1[/COLOR] = 0;[/FONT]
[FONT=Times New Roman]}[COLOR=teal]//else END[/COLOR][/FONT]
[FONT=Times New Roman][B][COLOR=purple]if[/COLOR][/B]([COLOR=blue]val1_height[/COLOR] == 0)[/FONT]
[COLOR=teal][FONT=Times New Roman]//if(amount1.getText().toString().equals(""))[/FONT][/COLOR]
[FONT=Times New Roman]{[COLOR=teal]//val1 BEGIN[/COLOR][/FONT]
[FONT=Times New Roman][COLOR=blue]fixFlag1[/COLOR] = 1;[/FONT]
[COLOR=teal][FONT=Times New Roman]// prepare the [U]aler[/U] t box [/FONT][/COLOR]
[FONT=Times New Roman]AlertDialog.Builder alertbox = [B][COLOR=purple]new[/COLOR][/B] AlertDialog.Builder([B][COLOR=purple]this[/COLOR][/B]); [/FONT]
[COLOR=teal][FONT=Times New Roman]// set the message to display [/FONT][/COLOR]
[FONT=Times New Roman]alertbox.setMessage([COLOR=blue]"Height must be > 0, please reenter."[/COLOR]); [/FONT]
[COLOR=teal][FONT=Times New Roman]// add a neutral button to the alert box and assign a click listener [/FONT][/COLOR]
[FONT=Times New Roman]alertbox.setNeutralButton([COLOR=blue]"Ok"[/COLOR], [B][COLOR=purple]new[/COLOR][/B] DialogInterface.OnClickListener() { [/FONT]
[COLOR=teal][FONT=Times New Roman]// click listener on the alert box [/FONT][/COLOR]
[FONT=Times New Roman][B][COLOR=purple]public[/COLOR][/B] [B][COLOR=purple]void[/COLOR][/B] onClick(DialogInterface arg0, [B][COLOR=purple]int[/COLOR][/B] arg1) { [/FONT]
[COLOR=teal][FONT=Times New Roman]// the button was clicked [/FONT][/COLOR]
[COLOR=teal][FONT=Times New Roman]//Toast.makeText(getApplicationContext(), "OK button clicked", Toast.LENGTH_LONG).show(); [/FONT][/COLOR]
[FONT=Times New Roman]} [/FONT]
[FONT=Times New Roman]}); [/FONT]
[COLOR=teal][FONT=Times New Roman]// show it [/FONT][/COLOR]
[FONT=Times New Roman]alertbox.show();[/FONT]
[FONT=Times New Roman]}[COLOR=teal]//val1 END[/COLOR][/FONT]
[FONT=Times New Roman][B][COLOR=purple]else[/COLOR][/B] {[COLOR=teal]//else BEGIN[/COLOR][/FONT]
[FONT=Times New Roman][COLOR=blue]fixFlag1[/COLOR] = 0;[/FONT]
[FONT=Times New Roman]}[COLOR=teal]//else END[/COLOR][/FONT]
[COLOR=teal][FONT=Times New Roman]//simplified to be simply val1+val2+val3:[/FONT][/COLOR]
[FONT=Times New Roman][COLOR=blue]val7_sum[/COLOR] = [COLOR=blue]val1_height[/COLOR] + [COLOR=blue]val2_width[/COLOR] + [COLOR=blue]val3_segments[/COLOR];[/FONT]
[FONT=Times New Roman][B][COLOR=purple]if[/COLOR][/B]([COLOR=blue]fixFlag1[/COLOR]==0){[COLOR=teal]//fixFlag1 BEGIN[/COLOR][/FONT]
[FONT=Times New Roman][COLOR=blue]tt[/COLOR].setText(Double.[I]toString[/I]([COLOR=blue]val7_sum[/COLOR]));[/FONT]
[FONT=Times New Roman]}[COLOR=teal]//fixFlag1 END[/COLOR][/FONT]
[FONT=Times New Roman][B][COLOR=purple]else[/COLOR][/B] {[COLOR=teal]//else BEGIN[/COLOR][/FONT]
[FONT=Times New Roman][COLOR=blue]tt[/COLOR].setText([COLOR=blue]" {LENGTH}"[/COLOR]); }[COLOR=teal]//else END[/COLOR][/FONT]
[FONT=Times New Roman]}[COLOR=teal]//calculate END[/COLOR][/FONT]
[FONT=Times New Roman]}[COLOR=teal]//Activity END[/COLOR][/FONT]
[FONT=Times New Roman][SIZE=3]
Thank you for your help!!
 
Back
Top Bottom