1. Download our Official Android App: Forums for Android!

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

Discussion in 'Android Development' started by Gregary Boyles, Oct 7, 2017.

  1. Gregary Boyles

    Thread Starter
    Rank:
     #851
    Points:
    15
    Posts:
    30
    Joined:
    Oct 1, 2017

    Oct 1, 2017
    30
    0
    15
    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 (Text):
    1.  
    2. ViewGroup.MarginLayoutParams marginParams = new ViewGroup.MarginLayoutParams(m_textviewStatusCurrent.getLayoutParams());
    3. marginParams.leftMargin -= m_nOffset;
    4. m_textviewStatusCurrent.setLayoutParams(marginParams);
    5.  
    This doesn't work either.
    Code (Text):
    1.  
    2. RelativeLayout.LayoutParams layoutparams = (RelativeLayout.LayoutParams)m_textviewStatusCurrent.getLayoutParams();
    3. layoutparams.leftMargin -= m_nOffset;
    4. m_textviewStatusCurrent.setLayoutParams(layoutparams);
    5.  
     

    Advertisement

    #1 Gregary Boyles, Oct 7, 2017
    Last edited: Oct 7, 2017
  2. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #10
    Points:
    1,988
    Posts:
    8,530
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    8,530
    12,699
    1,988
    Male
    Software developer
    South West of England
    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.
     
  3. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #10
    Points:
    1,988
    Posts:
    8,530
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    8,530
    12,699
    1,988
    Male
    Software developer
    South West of England
    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.
     

Share This Page

Loading...