I am working on an Android application that will be using images and so I am working being able to grab an image and display it. Though when I put in setContentView(R.layout.main); It tells me that main does not exist but offer to put into the layout file or R.java. When trying to place it into the file and save the R.java files tells me it reverted it right back to the original purpose, why is that?
From your comments you said you have activity_main.xml and not main.xml
So change to
setContentView(R.layout.activity_main);
ALso if you have imported R.java remove the same. Make sure there are no errors in your resource files. Clean and build.
If you have a imageview in activity_main.xml with id gimg1 then
ImageView iv = (ImageView) findViewById(R.id.gimg1);
and import
import android.widget.ImageView;
Its the same to initialize if you have others view's in your xml
R.java file is generated automatically, you can't edit it. In your case tyr to clean your project via Project->Clean
Related
I have encountered the following issue in Android Studio: when I select the "..." to specify the source drawable file for an ImageView, in the Project tab I don't see the project drawables, even if they do appear into the drawable folder on the left pane, but instead a long list of (I guess) system drawables (whose name is starting with "abc_") and no trace of the custom files I have successfully pasted into the project drawable folders.
If I try to write manually a reference to the correct resource in XML (android:src="#drawable/main_title"), I get the following error popup:
Rendering Problems Couldn't resolve resource #drawable/main_title. Failed to convert #drawable/main_title into a drawable.
Does anybody have any idea of what's happened? Thank you in advance.
You're trying to put in android:src a string, not a Drawable. If you want to apply drawable to your ImageView src you should use somthing like this:
android:src="#drawable/your_image_drawable"
I just found my own mistake: I pasted the drawable files inside the drawable folder, while they must reside inside the res folder. Now it works.
Thanks for your replies.
There are similar questions, but none address my specific issue.
I'm rather new to Android development and Eclipse but was able to follow the tutorials A OK.
In fact, I'm able to edit activity_main.xml from a tutorial, but now, in a test project I'm working on, I can't edit my new activity_main.xml (again, different project, same filename).
I created the file by right-clicking on the layout folder then selecting NEW > OTHER > Android XML Layout File. I was able to copy some of the other file so that my file now looks essentially like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
</LinearLayout>
When I type, the cursor moves around (looping through the text) but no characters appear on the screen. Again, in the other XML file I can edit with no problem.
I'm hoping that this is just some newbie problem.
I have had similar problems, though not this exact problem. Sometimes simply restarting Eclipse, or whatever editor you use, can help. Occasionally, Eclipse will not detect changes in your xml so you need to clean and rebuild the project. You can do this by
Winodow --> Project --> Clean...
and choose your project
I know there was an issue that I had which was similar with the editor jumping/replacing lines and such which I believe was fixed in a newer version of Eclipse. If I can find a source later I will edit
Clear all of text in layout activity_main.xml (in code view)
Drag and drop new LinearLayout in layout (in graphical view)
Go to Project -> Clean
i downloaded zxing library and installed it on my device. now i tried to make a simple app the extends zxing library. in this simple app I created a new layout for it and when i tried to setmycontentview to be this layout, eclipse highlits it with red and when i move the mouse pointer on the highlighted layout, eclipse suggests the following:
1-create the field "activity_firstactivity" in type layout
OR
2-create constant "activity_firstactivity" in type layout
now, my question is:why eclipse can not reach my xml file for this layout, i created the layout inside the layout folder but eclipse can't recognise it.
UPDATE:
even when i press ctrl+space the layout name is not listed
Java Code:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_firstactivity);
probably Eclipse is trying to find the layout in the android package. Try to access your layout through the full name of your package:
your.package.name.R.layout.activity_firstactivity
I have an imageView in my main.xml file, that isn't setup with a source initially. I want to be able to dynamically change the image resource within the code. so lets so i have my imageView setup like this:
<ImageView
android:id="#+id/countryImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/CountryImageContent"/>
So i try to access within my code like this:
ImageView img = (ImageView) findViewById(R.id.countryImage);
The problem is here. Eclipse is giving me an error saying that "countryImage cannot be resolved or is not a field". A quick peek into my R.java file is showing me that the imageView isn't actually in there. Why is this happening? Thanks.
look into your drawable and layout if there is any error
if not try cleaning your project
Go to Project > clean > select your project
if not then look into your imports for
your.packagename.R remove it
Project -> Clean.
That is the only solution to this.
Also make sure that among your import statements, you do not have this : import android.R
Check this link for a detailed procedure.
Note : I am assuming that there are no errors in your layout and drawable files, as errors in them may also lead to this problem.
make sure all resource files have only lowercase letters , numbers and the underscore character ("_") .
only if there are no errors in creating the R file (in the "gen" folder) , you can use the id of it.
I think it is the problem to giving the name of #string
Please Remove all UpperCase Character from #string/CountryImageContent and replace it with small character.
R.java file doesn't support any Uppercase character. It gives the same error when you declare the file name of any resources Like :- Image, XML, #string, etc...
Just rename CountryImageContent with country_image_content. it will work perfect.
Another option to try in this case is: File --> Invalidate Caches / Restart...
Quick question, when I try to assign a variable to the id of a flipperview in an xml file, I get an issue that doesn't allow me to find the id of the flipper.
mFlipper = (ViewFlipper) findViewById(R.id.your_flipper); contains an error that the id of the flipper view is not there.
The flipper view won't take the id assigned in the xml file and place it in the R.java class for some reason.
Any ideas why or is the id of a flipper not supposed to be accessible in the class?
Either your layout XML file does not have the ViewFlipper under that ID, or you need to clean your project. To do the latter, use ant clean from the command line or Project > Clean from the Eclipse main menu.