Results 1 to 6 of 6
  1. #1
    JavaLava is offline Member
    Join Date
    Jun 2013
    Posts
    3
    Rep Power
    0

    Question Print Line Error

    Java Code:
    package Project;
     
    public class Java 
    {   
        public static void main(String[] args)
        {
            System.out.println(EnumT.lor);
        }
    }
    Java Code:
    package Project;
     
    public enum EnumT 
    {
        Cobalt (new float[]{1/2f, 2/2f, 3/2f});
         
        private float[] cobaltArray;
         
        private EnumT(float[] par1ArrayOfFloat)
        {
            this.cobaltArray = par1ArrayOfFloat;
        }
         
        public static float lor;
        
        private void lorSet()
        {
        lor = cobaltArray[1];
        }
    }
    Sorry ignore title I fixed that error. Now I get the ";" in "public static float lor;" within enumT underlined in red. Any ideas?
    Last edited by JavaLava; 06-24-2013 at 05:54 AM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Print Line Error

    Before anything else, class (and enum and interface) names should always start with an uppercase letter. So, Enum7, not enum7. On the other hand, variable and method names should always start with a lowercase letter. So, cobaltArray, not CobaltArray.
    Code Conventions for the Java Programming Language: Contents

    Executable statements like lor = ... are not permitted in the body of a class, only in methods. But first, you need to better your understanding of what the keyword static means: Understanding Instance and Class Members (The Java™ Tutorials > Learning the Java Language > Classes and Objects)

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    JavaLava is offline Member
    Join Date
    Jun 2013
    Posts
    3
    Rep Power
    0

    Question Re: Print Line Error

    Okay thanks I fixed the code (refer to OP). But now when the value is read it returns 0.0 instead of 1.0. How do I get it to read a value from the array?

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Print Line Error

    Please don't repeatedly edit your OP after there are responses as that removed the context of the reply.

    You still haven't got the point of using static members. What happens when your enum has more than one constant?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    JavaLava is offline Member
    Join Date
    Jun 2013
    Posts
    3
    Rep Power
    0

    Default Re: Print Line Error

    Sorry about that. So by using static I make it so that the variable is specific to the class and not for every object of that method.

    "What happens when your enum has more than one constant?"

    God helps me? So is it giving me zero because its static and tied to the EnumT class? It an throws error if I remove it. Sorry for noobiety, I'm trying very hard to learn.
    Last edited by JavaLava; 06-24-2013 at 06:39 AM.

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Print Line Error

    I gave you a link to a tutorial. Have you gone through it?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Where does he print this certain line?
    By Lund01 in forum Advanced Java
    Replies: 6
    Last Post: 11-18-2010, 02:23 PM
  2. print every other line
    By welikedogs in forum New To Java
    Replies: 23
    Last Post: 11-16-2010, 05:40 PM
  3. print to the next line
    By bar in forum New To Java
    Replies: 14
    Last Post: 07-15-2010, 01:48 AM
  4. Print to next Line
    By singularity in forum New To Java
    Replies: 13
    Last Post: 09-10-2009, 09:03 AM
  5. print line
    By kazitula in forum Java Applets
    Replies: 2
    Last Post: 01-26-2008, 02:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •