0

My friend and myself are working on a java assignment and we are using github for version control.
We have a main file which has the correct syntax:
public static void main(String args[]) { //code }
Yesterday, I was able to run the main file as a java application. But today my friend made changes to some other files and I updated my repository. Now however I am unable to run the main file even though no changes have been made to it.

What can I do? Even the syntax highlighting is gone.
I am using Eclipse Version: Neon.3 Release (4.6.3)

fredjohnson
  • 187
  • 2
  • 10
  • 18
  • is the "main file" a class? a method is a part of a class, it can't survive by itself. please post your _main file_. – patateskafa May 07 '17 at 09:27
  • Eclipse doesn't think it is a source folder anymore. Do not share eclipse configuration files in the repository - it is brittle and will break. – Thorbjørn Ravn Andersen May 07 '17 at 09:28
  • @patateskafa the main file is a java class. I am sorry I cannot post my main file because my university prohibits me from posting assignment code on public forums. – fredjohnson May 07 '17 at 09:31
  • 1
    ah it's ok. check @ThorbjørnRavnAndersen's comment. that's probably the case. for your future questions in SO, consider abstracting, mimicking your code if there's a prohibition of sharing it. that would be helpful for both you and the community. – patateskafa May 07 '17 at 09:32
  • @ThorbjørnRavnAndersen I see. What should I do? I deleted the repository in eclipse, and imported it again from github, still did not work. – fredjohnson May 07 '17 at 09:33
  • Convert it into a maven project. may require elbow grease – Thorbjørn Ravn Andersen May 07 '17 at 09:39
  • Perhaps this [question+answers](http://stackoverflow.com/questions/179439/how-to-change-an-eclipse-default-project-into-a-java-project) would help – Hugues M. May 07 '17 at 09:47
  • @ThorbjørnRavnAndersen I converted my java project into a maven project, but it still will not run the main file – fredjohnson May 07 '17 at 09:48
  • Check whether the project has created as java project or web project. – PrabaharanKathiresan May 07 '17 at 11:23
  • Does your class holds `public static void main` ? You won't get `run as java application` in context menu if the class is missing main. – Master Po May 07 '17 at 11:32
  • Show the contents of the panel showing the files in your workspace. – Thorbjørn Ravn Andersen May 07 '17 at 21:41
  • @ThorbjørnRavnAndersen I was able to fix my problem. I imported the github project as an existing eclipse project instead of general project – fredjohnson May 08 '17 at 07:14

3 Answers3

1

If you have set up run configurations. Then you must check if you have used String args[] in main method parameter. It is necessary in java to add this parameter. After that you can rerun you class by run as-> Java application or Ctrl + F11

sawan
  • 2,341
  • 3
  • 25
  • 51
richacode
  • 11
  • 2
0

Try to Follow this.

Right click on your java file and choose "Run As">"Run Configurations". And add new java application Configurations. See .Imagebelow Than, Click on "Run".

Hemin
  • 712
  • 1
  • 14
  • 29
0

Faced the same issue when I was trying to run a simple program. I had missed the array declaration in the (String arg[] ) . Adding the [] at the end of args solved it.

Spear A1
  • 525
  • 1
  • 7
  • 20