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

  • SEARCH
  • Home
  • 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 9215803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:17:04+00:00 2026-06-18T02:17:04+00:00

My app needs to generate a hex string to use as a session ID.

  • 0

My app needs to generate a hex string to use as a session ID. Java’s SecureRandom doesn’t seem to be working (“java/lang/NoClassDefFoundError: java/security/SecureRandom: Cannot create class in system package”)

I thought of doing something like this:

byte[]  resBuf = new byte[50];
new Random().nextBytes(resBuf);
String  resStr = new String(Hex.encode(resBuf));

But the method nextBytes(byte[] bytes) isn’t available for some strange reason.

Does anyone have a means of generating a random hex number in Java ME/J2ME?

Many thanks.

Edit: The above generator seems to work when using Bouncy Castle lcrypto-j2me-145 (but not lcrypto-j2me-147).

  • 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-06-18T02:17:05+00:00Added an answer on June 18, 2026 at 2:17 am

    JavaME is a subset of JavaSE, so many classes and methods in the desktop version are not available.

    Looks like you are trying to get a random string of a given length. You can do something like this:

        private String getRandomHexString(int numchars){
            Random r = new Random();
            StringBuffer sb = new StringBuffer();
            while(sb.length() < numchars){
                sb.append(Integer.toHexString(r.nextInt()));
            }
    
            return sb.toString().substring(0, numchars);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a simple app that needs to generate an instance of a
I am currently writing an app in python that needs to generate large amount
So I am working on an iPad app that needs to talk to our
I have a Rails 3 app that needs to generate an image and send
To generate offline reports, my Rails app needs to download charts from the Google
My app needs to generate a pop up window on button click. The app
My app needs to generate a list of friends for the logged in user,
So my app needs to let users generate random alphanumeric codes like A6BU31, 38QV3B,
I'm writing an iOS app which needs to generate and animate individual text characters
I need to generate .rtf files in my Monotouch developed iOS app. I've found

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.