Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>From the stack trace it looks like the code is failing for this view </p> <pre><code>int score = Integer.parseInt(txtscore.getText().toString()); </code></pre> <p>The problem might be that your TextView does not have any text set on it, hence the <strong>getText()</strong> is returning an empty string. This will cause the integer conversion to fail with an invalid number format exception.</p> <p>Having said that, you do not need to convert the string to int at that step. Since you already have access to the TextView that will need to be set, you only need to call the <strong>setText(...)</strong> method on it.</p> <p>Change these lines </p> <pre><code>String myresult=result.getText().toString(); int score = Integer.parseInt(txtscore.getText().toString());//this is what is making the program crash </code></pre> <p>to this</p> <pre><code>String myresult = "NA"; // Default text to display int score = 0; // Default score value </code></pre> <p>That will basically get you past your program crashing.</p> <p>Now the reason why there is no score or result (pass/fail) displayed is because you are trying to use the Button.isPressed() method to check if it is male or female.</p> <pre><code>if(male.isPressed()) { ...... } else if(female.isPressed()) { ...... } </code></pre> <p>Since you are clicking on a 'Calculate' button to get the scores, none of the other buttons will be in a pressed state. What I believe you need here is some sort of checkbox or radio control to select from male or female. Perhaps a list will do this job.</p> <p>Just to do a sanity check if your calculation is working, change <code>if(male.isPressed())</code> to <code>if(true)</code>. This will always return the score for male. You can do the same for the female class as well.</p> <p>Also, as noted in the above post, your subclasses do not need to extend the <code>Activity</code> class. This is of course based on the code that you have provided.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload