I am trying to make a custom transform class that takes in a side input and I am using PipelineTester and PAssert to try and test it, but I keep getting a no such method exception on methods I am trying to bring into the transform from other classes.
Caused by: java.lang.NoSuchMethodError:
com.org.utils.MyUtils.createMap(Ljava/lang/Iterable;)Ljava/util/Map;
at com.org.beam.MyTransform.ProcessElement(MyTransform.java:51)
I have tried using the #Autowired annotation to bring in the class like
#Autowired
private MyUtils myutils;
as well as just creating a static instance in the code like
private static MyUtils myUtils = new MyUtils();
and then calling
this.myUtils.createMap(mapThisToThat(inputCollection, this.myMap));
I have also tried making the methods static and calling them like
MyUtils.createMap(mapThisToThat(inputCollection, this.myMap));
the signature to mapThisToThat is
private Iterable<MyObject> mapThisToThat(Iterable<MyObject> objectIterator, Map<String, Integer> myMap) {
which is being passed into the createMap method which has this signature -
public Map<String, MyObject> createMap(Iterable<MyObject> inputCollection){
so it is passing in an Iterable of MyObjects correctly, but it says the method doesn't exist for some reason. does this mean beam transforms can't have external methods or am I doing something wrong?
For me in python, there are a variety of things I need to do for that to work:
https://cloud.google.com/dataflow/faq#how-do-i-handle-nameerrors
https://beam.apache.org/documentation/sdks/python-pipeline-dependencies/
For you in java, they don't have reciprocal documentation for some reason, but over here https://beam.apache.org/documentation/runners/dataflow/ they say things like this:
In some cases, such as starting a pipeline using a scheduler such as Apache AirFlow, you must have a self-contained application. You can pack a self-executing JAR by explicitly adding the following dependency on the Project section of your pom.xml, in addition to the adding existing dependency shown in the previous section.
In their examples readme https://github.com/mbrukman/apache-beam/tree/master/examples/java they say this
Alternatively, you may choose to bundle all dependencies into a single JAR and execute it outside of the Maven environment. For example, you can execute the following commands to create the bundled JAR of the examples and execute it both locally and in Cloud Platform
If you continue to browse that examples repo, there is a common folder with utils. Hopefully you can copy how they did it.
I have an application that I've been trying to get working with Java 8's RMI. I'm using eclipse Neon.3 on Windows 10 and it is complaining that I am not implementing methods of an interface that don't exist. In trying to narrow down a separate issue, I've commented out one of the abstract methods of the interface.
After commenting out the one abstract method, the interface is then exported to a jar file; the jar file is then added to the build path of the server application that will implement the interface.
The interface:
package accessService;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.HashMap;
public interface ApplicationAccessService extends Remote{
//public void connectClient(Long[] clientId) throws RemoteException;
public HashMap<String, Long> getClientConnections() throws RemoteException;
public HashMap<String, Integer> getServerConnections() throws RemoteException;
}
The implementing class:
package iap.util;
import java.rmi.RemoteException;
import java.util.HashMap;
import accessService.ApplicationAccessService;
public class RemoteIAP implements ApplicationAccessService{
private final static HashMap<String, Integer> SERVERS = new HashMap<>();
private final static HashMap<String, Long> CLIENTS = new HashMap<>();
public RemoteIAP(){ }
//methods used by RMI interface--------------------------------------
#Override
public HashMap<String, Integer> getServerConnections() throws RemoteException {
return SERVERS;
}
#Override
public HashMap<String, Long> getClientConnections() throws RemoteException {
return CLIENTS;
}
//end RMI methods-------------------------------------------------------
}
The error:
The type RemoteIAP must implement the inherited abstract method ApplicationAccessService.connectClient(Long[])
It seems to me, that eclipse is somehow maintaining artifacts from before commenting out the method in question. Restarting eclipse and rebooting my pc has done nothing to change this behavior. I don't know if this is a problem with java, the manner I'm adding the interface to the build path using the context menu's in eclipse, or something else?
Sometimes, ide can read the old compiled .class file and somehow it does not replace with the new one after the build operation.
Change the class name and build again.
I think it's possible that taking out the line and then exporting may have failed. Understand that in the .jar, it is the code in the compiled .class file that matters, not in the .java file. So if you hadn't recompiled before exporting, you could have an old version in the .jar
I'm working on osgi application which uses com.ibm.ws.admin.client_8.5.0.jar because I need to use WebSphere with JMX.
When I import as dependency this jar I get error in bundle activators:
public abstract class AbstractServiceTracker implements ServiceTrackerCustomizer<Object, Object> {
...
private ServiceTracker<Object, Object> tracker = new ServiceTracker<>(bc, bc.createFilter(builder.toString()), this);
I get error in Netbeans type ServiceTrackerCustomizer does not take parameters and cannot infer type arguments for ServiceTracker<>
i suppose that this is a classpath issue. When i remove com.ibm.ws.admin.client_8.5.0.jar it's working fine. In this case what are the options to solve this problem?
I am working on a project that is having a layered Architecture.
I have a interface ABC and in that interface I have a enum XYZ
For ex
public interface ABC {
public enum XYZ {
CONSTANT1("SOMETHING"),
CONSTANT2("SOMETHING3");
final String name;
private TYPE(String name) {
this.name=name;
}
public String getName() {
return this.name;
}
}
}
I am compiling this using ant and using this jar file in other layer. In that layer I am trying to access it like
String name=ABC.XYZ.CONSTANT1.getName();
I am getting symbol not found error during compile. I verified classpath is set properly.
I am using ant v 1.8 and java 1.6.
Why I am getting this error ?
First of all, don't nest the enum in an interface. It's perfectly fine that it has its own source file named after the enum.
Second, I assume you mean XYZ instead of TYPE in your private constructor?
Last, you should be able to use it in that way, no matter if compiled via ant or within eclipse or directly using javac. Probably you have not compiled everything - the way you did it, there should be ABC.class (the interface), ABC$XYZ.class (the inner enum) and the class file of your calling class.
I am getting an exception and I can't find the reason of it.
The exception I get is :
java.lang.IllegalAccessError: tried to access method Connected.getData(Ljava/lang/String;)Ljava/sql/ResultSet; from class B
The method is public.
public class B
{
public void myMethod()
{
Connected conn = new Connected(); // create a connected class in order to connect to The DB
ResultSet rs = null; // create a result set to get the query result
rs = conn.getData(sql); // do sql query
}
}
public class Connected
{
public ResultSet getData(String sql)
{
ResultSet rs = null;
try
{
prepareConnection();
stmt = conn.createStatement();
stmt.execute(sql);
rs = stmt.getResultSet();
}
catch (SQLException E)
{
System.out.println("Content.getData Error");
E.printStackTrace();
}
return rs;
}
i am using apache tomcat 5.5.12
and JAVA 1.6
This happens when accessing a package scoped method of a class that is in the same package but is in a different jar and classloader.
This was my source, but the link is now broken. Following is full text from google cache:
Packages (as in package access) are scoped per ClassLoader.
You state that the parent ClassLoader loads the interface and the child
ClassLoader loads the implementation. This won't work because of the
ClassLoader-specific nature of package scoping. The interface isn't visible to
the implementation class because, even though it's the same package name,
they're in different ClassLoaders.
I only skimmed the posts in this thread, but I think you've already discovered
that this will work if you declare the interface to be public. It would also
work to have both interface and implementation loaded by the same ClassLoader.
Really, if you expect arbitrary folks to implement the interface (which you
apparently do if the implementation is being loaded by a different
ClassLoader), then you should make the interface public.
The ClassLoader-scoping of package scope (which applies to accessing package
methods, variables, etc.) is similar to the general ClassLoader-scoping of
class names. For example, I can define two classes, both named com.foo.Bar,
with entirely different implementation code if I define them in separate
ClassLoaders.
Joel
You are almost certainly using a different version of the class at runtime to the one you expect. In particular, the runtime class would be different to the one you've compiled against (else this would have caused a compile-time error) - has that method ever been private? Do you have old versions of the classes/jars on your system anywhere?
As the javadocs for IllegalAccessError state,
Normally, this error is caught by the compiler; this error can only occur at run time if the definition of a class has incompatibly changed.
I'd definitely look at your classpath and check whether it holds any surprises.
This happened to me when I had a class in one jar trying to access a private method in a class from another jar. I simply changed the private method to public, recompiled and deployed, and it worked ok afterwards.
I was getting this error on a Spring Boot application where a #RestController ApplicationInfoResource had a nested class ApplicationInfo.
It seems the Spring Boot Dev Tools was using a different class loader.
The exception I was getting
2017-05-01 17:47:39.588 WARN 1516 --- [nio-8080-exec-9]
.m.m.a.ExceptionHandlerExceptionResolver : Resolved exception caused
by Handler execution:
org.springframework.web.util.NestedServletException: Handler dispatch
failed; nested exception is java.lang.IllegalAccessError: tried to
access class com.gt.web.rest.ApplicationInfo from class
com.gt.web.rest.ApplicationInfoResource$$EnhancerBySpringCGLIB$$59ce500c
Solution
I moved the nested class ApplicationInfo to a separate .java file and got rid of the problem.
If getData is protected then try making it public. The problem could exist in JAVA 1.6 and be absent in 1.5x
I got this for your problem. Illegal access error
I was getting same error because of configuration issue in intellij.
As shown in screenshot.
Main and test module was pointing to two different JDK. (Press F12 on the intellij project to open module settings)
Also all my dto's were using #lombok.Builder which I changed it to #Data.
From Android perspective:
Method not available in api version
I was getting this Issue primarily because i was using some thing that is not available/deprecated in that Android version
Wrong way:
Notification.Builder nBuilder = new Notification.Builder(mContext);
nBuilder.addAction(new Notification.Action(android.R.drawable.ic_menu_view,"PAUSE",pendingIntent));
Right way:
Notification.Builder nBuilder = new Notification.Builder(mContext);
nBuilder.addAction(android.R.drawable.ic_media_pause,"PAUSE",pendingIntent);
here Notification.Action is not available prior to API 20 and my min version was API 16
Just an addition to the solved answer:
This COULD be a problem with Android Studio's Instant Run feature, for example, if you realized you forgot to add the line of code: finish() to your activity after opening another one, and you already re-opened the activity you shouldn't have reopened (which the finish() solved), then you add finish() and Instant Run occurs, then the app will crash since the logic has been broken.
TL:DR;
This is not necessarily a code problem, just an Instant Run problem
In my case the problem was that a method was defined in some Interface A as default, while its sub-class overrode it as private. Then when the method was called, the java Runtime realized it was calling a private method.
I am still puzzled as to why the compiler didn't complain about the private override..
public interface A {
default void doStuff() {
// doing stuff
}
}
public class B {
private void doStuff() {
// do other stuff instead
}
}
public static final main(String... args) {
A someB = new B();
someB.doStuff();
}
In my case I was getting this error running my app in wildfly with the .ear deployed from eclipse. Because it was deployed from eclipse, the deployment folder did not contain an .ear file, but a folder representing it, and inside of it all the jars that would have been contained in the .ear file; like if the ear was unzipped.
So I had in on jar:
class MySuperClass {
protected void mySuperMethod {}
}
And in another jar:
class MyExtendingClass extends MySuperClass {
class MyChildrenClass {
public void doSomething{
mySuperMethod();
}
}
}
The solution for this was adding a new method to MyExtendingClass:
class MyExtendingClass extends MySuperClass {
class MyChildrenClass {
public void doSomething{
mySuperMethod();
}
}
#Override
protected void mySuperMethod() {
super.mySuperMethod();
}
}
I was getting similar exception but at class level
e.g. Caused by: java.lang.IllegalAccessError: tried to access class ....
I fixed this by making my class public.