Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6766061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:47:06+00:00 2026-05-26T14:47:06+00:00

I have a problem that I want to append a string into StringBuffer object

  • 0

I have a problem that I want to append a string into StringBuffer object but it gives NullPointerException in my code. Please check this and tell where the code gets wrong and what is the best solution for this?

Error Stack:

11-03 18:13:29.672: ERROR/AndroidRuntime(17973): FATAL EXCEPTION: main
11-03 18:13:29.672: ERROR/AndroidRuntime(17973): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.TestCryptoActivity}: java.lang.NullPointerException
11-03 18:13:29.672: ERROR/AndroidRuntime(17973):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
11-03 18:13:29.672: ERROR/AndroidRuntime(17973):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-03 18:13:29.672: ERROR/AndroidRuntime(17973):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-03 18:13:29.672: ERROR/AndroidRuntime(17973):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-03 18:13:29.672: ERROR/AndroidRuntime(17973):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-03 18:13:29.672: ERROR/AndroidRuntime(17973):     at android.os.Looper.loop(Looper.java:123)
11-03 18:13:29.672: ERROR/AndroidRuntime(17973):     at android.app.ActivityThread.main(ActivityThread.java:4627)
11-03 18:13:29.672: ERROR/AndroidRuntime(17973):     at java.lang.reflect.Method.invokeNative(Native Method)
11-03 18:13:29.672: ERROR/AndroidRuntime(17973):     at java.lang.reflect.Method.invoke(Method.java:521)
11-03 18:13:29.672: ERROR/AndroidRuntime(17973):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-03 18:13:29.672: ERROR/AndroidRuntime(17973):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-03 18:13:29.672: ERROR/AndroidRuntime(17973):     at dalvik.system.NativeStart.main(Native Method)
11-03 18:13:29.672: ERROR/AndroidRuntime(17973): Caused by: java.lang.NullPointerException
11-03 18:13:29.672: ERROR/AndroidRuntime(17973):     at com.example.TestCryptoActivity.onCreate(TestCryptoActivity.java:83)
11-03 18:13:29.672: ERROR/AndroidRuntime(17973):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-03 18:13:29.672: ERROR/AndroidRuntime(17973):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
11-03 18:13:29.672: ERROR/AndroidRuntime(17973):     ... 11 more

Code:

String str;
    StringBuffer strBuf;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        String data = "xyzzy734499639E0022505@a2+;%d3-";


        try {
            str = getHashCode(data);
            strBuf.append(str); -----------------> This is the error position
        } catch (NoSuchAlgorithmException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }catch(Exception e)
        {
            e.printStackTrace();
        }


        for(int i=1;i<31;i++)
        {
            if(i<10)
            {
                str = String.valueOf(30)+String.valueOf(30+i)+str;
                try {
                    str = new String(getHashCode(str));
                } catch (NoSuchAlgorithmException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }else
            {
                char[] num = String.valueOf(i).toCharArray();
                String firstIndex = String.valueOf(num[0]);
                String secondIndex = String.valueOf(num[1]);
                str = firstIndex + secondIndex+ str;
                try {
                    str = new String(getHashCode(str));
                } catch (NoSuchAlgorithmException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            strBuf.append(str);
            System.out.println("The final string after hashing:"+str);
        }
    }
    public String getHashCode(String str) throws NoSuchAlgorithmException
    {

         MessageDigest md = MessageDigest.getInstance("SHA-512");
         md.update(str.getBytes());

         byte byteData[] = md.digest();

         //convert the byte to hex format method 1
         StringBuffer sb = new StringBuffer();
         for (int i = 0; i < byteData.length; i++) {
          sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
         }

         System.out.println("Hex format : " + sb.toString());
         return sb.toString();
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:47:07+00:00Added an answer on May 26, 2026 at 2:47 pm

    strBuf is not initialized.

    strBuf = new StringBuffer();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that i want to push_back into a deque. The problem
with my RCP program I have the problem that I want to have more
My problem is that I want to have a tab bar view with its
I have a problem with my site. I want that the shadow stops at
I have problem with fancybox. I want to write a function that will run
My problem is simple: I have a long list of elements that I want
I have a big problem. I want to extract text from html table that
In a couple of scripts that I use I have problem that is intermittent.
I have a problem that confuses my users, being that although an item is
I have the problem that an specific step in Ant can only be executed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.