Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 12 of 12

Thread: My code has a problem ;)

  1. #1
    Member
    Join Date
    Aug 2013
    Location
    Reykjavik, Iceland
    Posts
    51
    Thanks
    37
    Thanked 0 Times in 0 Posts

    Default My code has a problem ;)

    package tilraunir;
    import java.applet.Applet;
    import java.awt.*;


    public class Klukka extends Applet
    {
    /**
    *
    */
    private static final long serialVersionUID = 1L;
    TextField t1, tSvar;
    Button bReikna;
    Label a1;
    Integer I;
    int i, sek, min;

    public void init()
    {
    t1 = new TextField (5);
    tSvar = new TextField (25);
    bReikna = new Button ("Reikna mínútur");//Calculate minutes
    a1 = new Label ("Sekúndur");

    this.add(a1);
    this.add(t1);
    this.add(bReikna);
    this.add(tSvar);
    }

    public boolean action(Event e, Object o)
    {
    if (e.target == bReikna)
    {
    I = new Integer(t1.getText());
    i = I.intValue();
    min = i / 60;
    sek = i % 60;
    tSvar.setText(i + " sek. er " + min + " mín. og " + sek + " sek.");
    return true;
    }
    return false;
    }
    }
    Last edited by einar123; August 5th, 2013 at 03:54 PM. Reason: Trying to fix the syntax


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,166
    My Mood
    Hungover
    Thanks
    141
    Thanked 597 Times in 512 Posts

    Default Re: My code has a problem ;)

    When posting code, please use the highlight tags to preserve formatting.

    What seems to be the problem with this code? Does it compile? Does it run? Does it display a runtime error? Some strange behavior? Something else?

    See the link in my signature on asking questions the smart way, and we'll go from there.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. The Following User Says Thank You to KevinWorkman For This Useful Post:

    einar123 (August 5th, 2013)

  4. #3
    Junior Member ChainDev's Avatar
    Join Date
    Aug 2013
    Location
    Home :)
    Posts
    10
    My Mood
    Inspired
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Default Re: My code has a problem ;)

    1. Why do you compile with an online compiler? When eclipse does it when you run?
    2. Here is your answer. Java is CaSe SeNsItIvE with file names.

    In here :
    public class Klukka extends Applet //Klukka means a clock in English
    change it to :
    public class Klukka extends Applet //Klukka means a clock in English

    What did i do? Small "k" letter

    Edit :/ If your filename is
    Klukka.java
    change it to
    klukka.java

  5. The Following User Says Thank You to ChainDev For This Useful Post:

    einar123 (August 5th, 2013)

  6. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,166
    My Mood
    Hungover
    Thanks
    141
    Thanked 597 Times in 512 Posts

    Default Re: My code has a problem ;)

    Standard naming conventions dictate that class names should start with a capital letter. The filename of the public class needs to be the same as the class itself, in this case Klukka.java.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #5
    Junior Member ChainDev's Avatar
    Join Date
    Aug 2013
    Location
    Home :)
    Posts
    10
    My Mood
    Inspired
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Default Re: My code has a problem ;)

    Quote Originally Posted by KevinWorkman View Post
    Standard naming conventions dictate that class names should start with a capital letter. The filename of the public class needs to be the same as the class itself, in this case Klukka.java.
    Actually the same answer what i typed.
    Two options ;
    1. Change file name (your java file)
    Klukka.java
    to
    klukka.java
    OR
    2. Change what's inside the java file.
    public class Klukka extends Applet //Klukka means a clock in English
    to
    public class klukka extends Applet //Klukka means a clock in English

  8. The Following User Says Thank You to ChainDev For This Useful Post:

    einar123 (August 5th, 2013)

  9. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,166
    My Mood
    Hungover
    Thanks
    141
    Thanked 597 Times in 512 Posts

    Default Re: My code has a problem ;)

    Quote Originally Posted by ChainDev View Post
    Actually the same answer what i typed.
    I am aware that you gave two options. Unfortunately, only one of them was what the OP should actually do. Renaming the class in the code to klukka with a lowercase k might fix the problem, but it establishes a pretty bad habit of violating the standard naming conventions. I was correcting you, not disagreeing with you.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  10. #7
    Member
    Join Date
    Aug 2013
    Location
    Reykjavik, Iceland
    Posts
    51
    Thanks
    37
    Thanked 0 Times in 0 Posts

    Default Re: My code has a problem ;)

    Hahah-WOW!
    THANKS!
    I'll use the next 24 hours to process the replies And try to feed the children and doing some housework

    KevinWorkman I don't see the link in your signature-My it knowledge...I'm just not there yet

  11. #8
    Junior Member ChainDev's Avatar
    Join Date
    Aug 2013
    Location
    Home :)
    Posts
    10
    My Mood
    Inspired
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Default Re: My code has a problem ;)

    Quote Originally Posted by KevinWorkman View Post
    I am aware that you gave two options. Unfortunately, only one of them was what the OP should actually do. Renaming the class in the code to klukka with a lowercase k might fix the problem, but it establishes a pretty bad habit of violating the standard naming conventions. I was correcting you, not disagreeing with you.
    Haha, okay I understand you. But i didn't know about that "bad habit" thing

    Quote Originally Posted by einar123 View Post
    Hahah-WOW!
    THANKS!
    I'll use the next 24 hours to process the replies And try to feed the children and doing some housework

    KevinWorkman I don't see the link in your signature-My it knowledge...I'm just not there yet
    & No problem (:

    & If you don't see his/her Signature, check this page :

    http://www.javaprogrammingforums.com...inworkman.html
    and click "About me", there is his/her signature.

    & KevinWorkman, is your signature supposed to be shown on posts?
    As we can't see it.

  12. The Following User Says Thank You to ChainDev For This Useful Post:

    einar123 (August 5th, 2013)

  13. #9
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,166
    My Mood
    Hungover
    Thanks
    141
    Thanked 597 Times in 512 Posts

    Default Re: My code has a problem ;)

    Hmm I can see signatures. Are you guys on mobile or something? Oh well, no big deal.

    And the standard naming conventions should definitely be followed: Code Conventions for the Java Programming Language
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  14. The Following User Says Thank You to KevinWorkman For This Useful Post:

    einar123 (August 5th, 2013)

  15. #10
    Junior Member ChainDev's Avatar
    Join Date
    Aug 2013
    Location
    Home :)
    Posts
    10
    My Mood
    Inspired
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Default Re: My code has a problem ;)

    Quote Originally Posted by KevinWorkman View Post
    Hmm I can see signatures. Are you guys on mobile or something? Oh well, no big deal.

    And the standard naming conventions should definitely be followed: Code Conventions for the Java Programming Language
    Using Google Chrome on a PC.
    & Thanks for info (:

  16. The Following User Says Thank You to ChainDev For This Useful Post:

    einar123 (August 5th, 2013)

  17. #11
    Member
    Join Date
    Aug 2013
    Location
    Reykjavik, Iceland
    Posts
    51
    Thanks
    37
    Thanked 0 Times in 0 Posts

    Default Re: My code has a problem ;)

    Hey you! Masters of Javacode

    There is something wrong with my boolean

    When I compile it I get this: java.lang.NullPointerException
    The compiler points out that there is somthing about a1 in init-line 23

    Can you see what it is?

    Should I use something different from:

    I = new Integer(t1.getText());
    i = I.intValue();

    --- Update ---

    I've got it. It works now-Thanks for your help.

    How do I keep the syntax in order. I copy paste the code and it seems fine until i enter save then the indexing just disapears?

    Again Thanks-It's fun

  18. #12
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

    Default Re: My code has a problem ;)

    Quote Originally Posted by einar123 View Post
    How do I keep the syntax in order
    Code tags are discussed on the Announcements page in section 1

Similar Threads

  1. Problem with code.
    By heythisgreg in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 3rd, 2013, 04:44 PM
  2. what's problem with this code?
    By ashik16 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 12th, 2012, 11:32 AM
  3. I am in problem with my code
    By mohakal06r in forum Member Introductions
    Replies: 2
    Last Post: February 26th, 2012, 12:03 AM
  4. problem in my code java code graph editeur
    By kisokiso in forum Java Theory & Questions
    Replies: 5
    Last Post: January 6th, 2012, 07:36 AM
  5. problem in my code
    By dhruvguys in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 11th, 2011, 05:18 AM