why I cant see my layout file in eclipse - android

I have created a class which extends ArrayAdapter class. But while doint
View v = inflater.inflate(R.layout.xxxx,..) I cannot see my layout file. I dont know what does that mean. In other activity I can see it very well using R.layout.xxx.!

There is a simple solution for this issue.
Suppose your package name is
com.xyz.package
Now If you will look at the top of your code
you would find
import android.R;
replace this with
import com.xyz.package.R;
after replacing above import if you find still error that means your layout.xml file in res directory has errors. rectify it, clean and build it in eclipse.

Related

MainActivity not reading Subfolders Android Java

I created an application that uses the Room, ViewModel approach. I created subfolders to organize my code as shown in the photo:
How do I make my Main Activity recognize the code created in the subfolders? I tried invalidate caches/restart already and tried many times to rebuild the project.
There was an issue when I created my folders. I used New->Folder->Java Folder when the right process should be New->Package
You have to write an import statement for the classes to be recognized:
import com.example.laundry.data.ViewModel.CustomerViewModel
I think there are various ways to solve this problem.
Process 1.
For your Adapter import this
import com.example.laundry.adapter.CustomerListAdapter;
For your ViewModel import this
import com.example.laundry.data.ViewModel.CustomerViewModel;
Process 2
If you write down your adapter/model class name it will show some popup. From there you can select.
just like when I tried to import InfiniteScrollAdapter I got these options
Process 3
Please check if you have already import that adapter/model class with the different package names. Just delete that line and import again with alt+ enter

android developer, get error with webView1 = (WebView) findViewById(R.id.webView1); [duplicate]

I keep getting this error. Should I just make id a field?
My code is:
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.main);
ImageView mainimage = (ImageView) findViewById(R.id.mainanim);
mainimage.setBackgroundResource(R.anim.mainanim);
mainanimation = (AnimationDrawable) mainimage.getBackground();
}
How exactly do you fix this?
Look at your import statements at the top. If you are saying import android.R, then there that is a problem. It might not be the only one as these 'R' errors can be tricky, but it would definitely definitely at least part of the problem.
If that doesn't fix it, make sure your eclipse plugin(ADT) and your android SDK are fully up to date, remove the project from the emulator/phone by manually deleting it from the OS, and clean the project (Launch Eclipse->Project->Clean...). Sounds silly to make sure your stuff is fully up to date, but the earlier versions of the ADT and SDK has a lot of annoying bugs related to the R files that have since been cleared up.
Just FYI, the stuff that shows up in the R class is generated from the stuff in your project res (aka resources) folder. The R class allows you to reference a resource (such as an image or a string) without having to do file operations all over the place. It does other stuff too, but that's for another answer. Android OS uses a similar scheme - it has a resources folder and the class android.R is the way to access stuff in the android resources folder. The problem arises when in a single class you are using both your own resources, and standard android resources. Normally you can say import at the top, and then reference a class just using the last bit of the name (for example, import java.util.List allows you to just write List in your class and the compiler knows you mean java.util.List). When you need to use two classes that are named the same thing, as is the case with the auto-generated R class, then you can import one of them and you have to fully qualify the other one whenever you want to mean it. Typically I import the R file for my project, and then just say android.R.whatever when I want an android resource.
Also, to reiterate Andy, don't modify the R file automatically. That's not how it's meant to be used.
Do not modify the R class. The error means there's something syntactically wrong with your XML layouts and R cannot be auto-generated. Try looking there and post the xml code you're not sure about, if any.
Edit : also: remove "import android.R" from imports at top of file (if there)
One possible solution:-
Summary: make sure you are using import com.yourpkgdomainname.yourpkgappname.R instead of import android.R
Details: The problem occured when I changed ID of a label which was being referred in other places in the layout XML file. Due to this error, the R file stopped generating at first. Eclipse is bad in handling errors with the layout files.
When I corrected the ID reference (with project clean few times and Eclipse restarts, I noticed that my import packages now has:
import android.R
Changing it to following fixed the error:
import com.example.app.R
I just fixed my problem right-clicking in the layout folder and clicking in the option Validate. Some windows will appear, you just clik OK and ist fine.
May be you created a new xml file in Layout Directory that file name containing a Capital Letter which is not allowed in xml file under Layout Directory.
Hope this help.
Just throwing this out there, but try retyping things manually. There's a chance that your quotation marks are the "wrong" ones as there's a similar unicode character which looks similar but is NOT a quotation mark.
If you copy/pasted the code snippits off a website, that might be your problem.
As Jake has mentioned, the problem might be because of copy/paste code.
Check the main.xml under res/layout. If there is no id field in that then you have a problem.
A typical example would be as below
<com.androidplot.xy.XYPlot
android:id="#+id/mySimpleXYPlot"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10px"
android:layout_marginLeft="20px"
android:layout_marginRight="20px"
title="A Simple Example"
/>
Some times eclipse may confuse with other projects in the same directory.
Just change package name (don't forget to change in Android manifest file also), ensure the package name is not used already in the directory. It may work.
Just came across this myself.
Finally found my issue was with a .png file that I added that had a capital letter in it an caused exactly the same problem. Eclipse never flagged the file until I closed it and opened Eclipse back up.
What seems to be the problem, I just fixed mine in case anyone was wondering - Due to other errors i turned off build automatically, when i created a new project it said R.layout.main had an issue and needed to import R; So naturally as a novice, i did. Then i built manually and it had a problem with main. Try building your program as is, remove import R and it should be fine.
In main.xml (or wherever your item is defined) make sure that the ID for the R item is defined with #+id/... Here is an example with a button:
<Button android:text="B1" android:id="#+id/button_one"
android:layout_gravity="center_horizontal|center"
android:layout_height="fill_parent" android:layout_width="wrap_content" />
Each of these is important because:
# must precede the string
+ indicates it will create if not existing (whatever your item is)
I also had this error when I was working in a Java class once. My problem was simply that my xml file, with the references in it, was not saved. If you have both the xml file and java class open in tabs, check to make sure the xml file name in the tab doesn't have a * by it.
Hope this helps.
Just Clean your project so R will be generated automatically. This worked for me.
It gave me enough pain but I found the solution:
PROJECT ---> Clean ----> (Sele)
I had this problem but in my case it solved by restarting the eclipse.
For me the cause of the problem was that I had 2 images with the same name in my drawable-hdpi folder. Once I resolved that, then the R.java rebuilt itself and the problem was automatically solved.
select Project tab and click Build automatically so Build all option will be activated and then click on build all.and always start xml file name with lowercase.

new to android not sure what import info.androidhive.imageslider.R; means

I have been working through this tutorial and came across this code:
import info.androidhive.imageslider.R;
This is important because when i copy these files from this tutorial into a new project - it gives me an error on this line of code.
can you give me a detailed explanation on what it means?
This is the import of your resource library. Resource means where your app store its drawable, layout etc. In most cases, it is under the packages name like:
if your package name is: info.androidhive.imageslider
then, your resource package name will be info.androidhive.imageslider.R
When you open a new android project, your must notice that there is a gen folder where there is a R.java file. This import actually import that file to the class where you may use some resource.
As you copied the code from other places, I think you have changed your project package name and so for that, now the app can't match it with current package for R file. Please, check it and change it according to it.
Hope it may help you.
You got this explained in the tutorial (btw: it's good to read tutorial, not just copy files from it):
I kept my package name as info.androidhive.imageslider
You must have proper import here. If you are using Eclipse, best solution would be to press CTRL+Shift+o.

Android multiple packages in one project, what is R and how to import it?

I have a launcher for people with bad eyesight and a simple music player, this is my second APP so bear in mind I'm a complete noob in android and eclipse.
I tried to merge both my launcher and music player. I added the activity to the manifiest with a different intent, copied layouts and drawables to the launcher project and I added the player's package inside my /src folder.
Afterwards on the first lines of com.easyplayer.java I got this error:
import com.easyplayer.R; // the import com.easyplayer.R cannot be resolved
This is the only bug I'm getting so I suppose I did everything else fine. I imagine R must reference the player's layout, but I'm not sure how to fix it (cleaning/rebuilding doesn't work). What is the R class? And what can I do to fix this?
The R class you see is auto-generated by Android. It is a utility class that contains references to all the resources in your project. There is a few answers detailing its contents here.
You mentioned you performed a clean of your project, but you need to do a full build as well to regenerate this file.
edit: The import of the new code may have somehow invalidated your xml files. Check to see if there are any errors there, which could be preventing the R file from being re-created during a build.
if you have several packages like, com.example.app.package1 and com.example.app.package2, then import the R.java file like,
import com.example.app.R;
And if you already have import android.R; then please delete that and save the file and clean the project, problem will be solve...:)

How to get layout from another package in android?

I start a project MyFileChooser which contains package com.MyFileChooser.In my Project i have a layout abc.xml.I created another package com.FileChooser in the same project.In a class file inside the second package,i need to set abc.xml layout.But it is not possible to do so.Also i cannot acces the EditText inside abc.xml.
just import
import com.MyFileChooser.R;
Try to get layout by setContentView(R.layout.abc); now you can get all the tools of abc.xml by findviewbyid.
And no need to give any kind of Reference. Now just go to Project->Clean the Project before you Build.

Categories

Resources