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 7859361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:53:29+00:00 2026-06-02T21:53:29+00:00

Error in java when creating Threads. The error is in MainApp with RandomCharacterThread being

  • 0

Error in java when creating Threads. The error is in “MainApp” with RandomCharacterThread being the error. The Thread t1 is expecting a char whereas i am giving it an int value. This is what had caused the error. I have added comments to make the code clearer for the community.

//Main class.
//program to display random numbers and characters using threads.
public class MainApp 
{

    public static void main(String[] args)
    {
        new MainApp().start();
    }
    public void start()
    {
        Thread t1 = new Thread (new RandomCharacterThread("1"));
        t1.start();

    }

}


//RandomCharacterThread.
//Imports.
import java.util.Random;
//=====================================================================
public class RandomCharacterThread implements Runnable
{
//Variables.
    char letter;
    int repeats;
    Random rand = new Random();
//Constructor
//=====================================================================
public void RandomCharacterThread(char x)
{
    letter = x;
    repeats = rand.nextInt(999);
}
public void run()
{
    try
    {
        for(int i = 0;i < repeats; i++)
        {
            System.out.println("Character: " + letter);
        }

    }
    catch(Exception e)
    {

    }
}

}
  • 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-02T21:53:30+00:00Added an answer on June 2, 2026 at 9:53 pm

    Your “constructor” takes a char as an argument; you’re passing a String. You’d want to do something like

        Thread t1 = new Thread (new RandomCharacterThread('1'));
    

    Note the single quotes rather than double quotes, which makes this a char constant rather than a String with one character.

    I say “constructor” in quotes because you actually don’t have one: you have a method that returns void with the same name as the class. Remove the “void” and you’ll be good. Constructors have no return type at all:

    public RandomCharacterThread(char x) 
    {
        ...
    

    This is a very common newbie mistake, but most people only make it once!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting this error: Exception in thread main java.lang.OutOfMemoryError: Java heap space at
I've got the following java code, which is giving the error below: import java.io.File;
I am not sure why I get this error: Caused by: java.lang.RuntimeException: Deferred binding
The error occurs when creating the Box object. public void drawBoard(Board board){ for(int row
Exception in thread main org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#0': Instantiation of bean
This is my first Java application I am creating (using Eclipse IDE) and the
I'm running into 'Error: Java heap space, java.lang.OutOfMemoryError: Java heap space' when compiling an
A previously working Ecplise now gives me the error Java Virtual Machine Launcher Could
Error % javac StringTest.java StringTest.java:4: variable errorSoon might not have been initialized errorSoon[0] =
I am loging error im my java swing application: logger.error(ERROR: + ex); where ex

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.