Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have a piece of code that splits number of certain length into four parts while running the code when i enter the last number i get unfortunately closed error.
Java
if (iscan.length() == 54)
               {
                   Toast.makeText(getApplicationContext(), "1", Toast.LENGTH_SHORT).show();
                   if (iscan.contains("(01)") && iscan.contains("(17)") && iscan.contains("(10)") && iscan.contains("(21)")) {
                       //String igtin = String.valueOf(iscan.indexOf(iscan, 4));
                       Toast.makeText(getApplicationContext(), "2", Toast.LENGTH_SHORT).show();
                       String igtin = iscan.substring(4, 18);
                       String iexpiry = iscan.substring(21, 27);
                       String ibatch = iscan.substring(31, 37);
                       String sSerialNo = iscan.substring(41, 54);
                       //String sGTINCode=iscan.substring(5,17);

                       gtin.setText(igtin);
                       expiry.setText(iexpiry);
                       batch.setText(ibatch);
                       serial.setText(sSerialNo);
                       duplicateSecondary(sSerialNo);

                   }
               }
                   else {
                       //Toast.makeText(getApplicationContext(), "Invalid Code", Toast.LENGTH_SHORT).show();
                       error.setText("Invalid Code is Scanned.. Please Scan a proper Bar Code");
                       error.setTextColor(Color.parseColor("#FFFFFF"));
                   }
Posted
Comments
Richard MacCutchan 1-Jul-15 9:16am    
Check that the source string conforms exactly to the substring references that you are using.
Rahul Ramakrishnan 2-Jul-15 0:01am    
this is the value i need to split.
(01)18904037412920(17)160200(10)405595(21)HPNC000000019
when i type in (01)18904037412920(17)160200(10)405595(21 and when i click ) i get unfortunately stopped error
Richard MacCutchan 2-Jul-15 3:15am    
That is because your scanner immediately starts to try and extract the substrings from an incomplete string, since it 'sees' all the substrings that you are testing for. You should add some code that ensures that all the text is entered before it starts to process the string.
Sergey Alexandrovich Kryukov 1-Jul-15 11:18am    
If you want to ask "how", better ask what you want to achieve, not mixing it with your idea on "how". You did not specify what you want to parse. Maybe you need Regex instead...
—SA
Rahul Ramakrishnan 2-Jul-15 0:01am    
this is the value i need to split.
(01)18904037412920(17)160200(10)405595(21)HPNC000000019
when i type in (01)18904037412920(17)160200(10)405595(21 and when i click ) i get unfortunately stopped error

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900