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

Thread: Trying to follow tutorial. Embarrassingly stuck.

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    9
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Trying to follow tutorial. Embarrassingly stuck.

    Hi guys, I'm just starting to learn java so I've been looking around for good tutorials. Right now I'm on this one Developing General Java Applications - NetBeans IDE Tutorial

    on the Debugging the Application section.

    Every time I try to hit Run Project I get the <No Main Class Found> error.

    Here is my code.

    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package org.me.mylib;
     
    /**
     *
     * @author One
     */
    public class LibClass {
        public static String acrostic(String[] args) {
            StringBuffer b = new StringBuffer();
            for (int i = 0; i < args.length; i++) {
                if (args[i].length() > i) {
                    b.append(args[i].charAt(i));
                } else {
                    b.append('?');
                }
            }
            return b.toString();
        }
    }

    I've been trying to look at other code and I'm pretty sure my code needs a
    public static void main(String[] args)
    in there somewhere but I can't figure out how to mix that in with the Acrostic piece that the tutorial says should go there.

    I feel like there must be a really simple solution and maybe I missed something?

    Any help would be great, I feel really dull right now.


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Trying to follow tutorial. Embarrassingly stuck.

    I think you missed a few steps:

    Editing a Java file (scroll down a bit)

    It has you create a Main class which contains the main method.

  3. #3
    Junior Member
    Join Date
    Oct 2012
    Posts
    9
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Trying to follow tutorial. Embarrassingly stuck.

    I just checked and it looks like I did that step. My Main.java file looks like this
    package acrostic;
     
    import org.me.mylib.LibClass;
     
    /**
     *
     * @author One
     */
    public class Main {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            String result = LibClass.acrostic(args);
            System.out.println("Result = " + result);
        }
    }

    Looking at it more I thought I found the solution because in the properties of the MyApp project the main class is set to acrostic.Main and that runs fine when I run it so I went to the MyLib project where LibClass and set it's main class to acrostic.Main but that doesn't work either.

    I'm starting to get the feeling I'm more confused with the IDE than actual java itself.

  4. #4
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Trying to follow tutorial. Embarrassingly stuck.

    I'm starting to get the feeling I'm more confused with the IDE than actual java itself.
    It's very possible you are. I know there are several people who advocate learning to program without using an IDE first, then deciding later if you want to switch to an IDE or not. There's a post somewhere around here explaining in greater detail why, unfortunately I can't find it right now

  5. #5
    Junior Member
    Join Date
    Oct 2012
    Posts
    9
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Trying to follow tutorial. Embarrassingly stuck.

    I didn't even know that was possible. I haven't seen any tutorials that don't use an IDE.

  6. #6
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Trying to follow tutorial. Embarrassingly stuck.

    Ah-ha! Found it

    It doesn't really go too much into detail on how to program in Java without an IDE, rather mostly explains some of the fallacies with using IDEs.

    Writing a program with or without an IDE isn't too different, you just need a text editor. I would recommend getting one which has at least syntax highlighting and auto-indentation. For Windows I would recommend Notepad++, in Linux I've used gedit vim, and emacs (I prefer gedit, many other people swear by vim or emacs), and I've never really used Macs so I can't suggest any good programs.

    The 2 main skills that differ between an IDE and using the command-line are compiling and running programs.

    This page from Oracle has a tutorial on how to compile and run a simple program in Java. There are also many other tutorials and pages online on how to compile and run programs from the command-line.

  7. The Following User Says Thank You to helloworld922 For This Useful Post:

    0ffConstantly (October 11th, 2012)

  8. #7
    Member
    Join Date
    Sep 2012
    Posts
    128
    Thanks
    1
    Thanked 14 Times in 14 Posts

    Default Re: Trying to follow tutorial. Embarrassingly stuck.

    Quote Originally Posted by helloworld922 View Post
    It's very possible you are. I know there are several people who advocate learning to program without using an IDE first, then deciding later if you want to switch to an IDE or not. There's a post somewhere around here explaining in greater detail why, unfortunately I can't find it right now
    This idea is quite dated, and should really be replaced with a line that says "you should be familiar with using the console to program and compile".

    So get to know the console for a day and then switch to Eclipse or Netbeans.

    An IDE will really help in the early stages of learning to program because it prompts you when there's an error and reinforces style etc. Of course it can get things wrong, but there really is no point in struggling just because your forbears did. ;-)

  9. #8
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Trying to follow tutorial. Embarrassingly stuck.

    Quote Originally Posted by Starstreak View Post
    This idea is quite dated, and should really be replaced with a line that says "you should be familiar with using the console to program and compile".

    So get to know the console for a day and then switch to Eclipse or Netbeans.

    An IDE will really help in the early stages of learning to program because it prompts you when there's an error and reinforces style etc. Of course it can get things wrong, but there really is no point in struggling just because your forbears did. ;-)
    How long you work with the console is dependent on the user IDE's are nice but many of them really complicate the build and run process, which is great for many users but make it hard for beginners. I am by no means advocating a beginner struggle because their forbears did, but for a beginner building and running from the command-line is often times much simpler and easier to diagnose the problems (especially if seeking the help of others, we can just ask to see the code and the command-line args). The code a beginner usually deals with isn't complex so most of the advanced IDE features don't come into play that much. There are a few features I which would, though, for example you mentioned error highlighting and I would add package management to that list.

Similar Threads

  1. Follow redirect Link
    By jalalirs in forum Java Networking
    Replies: 2
    Last Post: October 10th, 2011, 07:58 AM
  2. CMD-Like GUI Tutorial
    By lucienmontierre in forum Java Theory & Questions
    Replies: 2
    Last Post: April 18th, 2011, 02:17 PM
  3. Make my code follow MVC
    By alpvii in forum What's Wrong With My Code?
    Replies: 6
    Last Post: November 29th, 2010, 07:48 AM
  4. java ws tutorial
    By aracky in forum Member Introductions
    Replies: 1
    Last Post: July 14th, 2010, 03:12 AM
  5. Store data in database using JSP
    By abhi4jdk in forum Java Servlet
    Replies: 1
    Last Post: May 18th, 2009, 04:42 AM