I've been trying to use Retrofit with an API which works with XML. I also notice that retrofit have an XML Converter called SimpleXmlConverter here:
https://github.com/mobile-professionals/retrofit-simplexmlconverter
But when I tried to use it, got this error:
FATAL EXCEPTION: Thread-14844
retrofit.RetrofitError: retrofit.converter.ConversionException: java.lang.ClassCastException: org.apache.harmony.luni.lang.reflect.ImplForType cannot be cast to java.lang.Class
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:409)
at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:284)
at com.aaaa.common.$Proxy0.configs(Native Method)
at com.aaaa.common.DemoAPI.getContributos(DemoAPI.java:47)
at com.aaaa.MainActivity$1.run(MainActivity.java:27)
at java.lang.Thread.run(Thread.java:841)
Caused by: retrofit.converter.ConversionException: java.lang.ClassCastException: org.apache.harmony.luni.lang.reflect.ImplForType cannot be cast to java.lang.Class
at retrofit.converter.SimpleXMLConverter.fromBody(SimpleXMLConverter.java:38)
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:394)
at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:284)
at com.aaaa.common.$Proxy0.configs(Native Method)
at com.aaaa.common.DemoAPI.getContributos(DemoAPI.java:47)
at com.aaaa.MainActivity$1.run(MainActivity.java:27)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.lang.ClassCastException: org.apache.harmony.luni.lang.reflect.ImplForType cannot be cast to java.lang.Class
at retrofit.converter.SimpleXMLConverter.fromBody(SimpleXMLConverter.java:36)
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:394)
at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:284)
at com.aaaa.common.$Proxy0.configs(Native Method)
at com.aaaa.common.DemoAPI.getContributos(DemoAPI.java:47)
at com.aaaa.MainActivity$1.run(MainActivity.java:27)
at java.lang.Thread.run(Thread.java:841)
I'm making a sample App so I'm just trying to be simple with my code:
RestAdapter restAdapter = new RestAdapter.Builder()
//.setEndpoint(API_URL)
.setServer(API_URL)
.setConverter(new SimpleXMLConverter())
.build();
And
static class Config {
String name;
int firstInt;
int secondInt;
}
interface Demo {
#GET("/{user}/api/config")
List<Config> configs (
#Path("user") String owner
);
}
You're not using the "SimpleXmlConverter" class that belongs to the retrofit-simplexmlconverter library. Instead you're using the "SimpleXMLConverter" class (see uppercase "XML") that is part of retrofit itself since a while. I'd advise you to go with the official one as this is unit tested and under more active development.
I created the retrofit-simplexmlconverter lib when there was no xml converter for retrofit yet.
Unfortunately I don't see the reason for your problem at first sight. The implementation of the converter classes should be similar. So concerning your problem I think it shouldn't make a difference which one you use. If I were you I'd step in with a debugger to get a clue about what's causing the ClassCastException.
Got it!!
Looks like Inner Classes can't be instantiated in the same way than normal classes by reflect, they need to be instantiated by a Constructor, so.. SimpleXMLconverter not works with inner classes like mine:
static class Config {
String name;
int firstInt;
int secondInt;
}
I just made a new folder "Models" with that classes and works perfect! ;)
Really thanks to #Sebastian Engel for teach me and show me how it to solve it.
Related
I have the following TextView
<TextView
android:id="#+id/LoginlinkLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical center_horizontal"
android:autoSizeMaxTextSize="45sp"
android:autoSizeMinTextSize="15sp"
android:autoSizeStepGranularity="2sp"
android:text="#string/Loginlink"
android:textAlignment="center"
android:textSize="15sp"
android:onClick="loginlinkLabelonClick"
android:clickable="true"/>
And this function
fun loginlinkLabelonClick(context:Context)
{
val urlString="http://www.google.gr"
val intent = Intent(Intent.ACTION_VIEW,Uri.parse(urlString)) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
intent.`package`="com.android.chrome"
try
{
context.startActivity(intent)
}
catch(ex:ActivityNotFoundException)
{
intent.`package`= null
context.startActivity(intent)
}
}
The error message:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.reviewer.reviewer, PID: 27809
java.lang.IllegalStateException: Could not find method loginlinkLabelonClick(View) in a parent or ancestor Context for
android:onClick attribute defined on view class
android.support.v7.widget.AppCompatTextView with id 'LoginlinkLabel'
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.resolveMethod(AppCompatViewInflater.java:423)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:380)
at android.view.View.performClick(View.java:6291)
at android.view.View$PerformClick.run(View.java:24931)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:101)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7425)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
But as soon as I tap the textview the application crashes and I can't seem to find what's wrong.
I'm new to Java, kotlin and Android studio.
I had a previous experience with visual studio and c# and Java / kotlin feels a bit strange
Now I'm really trying to figure out how to open urls, but I'm having trouble getting it to work
Usually when you have a click method in the xml, the argument for the method in kotlin is a view instance, see more here. So your method should look like this:
fun loginlinkLabelonClick(view:View)
{
}
The following lines within a Fragment are throwing an exception for which I am unable to find the root cause.
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_player_pane, container, false);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) rootView.getLayoutParams();
// set width height
params.height = (getArguments().getInt(HEIGHT));
params.width = (getArguments().getInt(WIDTH));
fragmentHeight = (getArguments().getInt(HEIGHT));
fragmentWidth = (getArguments().getInt(WIDTH));
// substitute parameters for left,top, right, bottom, (All 4 not necessary)
params.setMargins((getArguments().getInt(LEFT_MARGIN)),
(getArguments().getInt(TOP_MARGIN)),
(getArguments().getInt(RIGHT_MARGIN)),
(getArguments().getInt(BOTTOM_MARGIN)));
youTubePlayerNecessary = getArguments().getBoolean(REQUIRE_YOUTUBE);
rotate = getArguments().getBoolean(REQUIRE_ROTATION);
muteAudio = getArguments().getBoolean(MUTE_AUDIO);
rootView.setLayoutParams(params);
return rootView;
}
Exception:
11-02 11:36:04.966 3440-3452/com.blynq.app.multipaneplayer E/StrictMode: A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
java.lang.Throwable: Explicit termination method 'close' not called
at dalvik.system.CloseGuard.open(CloseGuard.java:184)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:127)
at com.android.webview.chromium.WebViewChromiumFactoryProvider.startChromiumLocked(WebViewChromiumFactoryProvider.java:16107)
at com.android.webview.chromium.WebViewChromiumFactoryProvider.ensureChromiumStartedLocked(WebViewChromiumFactoryProvider.java:333)
at com.android.webview.chromium.WebViewChromiumFactoryProvider.startYourEngines(WebViewChromiumFactoryProvider.java:427)
at com.android.webview.chromium.WebViewChromium.init(WebViewChromium.java:162)
at android.webkit.WebView.<init>(WebView.java:554)
at android.webkit.WebView.<init>(WebView.java:489)
at android.webkit.WebView.<init>(WebView.java:472)
at android.webkit.WebView.<init>(WebView.java:459)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at com.blynq.app.fragments.PlayerPane.onCreateView(PlayerPane.java:181)
at android.app.Fragment.performCreateView(Fragment.java:2053)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:894)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.app.BackStackRecord.run(BackStackRecord.java:834)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1454)
at android.app.FragmentManagerImpl$1.run(FragmentManager.java:447)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5343)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
I am currently running app in debug mode to check all possible memory leaks.
if (BuildConfig.DEBUG) {
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectAll()
.penaltyLog()
.penaltyDeath()
.build());
}
All tags in manifest file are properly closed too. I am unable to figure out which resource was left open without being handled. How do I resolve this ?
P.S. I have referred to thread before asking the question, which is a very generic question offering no new necessary insight for me. This question is very specific to the details mentioned above, here I am seeking help to find which resource is causing the leak..
Somebody raised an issue for this here: https://code.google.com/p/android/issues/detail?id=226751
I've been having the same issue, and it looks like it's a bug in API < 25. Try your program in an emulator with API 25 and see if it works. If it works there, then it is most likely the same problem and you are out of luck until is able to fix the issue.
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog()
.penaltyDeath().build());
For more Information Follow this Url
Error Solve Url
With app TalkBack active, I receive the exception:
java.lang.IllegalArgumentException: Comparison method violates its general contract!
The problem is I'm not using comparision method on my code.
Follow the complete exception:
java.lang.IllegalArgumentException: Comparison method violates its general contract!
at java.util.ComparableTimSort.mergeLo(ComparableTimSort.java:710)
at java.util.ComparableTimSort.mergeAt(ComparableTimSort.java:447)
at java.util.ComparableTimSort.mergeCollapse(ComparableTimSort.java:372)
at java.util.ComparableTimSort.sort(ComparableTimSort.java:178)
at java.util.ComparableTimSort.sort(ComparableTimSort.java:142)
at java.util.Arrays.sort(Arrays.java:1970)
at java.util.Collections.sort(Collections.java:1864)
at android.view.ViewGroup$ChildListForAccessibility.init(ViewGroup.java:6635)
at android.view.ViewGroup$ChildListForAccessibility.obtain(ViewGroup.java:6600)
at android.view.ViewGroup.addChildrenForAccessibility(ViewGroup.java:1703)
at android.view.ViewGroup.onInitializeAccessibilityNodeInfoInternal(ViewGroup.java:2529)
at android.view.View.onInitializeAccessibilityNodeInfo(View.java:5225)
at android.widget.AdapterView.onInitializeAccessibilityNodeInfo(AdapterView.java:937)
at android.widget.AbsListView.onInitializeAccessibilityNodeInfo(AbsListView.java:1494)
at android.widget.GridView.onInitializeAccessibilityNodeInfo(GridView.java:2263)
at android.view.View.createAccessibilityNodeInfoInternal(View.java:5186)
at android.view.View.createAccessibilityNodeInfo(View.java:5173)
at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchDescendantsOfRealNode(AccessibilityInteractionController.java:811)
at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchDescendantsOfRealNode(AccessibilityInteractionController.java:834)
at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchAccessibilityNodeInfos(AccessibilityInteractionController.java:720)
at android.view.AccessibilityInteractionController.findAccessibilityNodeInfoByAccessibilityIdUiThread(AccessibilityInteractionController.java:147)
at android.view.AccessibilityInteractionController.access$300(AccessibilityInteractionController.java:49)
at android.view.AccessibilityInteractionController$PrivateHandler.handleMessage(AccessibilityInteractionController.java:971)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)
Why I've this exception only with TalkBack active? This exception appear after that gridview is loaded (on display the gridview is loaded correctly)
Thanks a lot
EDIT:
I've found that the problem is on this code line:
public class GridLayoutAdapter extends BaseAdapter
{
#Override
public View getView(int position, View view, ViewGroup parent) {
view.setLayoutParams(new GridView.LayoutParams(60, 60));
}
How to resolve the problem? I don't know why I've a Comparison method violates
(if I try to comment the line it works without crash)
A few days ago we started to receive some crash reports from users using our app, but the stracktrace is really strange. It happens only on Samsung G900f (S5) and I can't reproduce it and decide to post a question here.
The stacktrace shows this:
Caused by java.lang.ClassCastException: android.support.design.widget.CollapsingToolbarLayout cannot be cast to android.support.design.widget.CollapsingToolbarLayout
at com.packageName.profile.ProfileFragment.onViewCreated(SourceFile:423)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1086)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1248)
at android.support.v4.app.BackStackRecord.run(SourceFile:738)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(SourceFile:1613)
at android.support.v4.app.FragmentController.execPendingActions(SourceFile:330)
at android.support.v4.app.FragmentActivity.onStart(SourceFile:547)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1234)
at android.app.Activity.performStart(Activity.java:6258)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2621)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2725)
at android.app.ActivityThread.access$900(ActivityThread.java:172)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1422)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5834)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
It is a Fragment which contains CollapsingToolbarLayout with initialization and use all correct, but not sure why this happens.
We got some other ClassCastExceptions with different classes from the same device. For example:
Caused by java.lang.ClassCastException:
com.packageName.model.VideoMeta cannot be cast to
com.packageName.model.VideoMeta
where VideoMeta is a class which implements Parcelable and this exception occurs in class Video which implements Parcelable too:
private Video(Parcel in) {
id = in.readLong();
postId = in.readString();
url = in.readString();
thumb = in.readString();
meta = (VideoMeta) in.readValue(VideoMeta.class.getClassLoader());
}
But that's not the end...
Caused by java.lang.ClassCastException:
android.support.design.widget.AppBarLayout$LayoutParams cannot be cast to
android.support.design.widget.AppBarLayout$LayoutParams
I have no idea what can cause this exception and why it's happening, that's why posting it here.
Thanks in advance for any kind of help or suggestions!
I'm developing a VR video viewer using Android Cardboard SDK and RajawaliVR (https://github.com/Rajawali/RajawaliVR)
On some devices I have this crash when returning from sleep (others just show black screen):
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.opengl.GLSurfaceView$GLThread.surfaceCreated()' on a null object reference
at android.opengl.GLSurfaceView.surfaceCreated(GLSurfaceView.java:523)
at android.view.SurfaceView.updateWindow(SurfaceView.java:580)
at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:176)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:944)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1970)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1061)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5891)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:550)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
As you can see the crash is in the android code, how do I start debugging it?
You have access to the source code, so start with that.
Assuming you're using Lollipop, it's failing on this line:
mGLThread.surfaceCreated();
The error message indicates that mGLThread is null. Doing a simple search for the assignment ("mGLThread =") with the web browser reveals two instances, the most interesting of which is this one:
public void setRenderer(Renderer renderer) {
...
mGLThread = new GLThread(mThisWeakRef);
Setting some of the complexities aside, mGLThread should be non-null so long as setRenderer() is called. So the first thing to do is check to see if your application is calling setRenderer() (typically in onCreate()).
If you're following along the Android Developer OpenGL tutorial, it's possible that Android Studio corrected this definition in your Activity class constructor:
mGLView = new MyGLSurfaceView(this);
and changed it to
mGLView = new GLSurfaceView(this);
because the class MyGLSurfaceView had not been coded yet...skipping the MyGLSurfaveView constructor which is where setRenderer(...) is called. Mr. fadden's answer above is excellent, explains how to diagnose the problem.