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
Related
How remove unnecessary import from package eclipse for android.
When i add some method after removing it the import statements not getting remove.
Is there a way to remove from entire application...
Instead of removing one by one.
You can use ctr + shift + o for removing unnecessary import of your class.
It is not just for removing but also used for importing the class that is not yet imported to your class.
The only way by which you import all defined packages that means
CTRL+SHIFT+O
Okay, this is driving me absolutely nuts. Relevant info:
I'm using Android Studio
I'm trying to set up a gaussian blur from here: https://stackoverflow.com/a/14556162/2170400
In my src/com/myprojectname folder I have, among others, the following files: AndroidImage.java, IAndroidFilter.java, ConvolutionMatrix.java and GaussianBlur.java. In IAndroidFilter.java I need to
import com.myprojectname.AndroidImage;
However I get a message saying "Cannot resolve symbol 'AndroidImage'". In the auto-complete menu that pops up while I'm typing the import statement I can see EVERY SINGLE CLASS in my src/com/myprojectname folder EXCEPT AndroidImage, which I can clearly see in the explorer.
I've quit and re-opened Android Studio several times, I've re-synced everything, I've deleted then re-created the AndroidImage class, I've tried to import AndroidImage in other classes with the same failed result as in the IAndroidFilter class...
Why is it that I can't import this class? Seriously, why? I'm at a total loss for further fixes to try.
Check to make sure your AndroidImage.java file has this at the top:
package com.myprojectname.AndroidImageProject;
Or whatever the package is.
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.
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.
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...:)