Search code examples
androidbigintegernumberformatexception

NumberFormatException: Invalid BigInteger


Here is part of my code:

public class Result extends Fragment{

     BigInteger sumCipher = BigInteger.ZERO;

     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
         View rootView = inflater.inflate(R.layout.result, container, false);
         return rootView;
     }

     @Override
     public void onStart() {
         super.onStart();

         new AsyncGetSumCipher().execute();
     }        

     public void setSumCipher(BigInteger sum){
         this.sumCipher = sum;
     }

     public BigInteger getSumCipher(){
         return sumCipher;
     }
}

The AsyncGetSumCipher class obviously contains doInBackground and onPostExecute. The latter is as follows:

protected void onPostExecute(StringBuilder result) {
 super.onPostExecute(result);

     BigInteger bi = new BigInteger(result.toString());

     setSumCipher(bi);
}

Here is the error

Can someone please help me? I've been stuck on this for weeks now :(


Solution

  • The problem was solved by doing the following:

    BigInteger bi = new BigInteger(result.toString().trim().replaceAll("\"",""));