ClassCastException on getting custom view

I have a layout like this:

<com.mypackage.QuadPaneHorizontalSplit xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/root_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <!-- more views here --> </com.mypackage.QuadPaneHorizontalSplit> 

The QuadPaneHorizontalSplit class extends QuadPaneLayout (which extends LineraLayout):

 public class QuadPaneHorizontalSplit extends QuadPaneLayout { public QuadPaneHorizontalSplit(Context context) { super(context); } public QuadPaneHorizontalSplit(Context context, AttributeSet attrs) { super(context, attrs); } @TargetApi(Build.VERSION_CODES.HONEYCOMB) public QuadPaneHorizontalSplit(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override protected boolean isVerticalSplit() { return false; } } 

After setting up the layout using setContentView, I try to get a custom view:

 QuadPaneLayout quadPaneLayout = (QuadPaneLayout) findViewById(R.id.root_layout); 

which works fine overall, but I got some crash reports with the following exception:

java.lang.ClassCastException: com.mypackage.QuadPaneHorizontalSplit cannot be added to com.mypackage.QuadPaneLayout

QuadPaneHorizontalSplit explicitly extends QuadPaneLayout, so an exception should not be possible. I get crash reports from Android 4.x devices and from different manufacturers. Interestingly, all devices are rooted so maybe this is a problem with some custom rom? Please note that this line of code is executed thousands of times every day without any problems, and so far I have received only 13 crashes (BugSense), but I still would like to figure this out.

I know about this: https://stackoverflow.com/a/464626/232632/ , but I do not use include for this layout, and I would not want to add a merge label because this could have unwanted effects.

Anyone have an idea what is going on here?

+6
source share
2 answers

I finally found the answer to this question, which may be of interest to other developers.

Since I had many other inexplicable crashes, including VerifyErrors, ClassNotFoundExceptions, and ActivityNotFoundExceptions, I got a suspicion about the origin of these crash reports. I added an β€œextra code” to make sure that the application was not tampered with, and if it was a bug report, it would show. In fact, all ClassCastException crashes occurred when I found that this application was clearly cracked, which also explains why I received this crash report only for the paid version of the application and why the paid application seems to crash much more often than the free .

Maybe it's time to spend this extra money on a DexGuard license ...

0
source

Hmm ... This happens to me sometimes, but it usually gets fixed as soon as I clean up the project. In this case, it is similar to os / device / user specific. How often do you choose QuadPaneHorizontalSplit for QuadPaneLayout? Perhaps you have another instance of "R.id.root_layout" where it is not the same View object? Maybe this is causing the problem?

Edit : Nevermind, I forgot a ClassCastException, specifically from QuadPaneHorizontalSplit to QuadPaneLayout, so it's probably not another instance of "R.id.root_layout". What other information do you get from BugSense?

0
source

All Articles