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

Apps Troubleshooting the stated error problem?

Discussion in 'Android Development' started by imso, Aug 11, 2016.

  1. imso

    imso Member
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    56
    Joined:
    Mar 8, 2011

    Mar 8, 2011
    56
    0
    15
    Sorry rather a newbie learning android studio where I downloaded a project http://www.androidhive.info/2014/12...mera-image-video-to-server-with-progress-bar/ to get my hands dirty with coding a camera app to upload to a server. Can anybody get it to work after downloading it? Because somehow I couldn't get it to work after I tried compiling it, with a error for this statement in the MainActivity.java file.

    Code (Text):
    1. getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor(getResources().getString(R.color.action_bar))));
    I've tried changing the code statement to this but still not working -->
    Code (Text):
    1. getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor(ContextCompat.getColor(this,R.color.action_bar))));
    2.  
    Someone please help! Thanks
     

    Advertisement

  2. LV426

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

    Oct 16, 2015
    7,275
    10,375
    1,988
    Male
    Software developer
    South West of England
    What's the error message?
     
  3. imso

    imso Member
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    56
    Joined:
    Mar 8, 2011

    Mar 8, 2011
    56
    0
    15
    It give an Error(47, 94) error: cannot find symbol method getColor(MainActivity,int);

    How do I solve this, could you have it work after downloading it from the website? Thanks
     
  4. LV426

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

    Oct 16, 2015
    7,275
    10,375
    1,988
    Male
    Software developer
    South West of England
    Why did you change the original code? What was the problem?
     
  5. imso

    imso Member
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    56
    Joined:
    Mar 8, 2011

    Mar 8, 2011
    56
    0
    15
    Originally the below error occur, therefore i change to this instead
    -->
    Code (Java):
    1. getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor(ContextCompat.getColor(this,R.color.action_bar))));
    2.  
    I'm at a lost here..
     
  6. LV426

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

    Oct 16, 2015
    7,275
    10,375
    1,988
    Male
    Software developer
    South West of England
    This is actually a very odd one, and I'm not surprised you're stumped. I was too.

    Try this

    Code (Text):
    1.  
    2. //noinspection ResourceType
    3. getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor(ContextCompat.getColor(this,R.color.action_bar))));
    4.  
    And if that doesn't work, try this

    Code (Text):
    1.  
    2. //noinspection ResourceType
    3. getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor(getResources().getString(R.color.action_bar))));
    4.  
    I had to do some digging about, but thanks to StackOverflow question below. The accepted answer doesn't work, but the question comments reveal that adding the commented line above the statement makes it work.
    Bizarre, and looks like a bit of a hacky workaround to me. But whatever gets it working I guess..

    http://stackoverflow.com/questions/5026995/android-get-color-as-string-value
     
  7. imso

    imso Member
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    56
    Joined:
    Mar 8, 2011

    Mar 8, 2011
    56
    0
    15
    Sorry for the late reply tried your suggestions it worked but more problem seems to surface perhaps the source code is depreciated, thus i tired out another alternative with more updated tutorial in the link here but I also encounter errors for the camera and gallery image selection. You mind helping?
     

Share This Page

Loading...