wood burning stoves 2.0*
The moose likes Java in General and the fly likes Please help with my program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic
Author

Please help with my program

Tawi Oei
Ranch Hand

Joined: Dec 16, 2012
Posts: 95
What is wrong with this code? Why does Java said that it cannot load main? What should I do? Here is the complete code:

Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
I compiled and ran your code, and I didn't get an error except a NullPointerException.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11170
    
  16

odds are pretty slim anyone is going to attempt to wade through 1300+ lines of code.

Can you reduce all the clutter, and post a short, simple example that still demonstrates your problem?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

So you wrote 1300 lines of code before you tested it at all?

Don't do that. Every time you start a new project, start with this:



Don't write any more code until you can compile and run that. Do that for every new project.

Then add a tiny bit at a time, compile, test, debug, and don't write any more code until that piece works.

Tawi Oei
Ranch Hand

Joined: Dec 16, 2012
Posts: 95
Keith Lynn wrote:I compiled and ran your code, and I didn't get an error except a NullPointerException.

Where? Why do I get the message that it cannot load main? What should I do? I post everything because I do not know what is wrong with it, how to fix that?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Tawi Oei wrote: I do not know what is wrong with it, how to fix that?


You fix it by doing what I suggested.

You start with nothing. Then you ad a lilttle bit. Test, debug, as many times as necessary. Then you add a little bit more. Test, debug, as many times as necessary. And continue on adding little bits until you've got the whole thing or until some little bit breaks it. If it breaks, you know which little bit caused the problem, so you can focus on finding out what's wrong with that little bit. It will likely involve breaking it down into even littler bits and testing them individually.

Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7552
    
  18

fred rosenberger wrote:odds are pretty slim anyone is going to attempt to wade through 1300+ lines of code.

Particularly when so many of them are enormous.

@Tawi: Please DontWriteLongLines (←click). It makes your post very hard to read.
I'm not even going to try to edit that monstrosity, but unless you do, and break up some of those huge lines
(and indeed, remove the non-relevant stuff), I doubt that you're going to get much help.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Steve Fahlbusch
Bartender

Joined: Sep 18, 2000
Posts: 557
    
    7

is this the same program you have posted at least three times before without following the directions you have been given?
Tawi Oei
Ranch Hand

Joined: Dec 16, 2012
Posts: 95
Well, how can I get a different result? I run it with my pc, it said that it cannot find or load main but with my notebook, it said that it found NullPointerException, how to fix this? I tried to fix this but it said that local variable hide a field, so what should I do?
Mack Wilmot
Ranch Hand

Joined: Jul 27, 2011
Posts: 88

Maybe you are not typing the name of the class in right when you execute it. =)

http://www.coderanch.com/t/552660/java/java/Java-find-load-class
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38075
    
  22
Tawi Oei wrote: . . . I run it with my pc, it said that it cannot find or load main but with my notebook, it said that it found NullPointerException, . . .
If you get an Exception, you must have started the application and therefore found the main method.

So what is the difference between those two computers and their Java installations?
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11170
    
  16

also...when you 'run it', what EXACTLY are you typing? Is the Class file there? Did you compile it?

Basically, all we're getting from you is "It doesn't work - fix it". We can't. We need more details. Read our HowToAskQuestionsOnJavaRanch FAQ, and apply the suggestions to your question.
Tawi Oei
Ranch Hand

Joined: Dec 16, 2012
Posts: 95
I do not know. My friend did some things to the notebook. I did not know the thing that he did to the notebook. So what is the problem? I got an error at the time I copy the code to my notebook but I changed the code after I knew that the code contained an error. I forgot the thing that was changed by me because I had plenty of works to do, so can you help me with this code? I post all of the code because I do not know exactly the problem that I have, can you help?
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11170
    
  16

No, we can't help. You do not provide enough information for anyone to have a clue what the problem is. You are simply saying "it doesn't work, please fix it".

Please post what EXACTLY you do. also, post the EXACT text of any error message. paraphrasing doesn't help. Repeating that it doesn't work is pointless. Unless you can provide us with additional information, there is nothing we can do.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Tawi Oei wrote:I post all of the code because I do not know exactly the problem that I have


If you had gutted it and started fresh from the beginning as I suggested, you'd probably have found the problem by now.
Tawi Oei
Ranch Hand

Joined: Dec 16, 2012
Posts: 95
Well, I modified the code, I insert this code:



Java said this code have an error, why?

Java also told me that multi-catch statement is not supported yed. How to solve this?



The complete code is in http://www.tawijakarta.blogspot.com under Java Program III title. I cannot post the code in here. The other questions are: why do some folks close my threads? If they said that the site was a spam so how to make you to have any ideas about the website I wanted to create with a Java Applet?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Tawi Oei wrote:Well, I modified the code, I insert this code:



Java said this code have an error, why?


People have been trying to tell you that you need to provide details, and you're still not doing it.

Copy/paste the exact, complete error message, and indicate clearly which line is causing it.

Java also told me that multi-catch statement is not supported yed. How to solve this?


Either upgrade to a version where it is supported, or create separate catch blocks for each exception you want to handle.

The complete code is in http://www.tawijakarta.blogspot.com


Most people are not going to want to go offsite to look at your code
Tawi Oei
Ranch Hand

Joined: Dec 16, 2012
Posts: 95
Jeff Verdegan wrote:
Tawi Oei wrote:Well, I modified the code, I insert this code:



Java said this code have an error, why?


People have been trying to tell you that you need to provide details, and you're still not doing it.

Copy/paste the exact, complete error message, and indicate clearly which line is causing it.

Java also told me that multi-catch statement is not supported yed. How to solve this?


Either upgrade to a version where it is supported, or create separate catch blocks for each exception you want to handle.

The complete code is in http://www.tawijakarta.blogspot.com


Most people are not going to want to go offsite to look at your code


Ok, it said that local variable hides a field, so what should I do to fix that? How to do the upgrade? Where to get the download?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Tawi Oei wrote:
Jeff Verdegan wrote:

Copy/paste the exact, complete error message, and indicate clearly which line is causing it.


Ok, it said that local variable hides a field


That's not even close to what I asked for. I don't think I can help you. Good luck.

fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11170
    
  16

At this point, most folks are probably done trying to help you. Nobody asked you to paraphrase what the error message is, which is what you did with "it said that local variable hides a field". I'm sure there was a lot more to it than that.

You have been asked to post the code here that is causing the error. You haven't done that.

We expect you to make some effort yourself. A quick google search would tell you how to upgrade and where to get the download.

You seem to expect us here to do everything for you, and all that you are accomplishing is driving everyone away from helping you.

so...please READ the suggestions you've been given. Follow the advice. Answer the questions you've been asked. Do what you are asked - otherwise, nobody will help you.
Tawi Oei
Ranch Hand

Joined: Dec 16, 2012
Posts: 95
I tried my best to fix it but I failed. I insert the code but Java say that the local variable hides a field. The complete code can be seen in my web site because I cannot post it in here. At there, you can see the full code so you can have some ideas about why does Java say that the local variable hides a field. What else do you want me to post? So what do you suggest me to do? I really do not know what is happening with my program so I do not have any ideas to solve it, please help me. I get out of stock idea. Do you have any ideas?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Tawi Oei wrote:I tried my best to fix it but I failed.


Except that you didn't follow the advice given here. I wouldn't call that your best.

The complete code can be seen in my web site


Nobody wants to click to a different site, or look at that much code. You've already been told this. It hasn't changed. If you won't pay attention to what people who are trying to help you are saying, you're just going to remain stuck.

I cannot post it in here.


Then post an SSCCE that demonstrates the problem.

So what do you suggest me to do?


I already suggested it several times. I'm not going to waste bits saying it again.

Do you have any ideas?


Yes, but so far you've ignored them.
Tawi Oei
Ranch Hand

Joined: Dec 16, 2012
Posts: 95
Java did not give me any error messages because before I compiled the code, Java put some error signs and after I put my mouse over the error signs, Java showed me the messages, so what should I do? I do not even know what my problem is so how will I post the relevant code? Where is the mistake? Why can I get those difference at the time I use my PC and notebook?
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11170
    
  16

Tawi Oei wrote:Java put some error signs and after I put my mouse over the error signs,

No...Java did not show you any 'error signs'. Java doesn't do that. You must be using an IDE like Eclipse or Netbeans.

Tawi Oei wrote: so what should I do?

We have told you several times:

Post the full and complete error message. Simply saying "It shows me an error" is a waste of everyone's time.

Tawi Oei wrote:I do not even know what my problem is so how will I post the relevant code? Where is the mistake?

The IDE should be telling you the exact line where it thinks the problem is. It doesn't just say "There is a problem somehwere in your code". It will tell you the exact line number and often the exact spot in the line where it first thinks there is an error

Tawi Oei wrote:Why can I get those difference at the time I use my PC and notebook?

Do you have the same environment on both? Same version of Eclipse (or whatever)? Same version of the JDK? Same version of the JRE? Same operating system?
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11170
    
  16

Here is a WILD GUESS, based on the fact that I was distracted.

I took your 1300 lines of code, copied them into a file on my pc named ProgramTesisBaru.java.

Then (and this is where i was distracted), I typed:

java ProgramTesisBaru.java

I meant to compile it, but missed the 'c'. This gave me the error:
Error: Could not find or load main class ProgramTesisBaru.java

Is this what you are seeing? If so, it means you haven't compiled your code. you need to do this:

javac ProgramTesisBaru.java

That gave me two WARNINGS, but that's ok. The code still compiled. I know because I now have about 20 .class files.

Once i had that, i could run your program with this:

java ProgramTesisBaru

I got a GUI that popped up. I don't know what the labels mean (there are two that say "Lanjut"). I click on them and stuff happens, but I don't know what.
Tawi Oei
Ranch Hand

Joined: Dec 16, 2012
Posts: 95
Ok you are correct, I am using netbeans. I put :



in front of:



and after that, the program works fine. Does Netbeans have a rule that everything that is put at the first line will be executed first? About the download, I cannot download it from Oracle, where can I download the updated version that can work with multi-catch?
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11170
    
  16

In any programming language that I know of, code is executed in a well defined order. so basically, yes, each line of code is executed in order. obviously method calls, loops, if statements, etc, can all move you to a different next line, but it is all pretty explicit what can happen.

About the download, I cannot download it from Oracle, where can I download the updated version that can work with multi-catch?

sigh...you're not learning.

WHY can't you download it from Oracle? If there is a reason, you should tell us so that we don't try steering you to another site that would cause you the same problem.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Tawi Oei wrote:Does Netbeans have a rule that everything that is put at the first line will be executed first?


It has nothing to do with NB. It's the rules of Java, regardless of what tool you use to write the source code.

I'm morbidly curious though: What order did you think things happened in?

Tawi Oei
Ranch Hand

Joined: Dec 16, 2012
Posts: 95
Well, I really cannot post to the forum so please open my website at http://www.tawijakarta.blogspot.com. I was changing my program. The result is in my website under the title Java Program III. Why does Java said that there is no main class? What is wrong with my program? What should I do? What comment do you have? Please don't say that I need to post short codes because I don't know the problem I have.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Did you read fred rosenberger's reply? It seems to describe exactly what you get.

Tawi Oei wrote:Why does Java said that there is no main class?

Because you're doing something wrong.

Tawi Oei wrote:What is wrong with my program?

Fred was able to compile and run it, so there doesn't seem to be anything wrong with it that prevents it from compiling and running.

Tawi Oei wrote:What should I do? What comment do you have?

You should explain in detail what commands you are typing to compile and run the program, and copy and paste any error messages that you get into your reply on this forum.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Tawi Oei wrote:Well, I really cannot post to the forum so please open my website at http://www.tawijakarta.blogspot.com.


You've already been told--a few times, I think--that that is not going to happen.

Please don't say that I need to post short codes because I don't know the problem I have.


If you had taken the advice to start over and build your program piece by piece, you would have solved your problem by now. Instead you continue to ignore what people here are telling you and cling to the mess you've made for yourself. It's like you're going out of your way to make more work for yourself and to make people here want to give up trying to help you.

People here do want to help, but most of the work has to come from you, and you have to actually pay attention to what you're being told and follow the advice you're given.
Steve Fahlbusch
Bartender

Joined: Sep 18, 2000
Posts: 557
    
    7

And just set the level.

He never wrote the program he is asking help for...... he copied it to finish his degree, that is why he cant run it and why he cant provide a smaller, simpler example.

Tawi Oei
Ranch Hand

Joined: Dec 16, 2012
Posts: 95
I make the program myself. The problem is I almost touch the time limit. I must finish this as soon as possible to get my master degree. The error message that I got was no main classes found. Can you help me? I cannot post the code in the forum so please just go to http://www.tawijakarta.blogspot.com. You can see the code under Java Program III title. This is not a spam because I cannot post it here.
Stuart A. Burkett
Ranch Hand

Joined: May 30, 2012
Posts: 679
Tawi Oei wrote:The error message that I got was no main classes found. Can you help me?

Fred has already told you what the probable cause of this is (see his post starting 'Here is a WILD GUESS'). We can't be certain because you refuse to post the complete and exact error message (copy and paste it - don't paraphrase). Until you follow Fred's suggestions and tell us whether they worked or not, there's no point in anyone trying to help you any further.
Tawi Oei
Ranch Hand

Joined: Dec 16, 2012
Posts: 95


Ok here is the code. What is wrong with this code? What is your suggestion? What should I do to fix this code? How to implement of this code?
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7552
    
  18

Tawi Oei wrote:Ok here is the code.

Right, so, after being told more than once that nobody is going to wade through 1300 lines of code, you've now posted it AGAIN.

What is wrong with this code?

Believe me, it would take too long to explain - and very little of what I have to say would have anything to do with your actual problem.

What is your suggestion? What should I do to fix this code? How to implement of this code?

Jeff has already told you. That program is 1290 lines too long.

Start again, and add small portions of what you've written piece by piece, compiling every time. It looks as though you may well have to do this fifty times or more, but basically it's what you should have done in the first place.

Winston
Tawi Oei
Ranch Hand

Joined: Dec 16, 2012
Posts: 95
The program was doing well. The only problems I have are NPE, dual exception, bad display. I can fix bad display, what about dual exception catch and NPE? I removed an exception catch and changed the program so the program is the same with the current program but NetBeans gave me error message that no main class found, what should I do? I cannot recreate the program because I almost run out of time so please just help me to solve the problem ok?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18546
    
  40

Tawi Oei wrote:The program was doing well. The only problems I have are NPE, dual exception, bad display. I can fix bad display, what about dual exception catch and NPE? I removed an exception catch and changed the program so the program is the same with the current program but NetBeans gave me error message that no main class found, what should I do? I cannot recreate the program because I almost run out of time so please just help me to solve the problem ok?



For NPEs, it is probably best to use the stacktrace. Add a printout of the stacktrace in the catch statement..... And as others already mentioned, there is zero chance that I will look at 1300 lines of code in my spare time. I have enough work in my real job.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11170
    
  16

Tawi Oei wrote:I cannot post the code in the forum so please just go to http://www.tawijakarta.blogspot.com.

You can't??? Why not? I went there, copied your code, and here it is:


That still leaves 400 lines of un-commented code. And for the record, you are getting a "no main defined" because your main method is in that block of 1000 commented out lines.

This is really such a mess of ugly, terrible code, that I doubt there is any point in salvaging it.

Best of luck to you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please help with my program
 
Similar Threads
Please help with NullPointerException
Please help to solve for problem
Hi, what is wrong with my code?
Please Help with setText
use user's input in JTextField in a class as a label for JLabel, how to do that?