By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,645 Members | 1,328 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,645 IT Pros & Developers. It's quick & easy.

How to resolve NumberFormatException : for input string error?

P: 1
This is a part of my code, where Im trying to generate a few patterns, Now Im getting an error saying :
Exception in thread "main" java.lang.NumberFormatException: For input string: "C2"
at java.lang.NumberFormatException.forInputString(Num berFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:449)
at java.lang.Integer.valueOf(Integer.java:554)
at nprf.offline.PatternGenerator.doGeneratePattern(Pa tternGenerator.java:77)
at nprf.offline.PatternGenerator.main(PatternGenerato r.java:23)

The error is occuring in these two lines [edit: 50 and 51] as shown below:
int a= Integer.valueOf(Fe[i][k].substring(1,Fe[i][k].indexOf(',')));
int b= Integer.valueOf(Fe[j][k].substring(1,Fe[j][k].indexOf(',')));

Fe[][] is an array which is declared as String [][] Fe=new String[500][77];

Expand|Select|Wrap|Line Numbers
  1. public void doGeneratePattern() throws Exception 
  2.     {
  3.         String sql; 
  4.         ResultSet rs;
  5.  
  6.         // STEP NO 8
  7.         int i=0;
  8.         int ptr=0;
  9.  
  10.         findF1();
  11.  
  12.         //STEP NO 10
  13.         e=2;
  14.         while (true) 
  15.         {
  16.             // Flush support of size MAX_CA
  17.             for(int a=0;a<MAX_CA;a++)
  18.                 Support[a]=0;
  19.  
  20.             // Flush  CAe
  21.             for(int a=0;a<MAX_CA;a++)
  22.                 for(int b=0;b<Auxiliary.MAX_ITERATION;b++) 
  23.                     CAe[a][b]=null;
  24.  
  25.             ptr=0;
  26.             int j;
  27.             for (i=0;i<nFe;i++) 
  28.             {
  29.                 for (j=i+1;j<nFe;j++) 
  30.                 {
  31.                     boolean flag=false;
  32.                     for (int k=0;k<e-2;k++) 
  33.                     {
  34.                         if (Fe[i][k].equals(Fe[j][k]))
  35.                             continue;
  36.                         else 
  37.                         {
  38.                             flag=true;
  39.                             break;
  40.                         }
  41.                     }
  42.                     int k;
  43.                     if (flag==false) // (k-2) items matched
  44.                     {
  45.                         for (k=0;k<e-2;k++)
  46.                             CAe[ptr][k]=Fe[i][k];
  47.  
  48.                      //   Double a=  Double.parseDouble(Fe[i][k].substring(1,Fe[i][k].indexOf(',')));
  49.                      //   Double b=  Double.parseDouble(Fe[j][k].substring(1,Fe[j][k].indexOf(',')));
  50.                        int a=  Integer.valueOf(Fe[i][k].substring(1,Fe[i][k].indexOf(',')));
  51.                        int b=  Integer.valueOf(Fe[j][k].substring(1,Fe[j][k].indexOf(',')));
  52.                     //  System.out.println("value of a and b"+a +b);
  53.                         if(e!=2 || a==1)
  54.                             if (a<b)
  55.                             {
  56.                                 CAe[ptr][k]=Fe[i][k];
  57.                                 CAe[ptr][k+1]=Fe[j][k];
  58.                                 ptr++;
  59.                             }
  60.                     }
  61.                     else
  62.                         continue;
  63.                 }
  64.             }
  65.             nCAe=ptr;
  66.             for (int k=0;k<nCAe;k++) 
  67.             {
  68.                 sql="select * from navigationtransaction";
  69.                 rs=Auxiliary.stmt.executeQuery(sql);
  70.                 while (rs.next()) 
  71.                 {
  72.                     String itemString=rs.getString(2);
  73.                     boolean flag=false;
  74.                     for(int l=0;l<e;l++)
  75.                     {
  76.                         if(itemString.contains(CAe[k][l])==true) 
  77.                             continue;
  78.                         else 
  79.                             flag=true;
  80.                     }
  81.                     if(flag==false)
  82.                         Support[k]++;
  83.                 }
  84.             }
  85.             int m=0;
  86.             for (int k=0;k<nCAe;k++) 
  87.             {
  88.                 if (Support[k]>=Auxiliary.minSupport) 
  89.                 {
  90.                     for (j=0;j<e;j++)
  91.                         Fe[m][j]=CAe[k][j];
  92.                     m++;
  93.                 }
  94.             }
  95.             nFe=m;
  96.             for (int k=0;k<nFe;k++) 
  97.             {
  98.                 for (j=0;j<e;j++) 
  99.                     NP[nNP][j]=Fe[k][j];
  100.                 nNP++;
  101.             }
  102.             e=e+1;      
  103.             if(nFe==0) 
  104.                 break;
  105.         }      
  106.     }
Apr 14 '12 #1
Share this Question
Share on Google+
1 Reply


Rabbit
Expert Mod 10K+
P: 12,421
The substring you're returning includes the comma.
Apr 14 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.