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

Apps Troubleshooting the stated error problem?

imso

Member
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:
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:
getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor(ContextCompat.getColor(this,R.color.action_bar))));

Someone please help! Thanks
 
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
 
Why did you change the original code? What was the problem?
 
Originally the below error occur, therefore i change to this instead
-->
Java:
getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor(ContextCompat.getColor(this,R.color.action_bar))));

Error stated: Expected resource of type string less... (Ctrl+F1)
This inspection looks at Android API calls that have been annotated with various support annotations (such as RequiresPermission or UiThread) and flags any calls that are not using the API correctly as specified by the annotations. Examples of errors flagged by this inspection:
Passing the wrong type of resource integer (such as R.string) to an API that expects a different type (such as R.dimen).
Forgetting to invoke the overridden method (via super) in methods that require it
Calling a method that requires a permission without having declared that permission in the manifest
Passing a resource color reference to a method which expects an RGB integer value.

I'm at a lost here..
 
This is actually a very odd one, and I'm not surprised you're stumped. I was too.

Try this

Code:
//noinspection ResourceType
getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor(ContextCompat.getColor(this,R.color.action_bar))));

And if that doesn't work, try this

Code:
//noinspection ResourceType
getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor(getResources().getString(R.color.action_bar))));

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
 
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?
 
Back
Top Bottom