0

to the point. I don't know what make my function error but here when i want to convert an int Array to ASCII character, i got some errors which says

java.lang.OutOfMemoryError: Failed to allocate a 51529974 byte allocation with 4194304 free bytes and 30MB

I think my function doesn't right enough to convert it. Here is my function :

public static String[] DectoASCII(int[] resultXORDec,int jumKat) {
    int length = jumKat;

    String ASCIIfromDec[] = new String[jumKat];

    for(int i=0;i<jumKat;i++) {
        StringBuilder builder = new StringBuilder(length);
        for (int j = length - 1; j >= 0; i--) {
            builder.append((char) ((resultXORDec[j] >> (8 * i)) & 0xFF));
        }
        ASCIIfromDec[i]=builder.toString();
        Log.d("ascifrom",ASCIIfromDec[i]);
    }
    return ASCIIfromDec;
}

}

Please master, help me. Is there any other way to convert int (Decimal) to ASCII code? Thanks..

1 Answer 1

3

Well, I guess the j index does not change in this loop:

for (int j = length - 1; j >= 0; i--) {
builder.append((char) ((resultXORDec[j] >> (8 * i)) & 0xFF));
}

thus you have an infinite loop, so builder gets bigger and bigger.

Sign up to request clarification or add additional context in comments.

3 Comments

Yea i think this is the problem, maybe the i-- was meant to be j--
okaay thanks sir, it can run properly now. But i got error on the result. The result of string builder just display ???? when i Log.d to it. Is there any way to convert stringbuilder to a normal String?
You just do it by using toString method. Another problem is what you actually put in resultXORDec.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.