Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[TUT]GLOBAL VARIABLES FOR JAVA!!![TUT]
#2
Try using that static field with a non-static method. ;) It wont work.
Another way is to first create a public field like so,
Code:
public int globalInt = 0; // idk
Make sure you keep public at the beginning or it doesnt work.

Then in the class you want to call it from, you create an object of the other class and call it like this,
Code:
GlobalDataStore gDS; // invokes the GlobalDataStore class

public void someMethod() {
  gDS.globalInt = 1; // calls the variable, and sets it to 1
}

This will work with any non-static methods. But the way one you posted only works with static methods. Understand?
My SMF Modifications:
http://anthony.vibrantvps.com/smf
Reply


Messages In This Thread
RE: [TUT]GLOBAL VARIABLES FOR JAVA!!![TUT] - by Project Evolution - 03-14-2010, 09:12 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  why java haphazard 8 1,757 12-12-2011, 03:23 AM
Last Post: RDCA
  Need Java help from java expert. Blazin 2 2,093 09-07-2011, 02:43 PM
Last Post: AceInfinity
  [TuT] Getting started with Java Programming! BlackSpider 53 16,248 08-03-2011, 03:05 AM
Last Post: Deceive
  Tabbed Pane Tut Buhrock 1 998 12-23-2010, 09:45 PM
Last Post: Bourd
  Java help php 1 1,033 04-06-2010, 06:41 AM
Last Post: php

Forum Jump:


Users browsing this thread: 1 Guest(s)