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 14 of 14

Thread: 2 questions(an error and line breakpoint?)

  1. #1
    Member
    Join Date
    May 2011
    Location
    west palm beach, FL
    Posts
    189
    My Mood
    Tired
    Thanks
    41
    Thanked 11 Times in 10 Posts

    Default 2 questions(an error and line breakpoint?)

    ok i made this and when i try to run it i get a compilation error and i have a question about something im seeing on eclipse

    package wlodmgcalc;
     
    import javax.swing.*;
    import java.awt.*;
    import java.awt.Event.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
     
    public class wlocalc extends JFrame implements ActionListener, ItemListener {
     
    	public wlocalc() {
    		super("Dmg Calculator");
    		setSize(200, 210);
    		setBackground(Color.white);
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		FlowLayout flow = new FlowLayout(FlowLayout.LEFT);
    		setLayout(flow);
     
    		JPanel row1 = new JPanel();
    		JLabel atkLabel = new JLabel("Attack:");
    		row1.add(atkLabel);
    		JTextField atk = new JTextField(7);
    		row1.add(atk);
    		add(row1);
     
    		JPanel row2 = new JPanel();
    		JLabel elementLabel = new JLabel("Element:");
    		row2.add(elementLabel);
    		String[] elements = { "Wind", "Fire", "Water", "Earth" };
    		JComboBox elementBox = new JComboBox(elements);
    		elementBox.setSelectedIndex(2);
    		row2.add(elementBox);
    		add(row2);
     
    		JPanel row3 = new JPanel();
    		FlowLayout flowbutton = new FlowLayout(FlowLayout.CENTER, 50, 10);
    		row3.setLayout(flowbutton);
    		JButton calculate = new JButton("Calculate");
    		calculate.addActionListener(this);
    		row3.add(calculate);
    		add(row3);
     
    		JPanel row4 = new JPanel();
    		JLabel totalLabel = new JLabel("Damage: ");
    		JTextField damageTotal = new JTextField(5);
    		row4.add(totalLabel);
    		row4.add(damageTotal);
    		damageTotal.setEditable(false);
    		add(row4);
     
    		pack();
    		setVisible(true);
     
    		atk.addItemListener(this);
    	}
     
    	public void actionPerformed(ActionEvent event) {
    		String atkNumber = atk.getActionCommand();
    		String pressed = event.getActionCommand();
    		if (pressed.equals("Calculate")) {
    		System.out.println(atkNumber);	
    		}
    	}
     
    	public static void main(String[] args) {
    		wlocalc dmg = new wlocalc();
    	}
    }

    the error i get is

    Exception in thread "main" java.lang.Error: Unresolved compilation problem:

    at wlodmgcalc.wlocalc.main(wlocalc.java:65)
    and the other question i have is 1 line in eclipse has a little purple dot next to it and says
    "Line Breakpoint:wlocalc [line:24] - wlocalc()"

    no idea what that means and i dont see anything wrong with line 65 either so im pretty lost. any help is very much appreciated thanks


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

    Default Re: 2 questions(an error and line breakpoint?)

    I'd recommend compiling from the command line until you understand these kinds of messages. Which line is number 65? Apparently it contains a compiler error. And have you googled "eclipse breakpoint" or something similar?
    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. #3
    Member
    Join Date
    May 2011
    Location
    west palm beach, FL
    Posts
    189
    My Mood
    Tired
    Thanks
    41
    Thanked 11 Times in 10 Posts

    Default Re: 2 questions(an error and line breakpoint?)

    ill google the breakpoint and see what comes up

    line 65 it says is

    public static void main(String[] args) {

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

    Default Re: 2 questions(an error and line breakpoint?)

    Quote Originally Posted by derekxec View Post
    ill google the breakpoint and see what comes up

    line 65 it says is

    public static void main(String[] args) {
    You need to get the actual compiler error, which eclipse should give you before you even try to run anything. But if you can't figure out eclipse, I seriously recommend compiling from the command line.
    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!

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

    derekxec (July 21st, 2011)

  6. #5
    Member
    Join Date
    May 2011
    Location
    west palm beach, FL
    Posts
    189
    My Mood
    Tired
    Thanks
    41
    Thanked 11 Times in 10 Posts

    Default Re: 2 questions(an error and line breakpoint?)

    usually i get some errors or so but when i try to run thats what comes up and the program terminates and i have some markers showing but not sure how to fix them...im having trouble getting how to make a gui work with my program its not getting through my thick skull lol

  7. #6
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,469
    My Mood
    Grumpy
    Thanks
    0
    Thanked 159 Times in 150 Posts

    Default Re: 2 questions(an error and line breakpoint?)

    wlocalc.java:7: cannot find symbol
    symbol: class ItemListener
    public class wlocalc extends JFrame implements ActionListener, ItemListener {
    ^
    wlocalc.java:52: cannot find symbol
    symbol : method addItemListener(wlocalc)
    location: class javax.swing.JTextField
    atk.addItemListener(this);
    ^
    wlocalc.java:56: cannot find symbol
    symbol : variable atk
    location: class wlocalc
    String atkNumber = atk.getActionCommand();
    ^
    3 errors

    Those are the errors I get. I don't know what you are doing.
    Improving the world one idiot at a time!

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

    derekxec (July 21st, 2011)

  9. #7
    Member
    Join Date
    May 2011
    Location
    west palm beach, FL
    Posts
    189
    My Mood
    Tired
    Thanks
    41
    Thanked 11 Times in 10 Posts

    Default Re: 2 questions(an error and line breakpoint?)

    weird i dont see any of that one mine usually i get red X or so on the left side with errors but none there now lol

    the linebreak i found was cause i went into debug mode to try it out and i guess the program stopped there but i toggled it off maybe thats why im having so much problems with it

  10. #8
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,469
    My Mood
    Grumpy
    Thanks
    0
    Thanked 159 Times in 150 Posts

    Default Re: 2 questions(an error and line breakpoint?)

    I got those errors when compiling on the command line. Something you were advised to do twice and totally ignored.
    Improving the world one idiot at a time!

  11. #9
    Member
    Join Date
    May 2011
    Location
    west palm beach, FL
    Posts
    189
    My Mood
    Tired
    Thanks
    41
    Thanked 11 Times in 10 Posts

    Default Re: 2 questions(an error and line breakpoint?)

    when i tried on command line i got an "is not recognized as an internal or external command operable program or batch file" and it wouldnt do anything

  12. #10
    Member goldest's Avatar
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    63
    Thanks
    1
    Thanked 12 Times in 10 Posts

    Cool Re: 2 questions(an error and line breakpoint?)

    Quote Originally Posted by derekxec View Post
    when i tried on command line i got an "is not recognized as an internal or external command operable program or batch file" and it wouldnt do anything
    Which means you haven't set your environment variables to use Java yet.

    Have a look how to do that here: Configure Java environment on Windows

    Hope that helps,

    Goldest
    Java Is A Funny Language... Really!

    Sun: Java Coding Conventions

    Click on THANKS if you like the solution provided.
    Click on Star if you are really impressed with the solution.

  13. #11
    Member
    Join Date
    May 2011
    Location
    west palm beach, FL
    Posts
    189
    My Mood
    Tired
    Thanks
    41
    Thanked 11 Times in 10 Posts

    Default Re: 2 questions(an error and line breakpoint?)

    i did that but maybe i didnt do correctly ill double check it to make sure but even when i go to the directory that the compiler is in and put all there it says it too but if i run a .jar like java -jar heh.jar it runs fine?

    ill double check and thanks for all the info

    one other question if you all dont mind

    import java.awt.*

    this doesn't add all of the java.awt. stuff?
    Last edited by derekxec; July 21st, 2011 at 11:37 AM.

  14. #12
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,469
    My Mood
    Grumpy
    Thanks
    0
    Thanked 159 Times in 150 Posts

    Default Re: 2 questions(an error and line breakpoint?)

    Quote Originally Posted by derekxec View Post
    when i go to the directory that the compiler is in and put all there
    Do not place your Java files in the Java installation directory. Keep your files elsewhere. If you have set up the environment variables correctly you can compile and run your Java programs anywhere on the computer.

    import java.awt.*

    this doesn't add all of the java.awt. stuff?
    The * is not recursive. Therefore any classes in the event subpackage (or any other subpackage) will not be imported. Personally I dislike using the * and add an explicit import statement for each class I use. One reason is:
    import java.sql.*;
    import java.util.*;
     
    class Kaboom {
        Date d; // error due to Date class in both sql and util packages.
    }
    Improving the world one idiot at a time!

  15. #13
    Member
    Join Date
    May 2011
    Location
    west palm beach, FL
    Posts
    189
    My Mood
    Tired
    Thanks
    41
    Thanked 11 Times in 10 Posts

    Default Re: 2 questions(an error and line breakpoint?)

    ah thank you that explains the first error i guess ill stop using the * too and save some hassle thanks a lot

    im checking the path out right now hopefully i just made some mistake in the path or so

  16. #14
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    471
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: 2 questions(an error and line breakpoint?)

    In my experience, clashes don't happen very often, and when they do (e.g. you need to use both classes, or as in the case above), you just have to explicitly qualify one class (usually the one you use least). With wildcard imports, you can add an explicit import for the clashing type you actually use (or use most often if you use both), and explicitly qualify the clashing type you use least. The compiler warns you when there's an unresolved name clash, so it's no problem.

    For example, if you use java.util.Date more in the code than java.sql.date, you could do this:
    import java.sql.*;
    import java.util.*;
    import java.util.Date; // explicitly import the class you use (or use most often) when there's a name clash.
     
    class NoProblem {
        Date d;                 // by default will use java.util.Date because of explicit import
        java.sql.Date s;      // to use java.sql.Date you need to explicitly specify its package
    }
    Of course, this is only needed when you're using many classes from a single package and there's a name clash with another package, and you want to avoid a rash of unnecessary import statements. The explicit import of one class and the explicit qualification of the other make it pretty clear which is which in the code.

    Most decent IDEs will have a setting where you can specify the number of separate imports from a single package at which the separate import statements will replaced by a single wildcard import. Wildcard imports are optional, but they're provided for a good reason.

  17. The Following User Says Thank You to dlorde For This Useful Post:

    derekxec (July 24th, 2011)

Similar Threads

  1. [SOLVED] How to make a more than one line JLabel or drawString for more than one line.
    By javapenguin in forum What's Wrong With My Code?
    Replies: 9
    Last Post: June 4th, 2011, 02:16 PM
  2. Reading a file line by line using the Scanner class
    By JavaPF in forum File Input/Output Tutorials
    Replies: 0
    Last Post: April 17th, 2009, 07:34 AM
  3. Reading a file line by line using the Scanner class
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: April 17th, 2009, 07:34 AM
  4. How to Read a file line by line using BufferedReader?
    By JavaPF in forum File Input/Output Tutorials
    Replies: 0
    Last Post: May 19th, 2008, 06:32 AM
  5. How to Read a file line by line using BufferedReader?
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: May 19th, 2008, 06:32 AM