Access to Class information from a static method

There does not appear to be anyway to access the Class object from instead a static method.
e.g. How could I convert the following code so that it works ?
class test {
static void printClassName() {
System.out.println( getClass().getName() );

The idea was to have a static method that could be
used to make a lookup based on the classname. Being
able to access the class name would mean that I would
not have to reimplement for every subclass !!!!!Hmm.. what are you trying to look up? Some kind of class-specific constant information maybe?
In general your best bet is to define an abstract method in your parent class for return of the constant value, then define a specific method in each sub-class that overrides it, retrurning the appropriate value.
Then you're common processing just gets the value with that method.
Using some kind of lookup on the basis of class name is much clumsier, and more inclined to run time errors. Better to use the built in virtual methods table.
Another approach is to have the value as a parameter of the constructor of the parent class and use "super(value)" in the child classes to store
it.

Similar Messages

  • Calling non-static command from within static method

    Hello,
    I have a static method that reads bytes from serial port, and I want to set a jTextField from within this method. but I get error that says it is not possible to call non static method from a static one. How can it be solved?

    ashkan.ekhtiari wrote:
    No, MTTjTextField is the name of jTextFiled class instance.You haven't declared any such variable in the class you posted, not to mention that such a variable name violates standard code conventions.
    This is and instance of that object actually. You haven't declared any such variable in the class you posted.
    the problem is something else. No, it isn't, based on the information you have provided. If you want accurate guidance, don't post misleading information about your problem.
    It can not be set from within static method.A question commonly asked on Java forums concerns an error message similar to the following:
    non-static variable cannot be referenced from a static context
    In Java, static means "something pertaining to an object class". Often, the term class is substituted for static, as in "class method" or "class variable." Non-static, on the other hand, means "something pertaining to an actual instance of an object. Similarly, the term instance is often substituted for non-static, as in "instance method" or "instance variable."
    The error comes about because static members (methods, variables, classes, etc.) don't require an instance of the object to be accessed; they belong to the class. But a non-static member belongs to an instance -- an individual object. There's no way in a static context to know which instance's variable to use or method to call. Indeed, there may not be any instances at all! Thus, the compiler happily tells you that you can't access an instance member (non-static) from a class context (static).
    Once you understand this concept, you can fix your own problem.
    ~

  • Calling a method from a static method

    hello all,
    I'm calling a non-static method from a static method (from the main method). To overcome this i can make the method i am calling static but is there another way to get this to work without making the method that is being called static?
    all replies welcome, thanks

    When you call a non-static method, you are saying you are calling a method on an object. The object is an instance of the class in which the method is defined. It is a non-static method, because the instance holds data in it's instance variables that is needed to perform the method. Therefore to call this kind of method, you need to get (or create an instance of the class. Assuming the two methods are in the same class, you could do
    public class Foo
         public static void main(String[] args)
                Foo f = new Foo();
                f.callNonStaticMethod();
    }for instance.

  • Pass an object from a static method

    Hi,
    I'm trying to pass a reference to an object from a static method, but I get an error when compiling.
    Say for example I have this:
    public class obj1 {
    public void myMethod (int i, Object ob, etc...) {
    ...and I want to call this method from a method that looks like this:
    public class obj2 {
    public static int anotherMethod(...) {
    obj1.myMethod(1,this,...);
    ...Can I pass a reference from obj2 to obj1 any other way?
    Thanks alot.

    how can I get a reference to obj2 then?Pay no attention to zdude's answer - it's nonsense.
    You're confused about basic Java concepts. obj2 is a class, not an object. References point to objects, not classes. There is no obj2 object in the code you show, so you cannot have a reference to an obj2 object.
    Maybe if you post some more code, we can get an idea of what you're trying to do. You might want to try the New to Java forum.

  • Error on Desktop: iTunes unable to load data class information from sync services.

    Error on Desktop; iTunes unable to load data class information from sync services.

    Hi there Randall112,
    You may find the troubleshooting steps in the article below helpful.
    iTunes for Windows: "Unable to load data class" or "Unable to load provider data" sync services alert
    http://support.apple.com/kb/ts2690
    -Griff W. 

  • When trying to sync my I Phone 4 to I tunes I am getting a message: Unable to Data class information from Sync Services. What does this mean?

    When I-tunes is trying to sync my phone, I get a message regarding Data Class Information from Sync Services saying they were unable to do this.  I have no idea what this means.  I have not been having any problems with syncing info from my computer to phone until just now.  I am trying to install new alert tones from an app that I purchased.  The alert ones are now in my library on I-tunes and they play but they are not syncing to my phone.  The snycing options is not available in my library and when I try to manually sync these tones, nothing is happening.  I recently purhcased ringtones from the I-tunes store and from my phone and they downloaded with no problems and are synced onto my computer and are showing up in the same library list as the tone alerts which I cannot seem to sync.  I have no idea why this is.  Please help!

    In the course of your troubleshooting to date, have you worked through the following document?
    iTunes for Windows: "Unable to load data class" or "Unable to load provider data" sync services alert

  • TS2529 iTunes was unable to load data class information from Sync Services. Reconnect or try again later is the error message I am getting when i connect my iphone 4 to my windows based computer. Any help out there?

    iTunes was unable to load data class information from Sync Services. Reconnect or try again later. This is the message when I try to connect my iphone 4 to my computer. If anyone could help me with this, I would appreciate it.

    iOS: Device not recognized in iTunes for Windows
    http://support.apple.com/kb/TS1538
    iOS: Device not recognized in iTunes for Mac OS X
    http://support.apple.com/kb/ts1591

  • I keep getting this error message: ITunes was unable to load data class information from Synch Services. Reconnect or try again later. What does that mean? Can I fix it? or do I have to wait for the next update?

    I keep getting this error message: ITunes was unable to load data class information from Synch Services. Reconnect or try again later. What does that mean? Can I fix it? or do I have to wait for the next update?

    See TS2690: iTunes for Windows: "Unable to load data class" or "Unable to load provider data" sync services alert.
    tt2

  • ITunes was unable to load data class information from Sync Services. Reconnect or try again later.

    Ever since I upgraded to iTunes 10.4 I've been getting this dreaded message on many occasions when I try to sync my iPhone 4 or iPad 2 with my Win 7 64 bit machine. "iTunes was unable to load data class information from Sync Services. Reconnect or try again later." What happens is that local content (music, videos etc) will sync properly to my iPhone, but other content (such as Outlook information, MobileMe stuff, etc) will not.
    I have uninstalled and completely purged all Apple data from my PC (including hidden files and folders under Common Files and in the Registry) and reinstalled iTunes. Yet after one or two syncs, the same problem resurfaces. The other weird part is that the Sync Services crap-out message will happen after I do a successful sync, leave the iPhone connected to the PC, and don't even touch the computer for several hours.
    I've actually developed a very tedious work around that seems to restore syncing if for a short time.
    - Undock/unconnect all Apple devices from the PC.
    - Close iTunes, MobileMe control panel, and Safari (if you have it).
    - Start Task Manager (Ctrl + Alt + Del) and shut down iTunesHelper.exe and SyncServer.exe
    - Open up a Windows Explorer window (like My Computer) and under Tools, Folder Options, View, toggle on Show Hidden Files and toggle off Hide Protected Operating System FIles
    - In WIndows Explorer, navigate to "C:\Users\<your name>\App Data\Roaming\Apple Computer". Rename the folder Sync Services to something else, like Sync Services_Old.
    - In WIndows Explorere, navigate to "C:\Program Files (x86)\Common Files\Apple\Mobile Device Support" and double-click on AppleSyncNotifier.exe.
    - Go back to your Folder Options and turn off SHow Hidden Files and toggle on Hide Protected Operationg System Files
    Now you can start up iTunes again and connect your device. It should sync properly again (at least, until it doesn't once more).
    Does anyone at Apple have any idea about this error or a solution?

    I actually spent a fair amount of time on the phone with a senior Apple tech last week. He directed me to this topic:
    http://support.apple.com/kb/HT1923?viewlocale=en_US
    It's important that you go through the steps EXACTLY as described here and in the proper order. Also make sure MobileMe control panel is uninstalled (if you have it).
    Interestingly, when I went through this procedure and then reinstalled iTunes 10.4 64-bit  (didn't do MobileMe or Safari at this stage, but QT is automatically installed) everything worked perfectly. The aforementioned error messages disappeared and all is working flawlessly, as it should.
    I hope my expereince will help! Give it a try.

  • ITunes was unable to load data class information from sync services.

    I get the error message "iTunes was unable to load data class information from sync services. Reconnect or try again later" after reinstalling iTunes. I cancel the message and iTunes proceeds to sync with my iPhone 4. The phone and iTunes software are the latest releases. My PC is running Windows 8.1, which had to be reinstalled after the system crashed, requiring a total reinstall of all software.

    Doublechecking. You've tried the following document?
    iTunes for Windows: "Unable to load data class" or "Unable to load provider data" sync services alert

  • Itunes was unable to load data class information from sync services.Reconnect and try again later.

    when I open itunes I get message " itunes was unable to load data class information from sync services. reconnect or try again later "
    I am unable to sync my ipad 2 or iphone 4 through itunes. I have tried all suggested options, removing itunes and related components from control panel + verified completely uninstalled from C program files + then reinstalling latest version of itunes (version 11.3.1.2). Also tried running itunes as administrator. Also tried reset sync history in itunes  Also tried system restore on windows 7 from earlier period.Still get the same above message.
    I run 64bit windows 7. Have recently renewed my Norton Intenet Security. Everything was OK up till then. Could this have anything to do with it.

    A quick cursory browse seems to point that the problem is on Apples end since the last update of iTunes, theres loads of forum posts about it but Apple themselves arent responding as yet other then the usual "unplug, delete sync data, reconnect or completely uninstall iTunes" spiel which doesnt work so hopefully they will fix it sooner or later

  • I get this message when i try to sync and download my iphone:  itunes was unable to load data class information from sync services, reconnect or try again later.  what does that mean and who do you fix it

    I get this message when i try to sync and download my iphone,   ITUNES was unable to load data class information from sync services,  reconnect or try again later.    this has happened twice.  i have not downloaded by phone in several months.  the first time i got this message i did not understand i and left my phone plug in for 12 hrs and it never did anything.   today.  when i got the message i just unplugged it.
    help

    http://support.apple.com/kb/TS2690?viewlocale=en_US&locale=en_US

  • HT1386 my ipad won't sink; I continually get message:  itunes was unable to load data class information from Sync Services. Reconnect or try again later.  I have done both several times and still receive same messaage.

    My iPad won't sink with my computer.  I continually receive this message: "iTunes was unable to load data class information from Sync Services.  Reconnect or try again later."  I have tried this over a number of days and receive the same message.  Any suggestions??

    IOS: Syncing with iTunes
    http://support.apple.com/kb/HT1386
    Apple - Support - iPad - Syncing
    http://www.apple.com/support/ipad/syncing/
    ITunes: Syncing media content to your iOS devices
    http://support.apple.com/kb/ht1351
    There are some similar posts on the right side of this page (More Like This). Look at those posts.
     Cheers, Tom

  • HT1766 I keep getting the following message, Unable to load data class information from Sync Services

    I keep getting the following message when I try to sync. Unable to load data class information from service. Reconnect or try again late

    Try this
    iTunes for Windows: "Unable to load data class" or "Unable to load provider data" sync services alert

  • HT1369 hey, when I connect either my ipod or ipad to itunes I get the promt ' i tunes was unable to load data class information from sync services. Reconnect or try again later'. Can anyone help me with syncing my devices?? Thanks in advance

    Hey, when I connect either my ipod or ipad to itunes I get the prompt 'itunes was unable to load data class information from sync services. Reconnect or try again later. Can anyone help me with syncing my devices?? Thanks in advance

    I am having the same issue, anyone else ?

Maybe you are looking for

  • Custom: use constant value in relationship between objects?

    I have two related classes: * Class A uses application identity, and has multiple PK fields, PK1 and PK2. * Class B has a 1-many relationship with class A. However, class B's database table only has a column that relates to Class A's PK2 column. (the

  • Why cant I convert a word document to PDF?

    If its free why cant I convert a word document to a PDF file?

  • Iphone not in my devices

    Hi, I have had an iPhone 3GS for 2 years, about 6 months ago, iTunes on my PC (Windows XP) stopped recognising my iPhone. The PC recognises it (ie. it shows up as a camera in My Computer and I can grab photos off of it.) I didn't find it too much of

  • My "Sync Session" won't start on my iPod Touch 4th Gen

    The session started fine but halfway through, it stopped working and now I can't sync any songs on my ipod.

  • Setting file paths

    Is there any way I can programmatically tell java.io classes to assume that file paths are within the source file directory? I'm asking because the sdk does this by default but, by running in debug directories, NetBeans changes this.