I am trying to use a PageAdapter. I found out that public Object instantiateItem( View pager, int position ) has been deprecated. So I am trying up update but ran into a problem. The new definition changes the deceration to public Object instantiateItem( ViewPager pager, int position ), when I do this and push it to my device the app crashed.
Here is my logcat output.
12-26 19:24:30.701: ERROR/AndroidRuntime(25431): FATAL EXCEPTION: main
java.lang.UnsupportedOperationException: Required method instantiateItem was not overridden
at android.support.v4.view.PagerAdapter.instantiateItem(PagerAdapter.java:175)
at android.support.v4.view.PagerAdapter.instantiateItem(PagerAdapter.java:110)
at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:649)
at android.support.v4.view.ViewPager.populate(ViewPager.java:783)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1016)
So I added #Override to the method call, but when I compile it ,using maven, I get the following output that corresponds to my method.
Chronos/ChronosApp/src/com/kopysoft/chronos/view/ClockViewer.java:[67,4] error: method does not override or implement a method from a supertype
I am at a lose as what to do. Any advice would be greatly appreciated!
The entire code can be found here: http://pastebin.com/da5Kqcmg
The runtime code in PagerAdapter.instantiateItem() is throwing the exception because it wants you to override that. So make sure you are overriding the method that is throwing the exception. You probably just want to switch your code back to overriding the deprecated method since that's what your runtime library is expecting.
Might it be possible that you have an older runtime you are running with?
Related
Hey guys I need some help. The problem is my jni is not loading after changing package name. Before it was working pretty cool. I have tried to solve it but I can't. So please help me.
This is the error:
JNI DETECTED ERROR IN APPLICATION: JNI NewGlobalRef called with pending exception 'java.lang.ClassNotFoundExceptio
in call to NewGlobalRef
from java.lang.String java.lang.Runtime.nativeLoad(java.lang.String, java.lang.ClassLoader, java.lang.String)
JNI DETECTED ERROR IN APPLICATION: JNI NewGlobalRef called with
pending exception 'java.lang.ClassNotFoundException' in call to
NewGlobalRef from java.lang.String
java.lang.Runtime.nativeLoad(java.lang.String, java.lang.ClassLoader,
java.lang.String)
You had a pending exception when you called NewGlobalRef. When an exception occurs when executing JNI code, your app doesn't crash, but a "pending exception" is created. It is your responsibility to check for exceptions when doing JNI work which might throw an exception.
After a pending exceptions is created, only a handful of JNI methods are safe to call( mentioned here).
In your case, your app crashed because before you called NewGlobalRef after a pending exception was thrown. NewGlobalRef is not in the list of methods safe to call after an exception. However, you also see the cause of the pending exception: java.lang.ClassNotFoundException.
Most likely this happened because you tried to do something similar:
cls = (*env)->FindClass(env, "com/example/ndktest/SomeClass");
but then you changed the package name of SomeClass from com.example.ndktest.SomeClass to com.other.package.SomeClass. However, you probably didn't also change how you searched for the class..so you need to also update your FindClass(...) call to:
cls = (*env)->FindClass(env, "com/other/package/SomeClass");
Hope this helps
I'm developing a Java ME project in Intellij. When I try to call a function from the javax.microedition package, all functions simply return null. After inspection, these functions exist but contain no substance (are unimplemented). For example, the javax.microedition.io.connector class function .open(String var) appears this way and always returns null:
public static Connection open(String var0) throws IOException {
return null;
}
This function does not match the documentation provided by Oracle and according to the documentation Connector is not an abstract class. All other functions I inspected seem to be implemented the same way. Did I miss a step in setting up the Java ME SDK? Am I missing something?
Additionally this is the code I try to run but returns null:
ServerSocketConnection server = (ServerSocketConnection) Connector.open("socket://:4040");
These are called stub classes. They only contain method signatures and default return values. You can use them to compile your code without problems.
When you run your app on an emulator (or on an actual device) these classes will have a proper implementation and behave as expected.
I've a problem with my build and it caused a huge headache for me.
I had an old class and I was using it to fetch data from it, and I created a new class with the same methods. When I test it locally on my machine, everything works fine, but when I try to do a build, it broke because it's unstable and I got this error in the log file:
Caused by: java.lang.NoSuchMethodError: com.mashvisor.bean.Neighborhood.getTraditionalRates()Lcom/mashvisor/database/dao/views/NeighborhoodRentalRates;
at com.mashvisor.database.dao.PropertyDao.retrieve(PropertyDao.java:91)
The NeighborhoodRentalRates class is the old class, and in my code I'm sure im not using it nor trying to access it in that line, here's my code for that line:
Hibernate.initialize(property.getNeighborhood().getTraditionalRates());
and here's it's declaration
public TraditionalNeighborhoodRentalRates getTraditionalRates() {
return traditionalRates;
}
The TraditionalNeighborhoodRentalRates is the new class, and the only change here is the class name.
Could any body help?
Your code is still calling the old method, i.e. it is looking for a method with the signature:
public NeighborhoodRentalRates getTraditionalRates() { ... }
Just using the same names it not enough. To have classes with the same (method-)interface, you have to have the same names, return types and argument types in all methods.
So you need to go through your calling code and make sure the new type is expected everywhere as return type and recompile the calling code.
I have implemented the method as below but there is an error saying - remove override annotation, which should be there. Under which circumstances this error would occur? Due to this my beans are not being created and I am not able to run the application.
#Override
public void setServletContext(ServletContext servletContext) {
}
The error which shows up on the console is - "The method setServletContext(ServletContext) of type MenuHelper must override a superclass method". But the method is there and goes undetected. If I remove the method, there should be an error saying add the unimplemented methods - which is also not showing up. Kindly help me with this situation. Thanks
I can't be sure without seeing the rest of your code, but from that error I'm guessing that your class does not implement ServletContextAware properly.
I think I've discovered a kind of Schrödinger's cat problem in my code. The body of a function is never executed if I change one line within the body of that same function; but if I leave that line alone, the function executes. Somehow the program knows ahead of time what the body is, and decides not to call it...
I'm working on an Eclipse RCP application in Java, and have need to use their Error Handling System. According to the page linked,
There are two ways for adding handlers to the handling flow.
using extension point org.eclipse.ui.statusHandlers
by the workbench advisor and its method {#link WorkbenchAdvisor#getWorkbenchErrorHandler()}.
So I've gone into my ApplicationWorkbenchAdvisor class, and overridden the getWorkbenchErrorHandler method:
#Override
public synchronized AbstractStatusHandler getWorkbenchErrorHandler()
{
System.out.println("IT LIVES!");
if (myErrorHandler == null)
{
AbstractStatusHandler delegate = super.getWorkbenchErrorHandler();
MyStatusHandler otherThing = new MyStatusHandler(delegate);
myErrorHandler = otherThing;
}
return myErrorHandler;
}
The MyStatusHandler is meant to act as a wrapper for the delegate handler. I've re-named the class for anonymity. As it is, above, this function is never called. The println never happens, and even in debug mode with breakpoints, they never trigger. Now the wierd part: If I change the line that assigns the myErrorHandler to
myErrorHandler = delegate;
then the function is called; multiple times, in fact!
This problem has me and two java-savvy coworkers stumped, so I'm hoping the good people of SO can help us!
As it turned out, my problem was that the MyErrorHandler class was defined in a different plugin, which presumably wasn't fully loaded yet. That doesn't seem to add up entirely, but once I moved the class definition of my error handler into the same plugin that was calling it during startup, the problems went away.