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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:17:28+00:00 2026-05-26T07:17:28+00:00

Anyway so im trying to make something like a chat program and someone told

  • 0

Anyway so im trying to make something like a chat program and someone told me to use this code to check for new messages while allowing the user to submit a message:

timer.schedule(new TimerTask() {

  @Override
  public void run() {
     read.readChat(line);
  }
 }, 0, 1000);

 //Wait for user input
 while(true) {
     String bar = scan.next();
 }

Where the read.readChat(line); is the method which displays the messages from another file. Java tells me that read and line both have to be declared as final… I dont understand why especially for the “line” because that’s a variable and I need it to change.

Additionally after I declare them as final I get this error:

unreported exception java.lang.Exception; must be caught or declared to be thrown
                            read.readChat(salt);

What am I doing wrong?

  • 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-26T07:17:28+00:00Added an answer on May 26, 2026 at 7:17 am

    Second error tells you that the method read.readChat(line); throws a checked exception so you have to catch.

    You cannot use local variables declared at outer class in the Anonymous inner classes. Make them final or declare them as fields (instance variables).

    EDIT:

    @Override
    public void run() {
      try
       {
        read.readChat(line);
       }catch(Exception ex)
       {
         ex.printStackTrace();
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to do something like this, enum Data_Property { NAME, DATETIME, TYPE, };
I'm trying to make something that looks like: http://dev.sencha.com/deploy/ext-3.4.0/examples/grid/edit-grid.html But I want to change
I'm trying to make some sliding captions, something like Mosaic , but lighter. Everything
Why linq is trying to check second expression anyway? .Where(t => String.IsNullOrEmpty(someNullString) || t.SomeProperty
maybe it's not so proper to ask this question here... anyway, I'm trying to
I'm trying to make something of a Tile-Map editor in C# using picture-boxes (the
and I am tearing my hair out!! Even something simple like this work: procedure
I could use something like javas finally clause in a C switch. Most of
Is there any way, to make something like: $elements_string = array() foreach ($something as
I have something like this: class Base { public: static int Lolz() { return

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.