• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to Make This Code Run?  RSS feed

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, everyone. Forgive the stupid question, but I've been asked to test some code, and when I go to run the code in Eclipse, it says there is no main method. Can someone please show me what I need to add or edit so that I can make this code run? Thank you in advance.

 
K Jones
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I posted about the same code there, but please let me clarify: This is NOT the same question I asked about the referenced code. My question on that site was already answered. Thanks.

EDIT:  I think I might be closer to the answer (i.e., add the main method and then print the values of the variables in the code). I've tried using println, but it says the the variables in this code "cannot be resolved to a variable." Can someone please tell me how I can get the final value of the loop? Thank you.
 
Ron McLeod
Bartender
Posts: 1603
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K Jones wrote:Yes, I posted about the same code there, but please let me clarify: This is NOT the same question I asked about the referenced code. My question on that site was already answered. Thanks.

Understood - just adding some extra context to your question.


K Jones wrote:I think I might be closer to the answer (i.e., add the main method and then print the values of the variables in the code).

You have the right idea.  You need a class with a main method which will create an instance of your all class (which really should begin with a capital letter), and then call your select method with the appropriate arguments.

The main method should look like this:
You can either add the main method to your existing class, or create a new class with only the main method.

Give it a try and if you have any problems, post your code here so we can help your sort out what went wrong.  If you see any error messages or stack traces, post them as well.
 
K Jones
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for your help! I would like to print the return value from the loop (i.e., the value of (a[i-1])). When I try to use System.out.println, I get an error message saying that this can't be resolved to a variable. I tried using only i, but I get the same error message. I see there are options for printing an array, but I'm not sure how to use it in this context. If you could point me in the right direction, I would greatly appreciate it.
 
Ron McLeod
Bartender
Posts: 1603
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post the code that you have so far, along with any error messages.
 
K Jones
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. This is what I have, but I know I'm going about it the wrong way:


I get the error message "a cannot be resolved to a variable." I'd like to find a way to get the final values of the elements in the array/the return value (a[i-1]) or the value of select (if possible).

EDIT: I'm guessing I need to assign values to these variables?

 
Ron McLeod
Bartender
Posts: 1603
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K Jones wrote: .. I'm guessing I need to assign values to these variables?

Well, you do need to create an instance of the class, and call your method with some arguments.  You probably also want to check/display the value returned by the method.

For example (I renamed your class from all to All):
 
K Jones
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much! Your explanation really helped me to understand several things that were confusing me.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!