Note that there are some explanatory texts on larger screens.

plurals
  1. POThere is an error in my calculator app(java.lang.NumberFormatException)
    text
    copied!<p>I'm getting this error in my code: <code>java.lang.NumberFormatException</code>.</p> <ul> <li><code>m1</code> is for main string that contains the whole expression</li> <li><code>s</code> is for second number if no operator other than division is present </li> <li><code>f</code> is for first number if no operator other than division is present</li> <li><code>f1</code> is for first number if operator other than division is also present</li> <li><code>s1</code> is for second number if operator other than division is also present</li> </ul> <p>Here is the code:</p> <pre><code>b12.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub String s=""; String f=""; String f1=""; String s1=""; int z=m1.length(); int pos,pos1; for(int i=0;i&amp;lt;z;i++) { int m=m1.codePointAt(i); //Checking for division if(m==47) { // Loop to calculate second number for(int j=i+1;j&amp;lt;z;j++) { int d=m1.codePointAt(j); if(d!=43||d!=45||d!=42||d!=47) { s+=m1; } else { pos=j; s1+=m1.substring(pos,z); break; } } // Loop to calculate first number for(int j=i-1;j&amp;gt;=0;j--) { int d=m1.codePointAt(j); if(d!=43||d!=45||d!=42||d!=47) { f+=m1; } else { pos1=j; f1+=m1.substring(0,pos1); break; } } String rev=new StringBuffer(f).reverse().toString(); float ans=Float.parseFloat(rev)/Float.parseFloat(s); String e=Float.toString(ans); if(f1==""&amp;&amp;s1=="") { m1=""+e; } else { m1=""+f1+e+s1; } z=m1.length(); e1.setText(m1); } } } }); } </code></pre>
 

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