This week's book giveaway is in the Java in General forum.
We're giving away four copies of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 and have ishori Sharan & Adam L Davis on-line!
See this thread for details.
Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Thread compile errors

 
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to figure out what is wrong with this class. It has a compile error I have the code copied and commented.


package messagemanagement;

import java.util.PriorityQueue;
import java.util.Queue;
import java.util.concurrent.PriorityBlockingQueue;

import journaling.CJournal;
import schedulingmanager.EEventMachine;
import messagemanagement.Message;

//Services work on messages passed to them
//the message manager receives and sends messages
//that in queue to to the other services that are runing

//so it
//a: receives messages from servies
//b: puts (stores) messages in a list
//c: passes along all messages to all services that are awake
//d: removes messages from list after complete


///!!!
// The message pump exists on one thread and
// the game itself exists on another

//example:  I'd like to draw an array of triangles (me being the aialgorithims for edxample)
// I send a message to the scheduler
// The scheduler isolates a thread for the message amd semds to the message manager
// The message manager puts my request on queue
// The message maanager broadcasts the "RenderTriangles" message
// There are only two methods (receivers) for that message
// They execute and after sending the remaining messages
// the messagemanager is done.
//


// delay message delivery

public  class MessageManager extends Thread {



@Override
public  void run() {
// TODO Auto-generated method stub
while (true)
if (!messagesQueue.isEmpty())
{
//pull message from queue
Message message = messagesQueue.remove();

//dispatch messages according to their type
switch(message.mflag)
{
case EM_BOOTSTRAP:
CJournal.Journal(MessageManager.class, "Messaging system working properly.");
default:
CJournal.Journal(MessageManager.class, "Default Dispatch Message Trashed");
}
}
}

}

               //ERROR: Syntax error on token static; interface expected after this token interface expected
               // interface headername expected
                //syntax error on these tokens, delete these tokens.

public static PriorityBlockingQueue<Message> messagesQueue = new PriorityBlockingQueue<Message>();


//syntax error on token void, @ expected

public static void EnqueueMessage(Message message)
{
messagesQueue.add(message);

}
//called upon when object is no longer needed

public void Destroy()
{
//called Destroy
}

//called every turn. checks messagemanager for message

public void ParseMessage()
{

}


public static void Launch() {}


//called on object creation

public static void Init() {}



public static void  Render()
{

}


public static void  Collision()
{

}

//when the game requires this particular state to be active

public static void  OnEnter()
{

}

//When the object no longer needs to be attachd to the scene graph

public static void  OnExit()
{
}

//for exammple, hitting the pause button

public static void  OnSuspend()
{
}


public static void Train()
{
//incoming messages are analyzed and sent
//to the trainer to record the behavior for the aialgorithims
}



}

Does the overall syntax of the code look right? I'm thinking that's the problem.
 
Sheriff
Posts: 26963
84
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ted Gress wrote:Does the overall syntax of the code look right? I'm thinking that's the problem.



That's not the problem. The compiler won't fail you if the "overall syntax" doesn't look right. In fact I don't even know what "overall syntax" might mean.

I'd strongly suggest that it's more practical to read the contents of the error message and try to interpret it in the context of the line of code it's attached to. If you can't interpret the message then by all means post the relevant information here and ask us about it. That's what we're here for, after all.
 
Master Rancher
Posts: 4600
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also please wrap all posted code in code tags.  Select the code and press the Code button.
 
Marshal
Posts: 74725
336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you still haven't worked it out, please post the text of the error messages because we have probably seen them before.
 
Ted Gress
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Error messages I'm getting for this code:


The error message is:

Description Resource Path Location Type
Syntax error on token "static", interface expected after this token MessageManager.java /ShadowEngineElite/src/messagemanagement line 65 Java Problem



Go easy on me, its been a while since I programmed in Java. The erroneous code is commented above.

 
Norm Radder
Master Rancher
Posts: 4600
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which line in the posted code is line 65 that is referred to in the error message?

Check that the {}s are properly paired.

One problem I see is that there is no { }  for the while statement.   Always enclose code following while, for, if etc statements in {}s
 
Paul Clapham
Sheriff
Posts: 26963
84
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:Check that the {}s are properly paired.



Yup, this is very likely the cause of the error. But it's also a good idea to make sure the {}s are used consistently. There's two styles of bracketing used in languages like Java. There's this style:



where the brackets all go at the start of their own lines and where you can match the opening and closing brackets by running your finger up and down a code listing. You (I mean you, Ted, not Norm) have mostly used this style. And then there's this style:



where the opening bracket goes at the end of a line and its matching closing bracket goes at the start of its own line. You used that style at least once.

So I think the mixture of bracketing styles is making it hard for you to identify unmatched brackets. And I have to apologize, I guess that's what you meant when you said "overall syntax" in your original post.

Anyway I'd recommend choosing one of the two styles. Doesn't matter which, choose whichever looks better to you. Then fix up your code to use that style for all blocks -- methods, if-blocks, else-blocks, switch blocks, the whole lot.

 
Ted Gress
Ranch Hand
Posts: 229
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I realize I was being a bit sloppy with how I was styling my brackets and that caused me to overlook
the while statement. That solved that issue. Thanks guys!
 
Paul Clapham
Sheriff
Posts: 26963
84
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Excellent! On to the next problem!
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic