Getting a java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams Error when using my library suddenly.
It had been working fine, but in one screen I have an Imageview which I add with a set size of the minimum of 50% X or 50% Y (This works fine) and then calculate its size later in Resume if there is a picture to show. The stack trace looks like it is failing when I get the Left for the Imageview.
My Class extends ViewWrapper<ScrollView>.
Then the function to add the view is:
It should have a layout, but it is like B4A doesn't know how to read it or something since it is from RelativeLayout. Is there a way to fix this? When running in debug it is showing the Activity Layout not available, my Relative Layout (Scrollview) has a layout, then my Imageview Layout is not available. Putting breaks in other parts of the code shows the Activity and Imageview never get a layout.
It had been working fine, but in one screen I have an Imageview which I add with a set size of the minimum of 50% X or 50% Y (This works fine) and then calculate its size later in Resume if there is a picture to show. The stack trace looks like it is failing when I get the Left for the Imageview.
My Class extends ViewWrapper<ScrollView>.
Then the function to add the view is:
B4X:
public void AddView(View NewView, String ViewName){
if (myRelLayout == null) {
myRelLayout= new RelativeLayout(ba.context);
LayoutParams myLayoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
myRelLayout.setLayoutParams(myLayoutParams);
getObject().addView(myRelLayout);
}
RelativeLayout.LayoutParams myLayoutParams = new RelativeLayout.LayoutParams(Width, Height);
myLayoutParams.setMargins(ViewLeftPadding, ViewTopPadding, ViewRightPadding, ViewBottomPadding);
if (xView.length() == 0) { // Assume Parent Align
if (xAlign == getxAlign_ParentLeft()) myLayoutParams.addRule(getxAlign_ParentLeft());
if (xAlign == getxAlign_ParentRight()) myLayoutParams.addRule(getxAlign_ParentRight());
if (xAlign == getxAlign_ParentCentHorz()) myLayoutParams.addRule(getxAlign_ParentCentHorz());
}
else {
if (viewList.containsKey(xView)){
if (xAlign == getxAlign_ViewLeft()) myLayoutParams.addRule(getxAlign_ViewLeft(), viewList.get(xView).getId());
if (xAlign == getxAlign_ViewRight()) myLayoutParams.addRule(getxAlign_ViewRight(), viewList.get(xView).getId());
if (xAlign == getxAlign_LeftOfView()) myLayoutParams.addRule(getxAlign_LeftOfView(), viewList.get(xView).getId());
if (xAlign == getxAlign_RightOfView()) myLayoutParams.addRule(getxAlign_RightOfView(), viewList.get(xView).getId());
}
}
if (yView.length() == 0) { // Assume Parent Align
if (yAlign == getyAlign_ParentTop()) myLayoutParams.addRule(getyAlign_ParentTop());
if (yAlign == getyAlign_ParentCentVert()) myLayoutParams.addRule(getyAlign_ParentCentVert());
}
else {
if (viewList.containsKey(yView)){
if (yAlign == getyAlign_AboveView()) myLayoutParams.addRule(getyAlign_AboveView(), viewList.get(yView).getId());
if (yAlign == getyAlign_BelowView()) myLayoutParams.addRule(getyAlign_BelowView(), viewList.get(yView).getId());
if (yAlign == getyAlign_ViewTop()) myLayoutParams.addRule(getyAlign_ViewTop(), viewList.get(yView).getId());
if (yAlign == getyAlign_ViewBottom()) myLayoutParams.addRule(getyAlign_ViewBottom(), viewList.get(yView).getId());
if (yAlign == getyAlign_ViewBaseline()) myLayoutParams.addRule(getyAlign_ViewBaseline(), viewList.get(yView).getId());
}
}
NewView.setLayoutParams(myLayoutParams);
myRelLayout.addView(NewView);
if (ViewName.length() > 0) viewList.put(ViewName, NewView);
}
It should have a layout, but it is like B4A doesn't know how to read it or something since it is from RelativeLayout. Is there a way to fix this? When running in debug it is showing the Activity Layout not available, my Relative Layout (Scrollview) has a layout, then my Imageview Layout is not available. Putting breaks in other parts of the code shows the Activity and Imageview never get a layout.
Last edited: