10 Replies - 794 Views - Last Post: 26 July 2013 - 11:04 AM Rate Topic: -----

#1 Dib't   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 25-July 13

Problem with activating program?

Posted 25 July 2013 - 08:04 PM

Basically my problem is I'm trying to figure out a working
public static void main
code.

And I'm also trying to fix another problem on how it loads.

1st Things 1st: When I just use this:
	public static void main(String args[]) {
		
	}


I get this in the console

Item info loaded: 2


When I use this
	public static void main(String args[]) {
		Engine engine = new Engine();
	}


I get this
Item info loaded: 2
Current Date is: [2013/07/25 23:00:28]
OS: Windows 7
Using Java Version: 1.6.0_43



I want to make it so that Item info loads after the Time, os, and Java version messages are shown.

Here's my Engine class, I'm unsure of where the problem is.

package framework;

import framework.game.items.ItemManager;
import framework.util.Constants;

public class Engine {

	public Engine() {
		Constants.println("Current Date is: ["+Constants.getDate()+"]");
		
		Constants.println("OS: "+System.getProperty("os.name"));
		Constants.println("Using Java Version: "+System.getProperty("java.version"));
	}
	
	public static ItemManager itemManager = new ItemManager();
	
	public void tick(long l) {
		try {
			Thread.sleep(l);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	public static void main(String args[]) {
		Engine engine = new Engine();
	}
	
}



And here's my loadItemXML method that says "Item info loaded: " I doubt the problem is in there though but I don't know.

    public void loadItemXML() {
    	try {
    		XMLParser itemInfoXML = new XMLParser("data/items/items.xml");
    		itemInfoXML.setByElement("Item");
    		for(int i = 0; i < itemInfoXML.getElements().size(); i++) {
    			Map<String, String> element = itemInfoXML.getElements().get(i);
    			String name = 
    					itemInfoXML.getStringByTag(element, "Name");
    			String examine = 
    					itemInfoXML.getStringByTag(element, "Examine");
    			int id = 
    					itemInfoXML.getIntByTag(element, "Id");
    			boolean stackable = 
    					Boolean.parseBoolean(itemInfoXML.getStringByTag(element, "Stackable"));
    			int minPrice =
    					itemInfoXML.getIntByTag(element, "MinPrice");
    			int normPrice =
    					itemInfoXML.getIntByTag(element, "NormPrice");
    			int maxPrice =
    					itemInfoXML.getIntByTag(element, "MaxPrice");
    			int classType =
    					itemInfoXML.getIntByTag(element, "ClassType");
    			itemLists.put(id, new ItemList(name, examine, id, classType,
    					minPrice, normPrice, maxPrice, stackable));
    		}
    		Constants.println("Item info loaded: "+itemLists.size());
    	} catch (Exception e) {
    		System.out.println("Error loading items!");
    	}
    }


I DON'T EXPECT SPOONFEEDING! BUT I DO EXPECT SOMEONE TO HELP IN A NON DOUCHEBAG/DICK MANNER!

Is This A Good Question/Topic? 0
  • +

Replies To: Problem with activating program?

#2 Dib't   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 25-July 13

Re: Problem with activating program?

Posted 25 July 2013 - 08:16 PM

I'm not sure where the edit button is so forgive me for double posting.. But this seems to be the problem
public ItemManager itemManager = new ItemManager();


When it's there it loads the method. Anyone know why?
Was This Post Helpful? 0
  • +
  • -

#3 macosxnerd101   User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12324
  • View blog
  • Posts: 45,424
  • Joined: 27-December 08

Re: Problem with activating program?

Posted 25 July 2013 - 08:17 PM

The ItemManager object is static in your Engine class. Hence, it is loaded first, as it is associated with the Engine class rather than the Engine objects. I'm guessing ItemManager has something to do with printing.

Quote

I DON'T EXPECT SPOONFEEDING! BUT I DO EXPECT SOMEONE TO HELP IN A NON DOUCHEBAG/DICK MANNER

Take a chill pill and relax some. Nobody has been rude to you. Not sure where the attitude is coming from.You can shoot me a PM if there are serious concerns.
Was This Post Helpful? 0
  • +
  • -

#4 Dib't   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 25-July 13

Re: Problem with activating program?

Posted 25 July 2013 - 08:24 PM

View Postmacosxnerd101, on 25 July 2013 - 08:17 PM, said:

The ItemManager object is static in your Engine class. Hence, it is loaded first, as it is associated with the Engine class rather than the Engine objects. I'm guessing ItemManager has something to do with printing.

Quote

I DON'T EXPECT SPOONFEEDING! BUT I DO EXPECT SOMEONE TO HELP IN A NON DOUCHEBAG/DICK MANNER

Take a chill pill and relax some. Nobody has been rude to you. Not sure where the attitude is coming from.You can shoot me a PM if there are serious concerns.


Thanks! And I'm sorry it's just how I talk over the internet.. Sometimes people read to fast or don't read everything at all and start to act rude so I wrote that in all caps.

When I do this

	public Engine() {
		Constants.println("Current Date is: ["+Constants.getDate()+"]");
		
		Constants.println("OS: "+System.getProperty("os.name"));
		Constants.println("Using Java Version: "+System.getProperty("java.version"));
		loadManagers(); <---
	}
	
	private void loadManagers() {
		ItemManager.loadItemXML(); <---
	}/code]

It'll say that it needs to make my loadItemXML method static, then it'll say I'll need to make [code]private Map<Integer, ItemList> itemLists = new HashMap<Integer, ItemList>();
also static. If I make it static will it still load the items and allow me to access the xml without problem?
Was This Post Helpful? 0
  • +
  • -

#5 macosxnerd101   User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12324
  • View blog
  • Posts: 45,424
  • Joined: 27-December 08

Re: Problem with activating program?

Posted 25 July 2013 - 08:40 PM

Why is your ItemManager object static in your Engine class? Why are you trying to invoke loadItemXML() as if it were a static method? Your design doesn't make sense there to me. Talk us through your design choices rather than just aimlessly changing methods and variables to/from static.

Quote

Sometimes people read to fast or don't read everything at all and start to act rude so I wrote that in all caps.

It's not just screaming at people, but assuming that people that respond are going to be rude to you. It's a little uncalled for when you come to a place to get help, but say "hey- don't be a dick" right up front. I don't imagine you would say that to an IT professional in real life if you asked one for help. Everyone on here (except for the spam bots) are people.
Was This Post Helpful? 0
  • +
  • -

#6 nandureddy   User is offline

  • D.I.C Head

Reputation: 28
  • View blog
  • Posts: 129
  • Joined: 31-January 11

Re: Problem with activating program?

Posted 25 July 2013 - 08:42 PM

Quote

Thanks! And I'm sorry it's just how I talk over the internet.. Sometimes people read to fast or don't read everything at all and start to act rude so I wrote that in all caps.

Don't assume like that.
Was This Post Helpful? 0
  • +
  • -

#7 Flukeshot   User is offline

  • A little too OCD
  • member icon

Reputation: 417
  • View blog
  • Posts: 1,030
  • Joined: 14-November 12

Re: Problem with activating program?

Posted 25 July 2013 - 09:22 PM

View Postmacosxnerd101, on 26 July 2013 - 12:17 PM, said:

Take a chill pill


Mac, the 90s called, said they wanted their phrase back.

They called me too. Shortly after posting this. :P

@Dib't: Dream.In.Code is probably one of the very few places on the internet where you don't need to worry about people being rude when you need help. I'd avoid the caffeine lounge if you're susceptible to trolling, though. :)
Was This Post Helpful? 0
  • +
  • -

#8 Dib't   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 25-July 13

Re: Problem with activating program?

Posted 25 July 2013 - 09:30 PM

View Postmacosxnerd101, on 25 July 2013 - 08:40 PM, said:

Why is your ItemManager object static in your Engine class? Why are you trying to invoke loadItemXML() as if it were a static method? Your design doesn't make sense there to me. Talk us through your design choices rather than just aimlessly changing methods and variables to/from static.

Quote

Sometimes people read to fast or don't read everything at all and start to act rude so I wrote that in all caps.

It's not just screaming at people, but assuming that people that respond are going to be rude to you. It's a little uncalled for when you come to a place to get help, but say "hey- don't be a dick" right up front. I don't imagine you would say that to an IT professional in real life if you asked one for help. Everyone on here (except for the spam bots) are people.


@Red, I've updated so everything looks like this now
public class Engine {
	
	public Engine() {
		Constants.println("Current Date is: ["+Constants.getDate()+"]");
		Constants.println("Using Java Version: "+System.getProperty("java.version"));
		Constants.println("OS: "+System.getProperty("os.name"));
		
		loadManagers();
	}
	
	private void loadManagers() {
		ItemManager.loadItemXML();
	}

	public void tick(long l) {
		try {
			Thread.sleep(l);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	public static void main(String args[]) throws IOException {
		Engine engine = new Engine();
	}

@Blue, I'm trying new ideas while I wait for someone to reply
@Purple, I'm doing what eclipse says. I've fix my 1st problem with the message being sent twice and now my concern/question is http://prntscr.com/1hkqjd

View PostFlukeshot, on 25 July 2013 - 09:22 PM, said:

View Postmacosxnerd101, on 26 July 2013 - 12:17 PM, said:

Take a chill pill


Mac, the 90s called, said they wanted their phrase back.

They called me too. Shortly after posting this. :P/>

@Dib't: Dream.In.Code is probably one of the very few places on the internet where you don't need to worry about people being rude when you need help. I'd avoid the caffeine lounge if you're susceptible to trolling, though. :)/>


Thanks for the advice (I can't seem to find the edit post button, do I have to have a certain amount of post before it shows or something?)
Was This Post Helpful? 0
  • +
  • -

#9 macosxnerd101   User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12324
  • View blog
  • Posts: 45,424
  • Joined: 27-December 08

Re: Problem with activating program?

Posted 26 July 2013 - 07:56 AM

Quote

@Purple, I'm doing what eclipse says. I've fix my 1st problem with the message being sent twice and now my concern/question is http://prntscr.com/1hkqjd

Yes- I can and did read that part. :rollseyes:

What I'm trying to do is get you to talk me through your design choices. What you are doing right now is throwing code at things hoping they will work. This is a bad approach. Everything you write, you should be able to justify in terms of your code.

Remember that classes model objects. So why should an Engine be responsible for managing inventory or reading from a File? It shouldn't. An Engine should be responsible for being the backbone of the car. It really doesn't make sense to me that you have an ItemManager in your Engine class.

Quote

@Red, I've updated so everything looks like this now

Again- you didn't answer the question. Stop throwing code and start trying to think things through.
Was This Post Helpful? 0
  • +
  • -

#10 Dib't   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 25-July 13

Re: Problem with activating program?

Posted 26 July 2013 - 09:02 AM

View Postmacosxnerd101, on 26 July 2013 - 07:56 AM, said:

Quote

@Purple, I'm doing what eclipse says. I've fix my 1st problem with the message being sent twice and now my concern/question is http://prntscr.com/1hkqjd

Yes- I can and did read that part. :rollseyes:

What I'm trying to do is get you to talk me through your design choices. What you are doing right now is throwing code at things hoping they will work. This is a bad approach. Everything you write, you should be able to justify in terms of your code.

Remember that classes model objects. So why should an Engine be responsible for managing inventory or reading from a File? It shouldn't. An Engine should be responsible for being the backbone of the car. It really doesn't make sense to me that you have an ItemManager in your Engine class.

Quote

@Red, I've updated so everything looks like this now

Again- you didn't answer the question. Stop throwing code and start trying to think things through.


The point of my engine class is to activate everything, it'll load the system for the items and npcs, and I think that's about it for now.
Was This Post Helpful? 0
  • +
  • -

#11 jjh08   User is offline

  • D.I.C Head

Reputation: 55
  • View blog
  • Posts: 198
  • Joined: 13-July 12

Re: Problem with activating program?

Posted 26 July 2013 - 11:04 AM

Quote

The point of my engine class is to activate everything, it'll load the system for the items and npcs, and I think that's about it for now.

Sorry OP. That still doesn't make sense. You will probably want to do as mac said and change that class Engine into something else. Just glancing at the code, since the class has a method called loadmanagers(), won't it make sense to call it public class Loader or something like that?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1