This is the Google Guice calling code:
public static ContainerRunner forInjector(Injector injector) {
return (ContainerRunner)injector.getInstancefaultContainerRunner.class);
}
public static ContainerRunner forModules(Iterable<? extends Module> modules) {
return forInjector(Guice.createInjector(modules));
}
And this the exception:
Exception in thread "main" java.lang.NoSuchMethodError: com.google.inject.internal.Initializer.requestInjection(Lcom/google/inject/internal/InjectorImpl;Ljava/lang/Object;Lcom/google/inject/Binding;Ljava/lang/Object;Ljava/util/Set;)Lcom/google/inject/internal/Initializable;
at com.google.inject.internal.BindingProcessor$1.visit(BindingProcessor.java:108)
at com.google.inject.internal.BindingProcessor$1.visit(BindingProcessor.java:70)
at com.google.inject.internal.ProviderInstanceBindingImpl.acceptTargetVisitor(ProviderInstanceBindingImpl.java:62)
at com.google.inject.internal.BindingProcessor.visit(BindingProcessor.java:70)
at com.google.inject.internal.BindingProcessor.visit(BindingProcessor.java:43)
at com.google.inject.internal.BindingImpl.acceptVisitor(BindingImpl.java:93)
at com.google.inject.internal.AbstractProcessor.process(AbstractProcessor.java:56)
at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:186)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:104)
at com.google.inject.Guice.createInjector(Guice.java:96)
at com.google.inject.Guice.createInjector(Guice.java:73)
at com.baml.gmt.xasf.container.ContainerRunners.forModules(ContainerRunners.java:39)
My problem is that the message does not tell me which particular method is missing. Is there a good way to debug this? Can this be a Maven transitive dependency issue?
It tells you exactly what method is missing. It's:
package com.google.inject.internal.Initializer
Initializable requestInjection(InjectorImpl, Object, Binding, Object, Set)
Considering that method signature was last changed Five years ago, you almost certainly have some sort of build issue that is making the method not be in your classpath somehow. You haven't given us enough information to be able to debug further.
It turns out that, when I executed in Unix environment, there were permission issue with the files in lib directory. As soon as I changed the permission, it got past this Guice error. This Guice error, from my paste experience, is almost always due to dependency issues, one way or the other. But Guice does not give you a more specific, more descriptive error message.
Related
Learning Java. I have two files, each containing one java class. When I run the file with the main method, I get the following error:
Exception in thread "main" java.lang.IllegalAccessError: failed to access class TapeDeck from class TapeDeckTestDrive (TapeDeck is in unnamed module of loader 'app'; TapeDeckTestDrive is in unnamed module of loader com.sun.tools.javac.launcher.Main$MemoryClassLoader #18bf3d14)
at TapeDeckTestDrive.main(TapeDeckTestDrive.java:3)
class TapeDeckTestDrive{
public static void main(String[] args){
TapeDeck t = new TapeDeck();
t.canRecord = true;
t.playTape();
if (t.canRecord == true) {
t.recordTape();
}
}
}
class TapeDeck {
boolean canRecord = false;
void playTape(){
System.out.println("tape playing");
}
void recordTape(){
System.out.println("tape recording");
}
}
Any help please?
Actual Issue
I got this exact same error* doing something very silly:
I tried to run the file as java {main-class}.java. That simple!
Instead, be sure to run it simply as java {main-class}.
*Specifically, the error format I had, like yours:
Exception in thread "main" java.lang.IllegalAccessError: failed to access class {pack.other-class} from class {pack.main-class} ({pack.other-class} is in unnamed module of loader 'app'; {pack.main-class} is in unnamed module of loader com.sun.tools.javac.launcher.Main$MemoryClassLoader #29f69090)
at {pack.main-class}.{who-cares-where}
at {pack.main-class}.{who-cares-why}
. . .
Extra Advice
You can get a similarly annoying error on the same issue, namely inability to access packages in the same directory, if you only compile your {main-class}.
So instead of javac {directory}/{main-class}.java
Be sure to compile all of them at the same time, so there's no issue in cross-referencing: javac {directory}/*.java
OP Specific
This would just be a silly command-line mistake. If it's occurring in IntelliJ as well, as you say, this isn't your issue. However, I hope it's at least helpful to the others who come across your question with this error!
Make sure each class is in the same folder, since the error is saying TapeDeckTestDrive can not find TapeDeck. I would recommend starting out with an IDE like Eclipse since it will help you focus more on coding and less with folder problems.
I know your code is all good (in java 8 at least) since when I copied it in eclipse it works no problem, meaning it has to be a folder problem, a problem with the installed version of java, or the way you are running the code is not working for some reason. If both files are in the exact same folder then I would make sure your java version says 1.8 something in the system files (Program Files(x86) most likely in windows), if it does not say that version then it could be another problem with the code and syntax for that version.
Another thing that might help is to put public behind the "class" on the first line of each class and make the Boolean public. This might be a syntax requirement on other versions of java or something that is needed when running off command prompt.
Quick possible fix, try making the classes and methods "Public".
Under normal circumstances this shouldn't be necessary but you may be hitting a specific case where it might be (It's an edge case so I don't know if it's a problem or not off the top of my head):
Java is really uncomfortable with stuff being in the "Default" package--code from other packages can't access objects in the default package (Meaning no package statement). Although this shouldn't cause problems in your case, maybe your "package" level security settings are also not working in the default package.
If this is actually the problem, the two fixes would be to make the packages and methods public (as I said above) or move both classes into a package.
What worked for me was to add the key word 'public' in both methods (playTape and recordPlay) and variables (canRecord).
I have this code:
GoogleApiAvailability googleAPI = GoogleApiAvailability.getInstance();
String msg = getString(R.string.common_google_play_services_update_text);
Log.e(TAG, msg);
Dialog errDlg = googleAPI.getErrorDialog(MyActivity.this, result, 1111, listener);
When this runs, the String common_google_play_services_update_text is correctly written to LogCat, but getErrorDialog() throws this Exception:
java.lang.NoSuchFieldError: No static field
common_google_play_services_update_text of type I in class
Lcom/google/android/gms/R$string; or its superclasses (declaration of
'com.google.android.gms.R$string' appears in
/data/app/com.mygame-1/base.apk)
How can I fix this?
The error NoSuchFieldError means that the class doesn't have a field of a specified name. It is thrown if an application tries to access or modify a specified field of an object, and that object no longer has that field. Normally, this error is caught by the compiler and can only occur at run time if the definition of a class has incompatibly changed.
Also, maybe you've got old code that is referencing a field that no longer exists in the recompiled class files. You may check it here.
The solution is to clean out all the class files and compile everything from fresh.
Update: If you still get the same error after recompiling everything, then you're probably compiling against one version of an external library and using another at runtime.
What you need to do now is first identify the class that is causing the problem (it looks like you have done this already) and then run your application with the -verbose:class command line option. It will dump a lot of class loading information on your standard out and you'll be able to find out where the problematic class is exactly loaded from.
Hope this helps!
I am using JasperReports 5.6 via API. I am building a report using iReport. The problem is that I've already set a jar with bean factory in the classpath of iReport as
com.myname.beanproject.beanpackage.BeanFactoryClass
Also I set up static method to call a list of beans:
getListEntries
but still getting a error while testing a connection. What am I doing wrong?
Error is not helpful at all:
General problem: null
As I can see, the problem is not in classpath neither factory: when I change any, the error is changing either to
"No class found"
(if I add something to class name)
or
"General problem: com.myname.beanproject.beanpackage.BeanFactoryClass.getListEntries11111()"
(if I add 11111 to the name of factory method to test)
Your getListEntries() method should be static and public too
that way , ireport can deal with it :)
i ran into the same problem, i had put my method like that
protected static getmyBeans().....
i fix the connection test after i put
public static getmyBeans().....
in my factoryClass
so check your method defenition
and dont forget to rebuild your jar code
and restart ireport
good luck, and sorry if i do mistakes in my english language
I just ran into the same problem. Your getListEntries() method should be static. That fixed it for me.
I am attempting to run a tomcat application, but when I try to go to the application I get:
java.lang.NoClassDefFoundError: Could not initialize class ysl.util.Utils
ysl.util.Utils.executeQuery(Utils.java:186)
ysl.util.Utils.getProperty(Utils.java:395)
ysl.util.Utils.getProperty(Utils.java:383)
ysl.util.YslMachineProperties.init(YslMachineProperties.java:76)
ysl.util.YslMachineProperties.getTomcatImagesDirectory(YslMachineProperties.java:109)
org.apache.jsp.YSLLogin_jsp._jspService(YSLLogin_jsp.java:70)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
I have found many references to this problem on the web - most say there was a class available when the application was compiled that is not available at run time and that I need to add something to the java classpath to find it. But how can I determine what class is missing?
The error message says that the Utils class could not be initialized, yet the stacktrace shows that we are into the second method in the class, so I would think that the class was already initialized. And certainly that is not the class whose definition can't be found, since we have line number information in the stacktrace.
The method which is triggering the error looks like this:
static public ResultSet executeQuery(String queryString) throws SQLException {
return dbConnPool.executeQuery(queryString);
Any suggestions?
Most likely the Utils class is trying to use another class that is unavailable during static initialization (that would be the root cause that #BalusC pointed out). The failure to load that class causes Utils to fail as well, so even though Utils is defined, its dependencies are not.
If you are using oracle (ex Sun) java, try running:
java -verbose:class
more options under http://download.oracle.com/javase/6/docs/technotes/tools/windows/java.html
You will see what classes were loaded.
I'm trying to use the org.apache.ddlutils package for reading database metadata.
I've written the following method:
public static void readMetaData(DataSource dataSource) throws DdlUtilsException{
final Platform platform = PlatformFactory.createNewPlatformInstance(dataSource);
}
But the statement throws DdlUtilsException gives the following error:
No exception of type DdlUtilsException can be thrown; an exception type must be a subclass of Throwable
I simply do not understand the reason behind this error because the API at http://db.apache.org/ddlutils/api/org/apache/ddlutils/DdlUtilsException.html clearly states the following:
java.lang.Object
extended by java.lang.Throwable
extended by java.lang.Exception
extended by java.lang.RuntimeException
extended by org.apache.commons.lang.exception.NestableRuntimeException
extended by org.apache.ddlutils.DdlUtilsException
Please advice.
My guess is that you've got another class called DdlUtilsException somewhere - possibly in the top-level package, given that the compiler isn't mentioning a full package name. If you're using Eclipse or something similar, try to navigate to the class declaration.
EDIT: Okay, judging by your comment, you aren't including the various dependencies. Make sure you've downloaded DdlUtils-1.0-bin.zip, and the dependencies are all in the lib directory. It's not immediately clear to me whether you need all of them, but you might as well use them all to start with, and then remove what you don't need.
It looks like that other class 'org.apache.commons.lang.exception.NestableRuntimeException' is located in commons-lang. Download and add that jar and it should work. Check the docs for DDL Utils and see what else it depends on.