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.
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
Code :
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.
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.
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
Code :
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. b-(
Re: Trying to follow tutorial. Embarrassingly stuck.
Quote:
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 :P
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.
Re: Trying to follow tutorial. Embarrassingly stuck.
Ah-ha! Found it :P
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.
Re: Trying to follow tutorial. Embarrassingly stuck.
Quote:
Originally Posted by
helloworld922
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 :P
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. ;-)
Re: Trying to follow tutorial. Embarrassingly stuck.
Quote:
Originally Posted by
Starstreak
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 :P 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.