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

I think I trying to solve this problem for any ways such as: CLASSPATH is wrong, Remove cache file , Restart.. etc...
BUT One interesting issues: I got fixed when I trying to add Libraries' New Java(such as spigot-1.17.1.jar) and Edit Modules Dependencies(Scope section) Normal Provided(Maven: org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT) -> Compile
Then this got fixed BUT I DON'T KNOW WHY THIS WORKING TO ME
EXPLAIN:
First of all, When I click(application menu) and press RUN button then I got this msg:
Error: Could not find or load main class me.kennytool.betaplugin.BetaPluginHandler.
Caused by: java.lang.NoClassDefFoundError: org/bukkit/event/Listener
package me.kennytool.betaplugin;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
public class BetaPluginHandler implements Listener {
public static void main(String[] args) {
}
#EventHandler
public void onJoin(PlayerJoinEvent e){
Player player = e.getPlayer();
if (player.hasPlayedBefore()){
e.setJoinMessage(ChatColor.AQUA + "[REJOIN]" + ": " + ChatColor.BOLD + player.getDisplayName() + ChatColor.YELLOW + " WELCOME BACK");
// Have experienced logging log
}else{
e.setJoinMessage(ChatColor.YELLOW + "[FIRST]" + ": " + ChatColor.BOLD + player.getDisplayName() + ChatColor.BLUE + " WELCOME FIRST!");
// First logging on!
}
}
}
I don't know why this error shows to me.... Too many solution got it to solve this problems but this not WORK to me
NOTE: I used Java and with Minecraft Development Kit(Spigot)
(This probs doesn't occur in plain Java Project)

From your screenshots, all the dependencies are marked as scope provided, this means that they are expected to be provided externally and not available on the classpath. Please provide the contents of your pom.xml to verify, but I suspect you'll find a line on your dependencies that reads something like <scope>provided</scope> deleting this should resolve the issue. You can read more about maven dependency scopes here: https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#dependency-scope

Related

Cplex Java Library set up path problem in Eclipse

I have a newbie problem with taking the Cplex library in Eclipse,
Error: Could not find or load main class Files\IBM\ILOG\CPLEX_Studio1210\cplex\bin\x64_win64
Caused by: java.lang.ClassNotFoundException: Files\IBM\ILOG\CPLEX_Studio1210\cplex\bin\x64_win64
I added cplex.jar from external libraries and also added the native path by editing it,
CPLEX library path error in eclipse
under VMArguments I added,
-Djava.library.path=C:\Program Files\IBM\ILOG\CPLEX_Studio1210\cplex\bin\x64_win64
where cplex12100.dll stands. I managed to work with it before but I couldn't find why it is not working right now.
Everything is 64bit.
Thanks in advance!
Your error message references the following path:
Files\IBM\ILOG\CPLEX_Studio1210\cplex\bin\x64_win64
Notice that it does not start with "C:Program Files". My guess is that you need to put quotes around the path you are providing, like so:
-Djava.library.path="C:\Program Files\IBM\ILOG\CPLEX_Studio1210\cplex\bin\x64_win64"
This should allow Java to handle your path which includes a space character.
thanks for the answer,
Unfortunately, I forgot to add that I already tried that, but it gives another error when I try like that.
Error: Unable to initialize main class model(my package name).model(my class name)
Caused by: java.lang.NoClassDefFoundError: ilog/concert/IloException
Here is part of my code, I cut half of it(after ...) since I guess it is unrelated to the question.
package model;
import ilog.concert.*;
import ilog.cplex.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.*;
import java.time.Instant;
import java.util.concurrent.TimeUnit;
public class model {
public static void main(String[] args) throws Exception {
long startTime = Instant.now().toEpochMilli();
int a = 45; //matrisin boyutu
int b = 45; //matrisin 2. boyutu
int maxdistance = 90; //mesela 90 dan küçük deðerler
int depot = 0;
double alfa = 0.9;
double beta = 0.1;
float[][] distance = new float[a][b]; // bunu scanner dan çektik
int m = 3;
int C = 1200;
System.out.println();
System.out.println("m : " + m + " C : " + C );
System.out.println();
ArrayList<ArrayList> Nlist = new ArrayList<ArrayList>();
Scanner reader = null;
File burdurData = new File("burdur45.txt");
...
try {
long timeElapsed = endTime - startTime;
System.out.println("Execution time in milliseconds: " + timeElapsed);
System.out.println("Execution time in seconds: " + timeElapsed/1000);
} // try'ýn parantezi
catch (IloException exc) {
System.out.println(exc);
System.out.println("sýkýntý");
}
}
}
surely you should edit your question. In fact, for getting error:
java.lang.NoClassDefFoundError: ilog/concert/IloException
I had this error before and I solved it just by importing cplex.jar in ClassPath section of my project Java Build Path not in ModulePath. Also set Native Library Location path to cplex's dlls folder too. Furthermore you can check your details in java configuration->show command line too.

How to debug "error: cannot find symbol method" in Android code?

Why do I get these error's and how do I fix them...noob here please help?
error: cannot find symbol method getServiceUuid()
error: cannot find symbol method toByteArray()
error: cannot find symbol variable UrlBeaconUrlCompressor
Code:
beaconManager.setRangeNotifier(new RangeNotifier() {
#Override
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
// code to get URL below!!!!!
for (Beacon oneBeacon : beacons) {
if (oneBeacon.getServiceUuid() == 0xfeaa && oneBeacon.getBeaconTypeCode() == 0x10) {
// This is a Eddystone-URL frame
String url = UrlBeaconUrlCompressor.uncompress(oneBeacon.getId1().toByteArray());
Log.d("BeaconsEverywhere", "I see a beacon transmitting a url: " + url +
" approximately " + oneBeacon.getDistance() + " meters away.");
}
}
}
}
As per the details you have provided I can see you are getting error of
Cannot find symbol method for following method
toByteArray()
getServiceUuid()
And class : UrlBeaconUrlCompressor
These class and methods belongs to Beacon Library, But in your code you are not able to access these Class and Methods, There could be two possible reasons :
You have not imported related package : Check if you are importing them properly, Example :(If you are using altBeacon's UrlBeaconUrlCompressor )
import org.altbeacon.beacon.utils.UrlBeaconUrlCompressor;
You have not added dependencies properly in your build environment. Example :
dependencies {
compile 'com.google.apis:google-api-services-proximitybeacon:v1beta1-rev38-1.25.0'}
or you might not have added dependencies for altbeacons
However I will recommend you to add proper log stacks and gradle dependencies with your question.

How to provide python package path in Jython/Java code?

I have taken a written sample from this link to write my Python + Java integration code.
http://www.jython.org/jythonbook/en/1.0/JythonAndJavaIntegration.html
The code looks like below.
package org.jython.book.interfaces;
import org.jython.book.interfaces.JythonObjectFactory;
import org.python.core.Py;
import org.python.core.PyString;
import org.python.core.PySystemState;
public class Main {
public static void main(String args[]) {
String projDir = System.getProperty("user.dir");
String rootPath = projDir + "/src/org/jython/book/interfaces/";
String modulesDir = projDir + "/src/org/jython/book/interfaces/";
System.out.println("Project dir: " + projDir);
PySystemState sysSt = Py.getSystemState();
JythonObjectFactory factory = new JythonObjectFactory(sysSt, BuildingType.class, "Building", "Building");
BuildingType building = (BuildingType) factory.createObject();
building.setBuildingName("BUIDING-A");
building.setBuildingAddress("100 MAIN ST.");
building.setBuildingId(1);
System.out.println(building.getBuildingId() + " " +
building.getBuildingName() + " " +
building.getBuildingAddress());
}
}
When I run this code, it throws an error that it did not find the python module. I have kept the .py and .pyc files under the path provided as 'modulesDir'.
The literature says that "the requested module must be contained somewhere on the sys.path"; however, I did not understand how this can be set from this Java program. Can someone please provide some help?
Project dir: /Users/eclipsews/PythonJava
Exception in thread "main" ImportError: No module named Building
Hi found the answer to this issue!
Added the PySystemState.initialize method where I explicitly provide the "python.path" property, which is initialized to my project's path, where python modules are available.
private static Properties setDefaultPythonPath(Properties props) {
String pythonPathProp = props.getProperty("python.path");
String new_value;
if (pythonPathProp == null) {
new_value = System.getProperty("user.dir") + "/src/org/jython/book/interfaces/";
}
props.setProperty("python.path", new_value);
return props;
}
Properties props = setDefaultPythonPath(System.getProperties());
PySystemState.initialize( System.getProperties(), props, null );
This produces the correct output as follows:
module=<module 'Building' from '/Users/eclipsews/PythonJava/src/org/jython/book/interfaces/Building$py.class'>,class=<class 'Building.Buildin
g'>
1 BUIDING-A 100 MAIN ST.

How to force renaming of variable names in eclipse mars

How can I force eclipse mars to rename variable names?
When I try, I get
This refactoring cannot be performed correctly due to syntax errors in
the compilation unit.
The dialog only offers "Cancel".
It was possible to do this in older versions of eclipse, and I used the feature extensively, for example after copy&paste of code snippets found on the net.
Note this is not a duplicate of Refactoring variable names in Eclipse .
Edit 3 (summary of what happened):
In the code (shown below) were not only those common errors like missing imports or undeclared variables, but also a missing ";", thus a true syntax error. This, at first hidden among several other compiling issues, caused eclipse to refuse the refactoring.
As it turned out, this is not a special feature of mars but also of older versions of eclipse.
Edit: here comes my example code. It is mainly based on the examples from tutorialspoint for mongodb but very probably doesn't have anything to do with mongo.
import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientURI;
import com.mongodb.MongoCredential;
import com.mongodb.client.MongoDatabase;
public class MongoDBJDBC2 {
private static String myUserName;
private static String myPassword;
private static String myHost = "localhost";
private static String myDatabaseName = "mydb";
private static MongoDatabase db;
public MongoDBJDBC2() {
initDb();
// TODO Auto-generated constructor stub
}
public static void main(String args[]) {
MongoDBJDBC2 mo = new MongoDBJDBC2();
}
private static void initDb() {
MongoClientURI uri = new MongoClientURI(
"mongodb://" + myUserName + ":" + myPassword + "#" + myHost + "/?authSource=db1");
try (MongoClient mongoClient = new MongoClient(uri);) {
db = mongoClient.getDatabase(myDatabaseName);
System.out.println("Connect to database successfully");
// boolean auth = db.authenticate(myUserName, myPassword);
} catch (Exception e) {
System.err.println(e.getClass().getName() + ": " + e.getMessage());
}
}
public static void main4( String args[] ) {
try{
// To connect to mongodb server
MongoClient mongoClient = new MongoClient( "localhost" , 27017 );
// Now connect to your databases
DB db = mongoClient.getDB( "test" );
System.out.println("Connect to database successfully");
boolean auth = db.authenticate(myUserName, myPassword);
System.out.println("Authentication: "+auth);
DBCollection coll = db.getCollection("mycol");
System.out.println("Collection mycol selected successfully");
DBCursor cursor = coll.find();
while (cursor.hasNext()) {
DBObject updateDocument = cursor.next();
updateDocument.put("likes","200")
col1.update(updateDocument);
}
System.out.println("Document updated successfully");
cursor = coll.find();
int i = 1;
while (cursor.hasNext()) {
System.out.println("Updated Document: "+i);
System.out.println(cursor.next());
i++;
}
}catch(Exception e){
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
}
}
}
I try to rename db to myDb in
private static MongoDatabase db;
Previously I used eclipse Helios and never encountered this kind of "feature".
Edit2: I have located the fatal error. In method "main4" a semicolon is missing after
updateDocument.put("likes", "200")
Still don't understand why this upsets eclipse so much that it refuses to refactor, and I still would like to know if there is a way to force refactoring despite of errors.
Compilers issue two kinds of errors: syntax errors and all other kinds of errors, like "type mismatch" and "symbol not found". Eclipse complains about a syntax error. Are you sure that in previous occasions when Eclipse agreed to refactor your code despite the fact that it contained errors, it was syntax errors that your code contained? You see, there is a big difference.
Refactoring symbol names in java is far more involved than a simple text search and replace, the structure of your code has to be taken into account.
But in the case of a syntax error, the compiler has given up parsing your file, so it does not know the structure of your code: it does not know which tokens are variables, which tokens are types, which tokens are methods, etc. so it really cannot do the refactoring that you want.
So, if you must really proceed with your refactoring despite having syntax errors, then I am afraid that text search and replace is the way to go for you in this particular case.
But fixing the syntax errors before attempting to refactor would be the most prudent thing to do.
This happens when there is compilation issue in your code.
Fix the compilation issue than you can refactor your code.Yes this feature is recently introduced in newer version of eclipse.

JInput "no jinput-dx8 in java.library.path" Error

Hi I'm trying to make a game in java that gives users the option to a joystick or gamepad to control movement. So I found something called "JInput" that is suppose to make it easy to detect all connected game controllers. The problem is that when I run it in Eclipse I get the following error: "java.lang.UnsatisfiedLinkError: no jinput-dx8 in java.library.path".
My code is the following:
import net.java.games.input.*;
public class ListControllers
{
public static void main(String[] args)
{
System.out.println("JInput version: " + Version.getVersion());
ControllerEnvironment ce =
ControllerEnvironment.getDefaultEnvironment();
Controller[] cs = ce.getControllers();
if (cs.length == 0) {
System.out.println("No controllers found");
System.exit(0);
}
// print the name and type for each controller
for (int i = 0; i < cs.length; i++)
System.out.println(i + ". " +
cs[i].getName() + ", " + cs[i].getType() );
} // end of main()
} // end of ListControllers class
I'm currently developing in Windows 7 environment. Any help would be really appreciated.
You should set java.library.path property to point to the directory containing native dlls of JInput.
You can do it by adding -Djava.library.path=x (where x is your path) to the command line or to the "VM arguments" field of "Run configurations" dialog in Eclipse.

Categories

Resources