Calling a method inside a class

2

I have this part of my code where I call a class to add '0' to a group of characters that must have 4 characters.

StringTokenizer frase = new StringTokenizer(IMEIstring,".");
String first = frase.nextToken();
if(first.length()<4){
    AddOh instancia = new AddOh();
    String primeiro = instancia.AddZero(first);
    first = primeiro;
}

But it does not call the class, it gives error. In Logcat nothing appears and when I do Debug it looks like this:

BelowthefullcodeoftheAddOhclass:(Oh,ifIputitinsidethemainclassasaninternalfunctionandItrycallingitwithoutinstanceitalsodoesnotrun)

packagecom.example.minhaslicencasnobre;publicclassAddOh{publicStringAddZero(Stringpedaco){Stringfim=null;String[]H=null,finish,temp;inti,j=0;finish=newString[4];temp=newString[4];if(pedaco.length()<4){inttam=pedaco.length();for(i=0;i<pedaco.length();i++)H[i]=pedaco.substring(i,i+1);for(i=3;i>=0;i--){if(i<tam){temp[i]=H[j];j++;}elsetemp[i]="0";    
            }
            j=temp.length-1;
            for(i=0;i<temp.length;i++){
                finish[i] = temp[j];
                j--; 
            }
        }
        for(i=0;i<=finish.length;i++){
            fim = fim + finish[i];
        }
        return fim;
    }
}
    
asked by anonymous 20.05.2015 / 20:50

1 answer

2

From what I understood from your question and according to the comments, I believe that the solution can be simplified by using the class itself String .

Try something like this:

first = String.format("%4s", first).replace(' ', '0')

So you will have a " padding " on the left in your string and then replaced with zeros each of the spaces.

See an example on Ideone .

    
20.05.2015 / 21:30