• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Call to setLayoutParams(...) crashes my app - why?

The call to setLayoutParams(...) is causing my app to crash.
If I comment out the line of code in bold then my app run as normal.
What am I doing wrong?
Code:
ViewGroup.MarginLayoutParams marginParams = new ViewGroup.MarginLayoutParams(m_textviewStatusCurrent.getLayoutParams());
marginParams.leftMargin -= m_nOffset;
m_textviewStatusCurrent.setLayoutParams(marginParams);

This doesn't work either.
Code:
RelativeLayout.LayoutParams layoutparams = (RelativeLayout.LayoutParams)m_textviewStatusCurrent.getLayoutParams();
layoutparams.leftMargin -= m_nOffset;
m_textviewStatusCurrent.setLayoutParams(layoutparams);
 
Last edited:
In order for someone to help with this you need to show the stack trace from the Logcat output.
And you need to show a bit more code than the above.
Plus there's no code line shown in bold.
 
The call to setLayoutParams(...) is causing my app to crash.
If I comment out the line of code in bold then my app run as normal.
What am I doing wrong?
Code:
ViewGroup.MarginLayoutParams marginParams = new ViewGroup.MarginLayoutParams(m_textviewStatusCurrent.getLayoutParams());
marginParams.leftMargin -= m_nOffset;
m_textviewStatusCurrent.setLayoutParams(marginParams);

This doesn't work either.
Code:
RelativeLayout.LayoutParams layoutparams = (RelativeLayout.LayoutParams)m_textviewStatusCurrent.getLayoutParams();
layoutparams.leftMargin -= m_nOffset;
m_textviewStatusCurrent.setLayoutParams(layoutparams);

To establish why your app crashed, we need to know what exception it generated. This will be shown in the stack trace, displayed in the Logcat view.
 
Back
Top Bottom