Error: Could not find or load main class Orders - java

So I have a folder where some files are sitting. One PDF (the homework assignment), one .vscode folder with the Launch.json inside for debugging, and 3 .java files.
These files are: Orders.java, Truck.java, and Car.java
Truck and Car contain classes, Orders contains the main program:
public class Orders {
public static void main(String[] args) {
//actual program inside
}
}
I used VS Code's gear button in the debugger pane to create the launch.json, which gave me this for a launch option:
"configurations": [
{
"type": "java",
"name": "Debug (Launch)-Orders",
"request": "launch",
"mainClass": "Orders",
"args": ""
},
I set some breakpoints hoping to be off to the races. However when I hit the green play button to run the program, I get the error listed in the title of the post: Error: Could not find or load main class Orders
Is there something wrong with Launch.json or is there something else that could be causing this issue?
Also, if I run the program in the VS Code provided terminal:
Windows PowerShell
Copyright (C) 2016 Microsoft Corporation. All rights reserved.
d.
PS C:\Users\Profile Name\Documents\RIT\Fall 2017\ISTE 200\HW\HW3> java Orders
The program runs fine but hits no breakpoints.
I'm using the Redhat Java Support extension, if that matters.

Related

Java: Where is Autowired.Value looking for a setting?

I've inherited a large-ish Java project using org.springframework.beans.factory.annotation.Autowired, among other things.
I have one module that starts like this:
#Autowired
public Application(
FlattenByFeedRunInvoker flattenRunInvoker,
#Value("${jobId:}") String jobId,
#Value("${instanceId:}") String instanceId,
#Value("${feed}") String feed,
When I run it under debug, using this config:
{
"type": "java",
"name": "Debug (Launch)-Application<tbsm-reporting-etl-flatten>",
"request": "launch",
"mainClass": "com.tbsm.reporting.etl.flatten.Application",
"projectName": "tbsm-reporting-etl-flatten"
}
I get the message:
[ERROR] 2019-07-23 10:10:58.137 [THREAD ID=main]
[CLASS=(SpringApplication:771)] - Application startup failed
java.lang.IllegalArgumentException: Could not resolve placeholder
'feed' in value "${feed}"
I'm guessing that the framework is trying to find a value labelled "feed" somewhere. FWIW I do have a file called "default.properties" in the "resources" directory for the project and that file has the line
feed=myfeed
It looks like that file or value is not being found. I'm wondering if it is just in the wrong directory wrt the program i'm running:
..\src\main\java\com\tbsm\reporting\etl\flatten\Application.java
vs
..src\main\resources\default.properties
Or if I need to do something else to tell it where to look. e.g. does the vscode launch config need something else?

Visual Studio Code: Failed to evaluate. Reason: Cannot evaluate because the thread is resumed. When trying to use scanner

When I try to run this code
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
String input = in.nextLine();
System.out.println(input);
in.close();
}
}
I get the error: Failed to evaluate. Reason: Cannot evaluate because the thread is resumed.
I don't really know why this appears nor how to fix it
The error message appears to be produced by the debugger.
(Refer to line 70 of this: https://github.com/Microsoft/java-debug/blob/master/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/EvaluateRequestHandler.java)
The preceding comment says:
// stackFrameReference is null means the stackframe is continued by user manually,
It seems that you may have gotten the debugger into a slightly confused state. There was a related issue in the issue tracker for the Java debugger for Visual Studio.
https://github.com/Microsoft/java-debug/issues/109
The evaluation has some hints as to what the developer thinks was going on. Unfortunately, the person who raised the issue did not explain what he was doing, and the developer concluded that there was no real issue here.
But it is also possible that the underlying cause for this error message has since been fixed.
If you change internalConsole to integratedTerminal or externalTerminal in launch.json works, but say bye bye colors
// "console": "internalConsole",
"console": "integratedTerminal",
//"console": "externalTerminal",
The default Debug Console in VS Code doesn't support inputs. In case your program need inputs from terminal, you can use Integrated Terminal within VS Code or external terminal to launch it.
(https://code.visualstudio.com/docs/java/java-debugging)
Open ~/.vscode/launch.json and change configurations.console to integratedTerminal or externalTerminal (probably the former).
// launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Debug (Launch)-App<test-app>",
"request": "launch",
"cwd": "${workspaceFolder}",
// ..........
"console": "integratedTerminal",
// **********
"stopOnEntry": false,
"mainClass": "com.test.app.App",
"projectName": "test-app",
"args": ""
}
]
}

Sublime text 3 how to: Java output

Recently I have discovered Sublime Text 3, but when I try to run Java with for example some println's it doesn't return anything. All it does is say "[Finished in x seconds]". Can someone please explain how to make it output text when I run my code. I am on mac os 10.9.5
Code example:
public class Main{
public static void main(String[] args){
System.out.println("Hello, world!");
}
}
That's because you are not running anything. The default java plug-in won't run code until you modify it. You are only building (compiling) your code.
To modify the plug-in you have to go to /Packages and unzip the Java.sublime-package file:
cd <sublime-text3-folder>/Packages
mkdir java
cp Java.sublime-packages java
cd java
unzip Java.sublime-packages
Then use an editor (vi, emacs...) and modify JavaC.sublime-build to add the following lines (don' forget the extra comma after the last line
{
"shell_cmd": "javac \"$file\"",
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"selector": "source.java",
"variants":
[
{
"name": "Run",
"shell_cmd": "java $file_base_name"
}
]
}
Zip again the contents in Java.sublime-package and put it back in Package folder via:
zip Java.sublime-package *
cp Java.sublime-package ../<sublime-text3-folder>/Packages
Restart sublime and now along with Ctrl+B to build your project you will be able to run it with Ctrl + Mayus + B

Errror when packaging sencha touch for ios debug

I'm trying to package a sencha application for ios. But when I in the terminal do: "sencha package build package.json" I get the following
: [ERR] null
at com.sencha.command.environment.AppEnvironment.(AppEnvironment.java:48)
at com.sencha.command.environment.BuildEnvironment.load(BuildEnvironment.java:193)
at com.sencha.command.Sencha.loadBuildEnvironment(Sencha.java:374)
at com.sencha.command.Sencha.main(Sencha.java:127)
I probably screwed something up with the certficates and provisioning profiles, but, I'm not sure if this is some kind of environment error, ie sencha cmd not finding path of Java. The error seems to suggest this, but the cmd works with other commands. I can, for example, create a new app with "sencha app generate myapp ..myapp".
So, my question is really, is the error caused by some environment problem, and if so, what to do about it, or is his a problem related to some errror in my packager.json. Here's my packager.json file.
All help much appreciated!
{
"applicationName":"app",
"applicationId":"com.appname",
"bundleSeedId":"xxxxxxxx",
"versionString":"1.0",
"iconName":"icon.png",
"icon": {
"36":"resources/icons/Icon_Android36.png",
"48":"resources/icons/Icon_Android48.png",
"57":"resources/icons/Icon.png",
"72":"resources/icons/Icon~ipad.png",
"114":"resources/icons/Icon#2x.png",
"144":"resources/icons/Icon~ipad#2x.png"
},
"inputPath":"/Applications/XAMPP/xamppfiles/htdocs/app/",
"outputPath":"../build/",
"configuration":"Debug",
"platform":"iOS",
"deviceType":"Universal",
"certificatePath":"../cert/mycert.p12",
"certificateAlias":"iPhone Developer:",
"certificatePassword":"",
"provisionProfile":"../cert/name.mobileprovision",
"notificationConfiguration":"",
"orientations": [
"portrait",
"landscapeLeft",
"landscapeRight",
"portraitUpsideDown"
]
}

Cannot run "Hello World" program in Eclipse

I have an error in my first step with Java, so when i try to run the code hello world:
class apples{
public static void main(String args[]){
System.out.println("Hello World!");
}
}
I go to: - Run as .. -> Then i choose Java aplicacion - > And i press Ok
But when i press Ok does not appear the window down to show me the correct message Hello World
Your code works fine for me:
class apples
{
public static void main(String args[])
{
System.out.println("Hello World!");
}
}
I downloaded it to c:\temp\apples.java.
Here's how I compiled and ran it:
C:\temp>javac -cp . apples.java
C:\temp>dir apples
Volume in drive C is HP_PAVILION
Volume Serial Number is 0200-EE0C
Directory of C:\temp
C:\temp>dir ap*
Volume in drive C is HP_PAVILION
Volume Serial Number is 0200-EE0C
Directory of C:\temp
08/15/2010 09:15 PM 418 apples.class
08/15/2010 09:15 PM 123 apples.java
2 File(s) 541 bytes
0 Dir(s) 107,868,696,576 bytes free
C:\temp>java -cp . apples
Hello World!
C:\temp>
Your lack of understanding and the IDE appear to be impeding your progress. Do simple things without the IDE for a while until you get the hang of it. A command shell and a text editor will be sufficient.
Sorry about missing javac; cut & paste error.
If you look at the screenshot, your class name is there, last in the list. Select it and press OK. To not see this message again, right-click on the class name on the left side and select there Run...->Java Application.
The only problem that causes your error here is that the classname and the filename do not match - and they have to.
Solution
Rename either the file thesame.java to apple.java or the class to thesame. Then if you select "Run as..." again, eclipse will present a menu item to start your Java application.
(other mentioned, that there's no requirement that a top-level class and the filename do match - unless the top level class is public. Of course this is true. But the problem was about "running" a class under eclipse as a Java application)
Try public class apples and make sure the file is apples.java. Also it should be public static void main(String[] args)
You have 2 classes by name of "thesame.java" under the source folder. Since one is directly under the src folder, and other under (default package), they use the same namespace, hence Interpreter is confused which java file to execute and is asking you to select the class you want to execute.
Class names must be capitalized... so change apples to Apples. Also, if you are a beginner (which it seems like), I would recommend the Netbeans IDE -- it's a bit more friendlier for new users than Eclipse.
You class must be named "thesame" if you store it in a file called "thesame.java", as you have. Either rename your class to "thesame" or change the file to be "apples.java".
You should move the "[]" to be before "args". So, String[] args.
Either select "apples" at the bottom of the menu you posted and run it, or right-click on the Java file and make it the default thing to run for this project. Or launch it by right-clicking on the file and selecting "run".

Categories