Android: cannot find symbol for my own imported class - android

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.

Related

unresolved reference "Settings" in Kotlin

I am trying to write some value in the System Settings property using putInt but getting an error. The compiler says "Unresolved Reference Settings". Please check the below code -
Settings.System.putInt(context.contentResolver, SETTINGS_1, shutterOpen)
Settings.System.putInt(context.contentResolver, SETTINGS_2, muted)
Can anyone please help? Do I have to import anything extra for using this function? I am quite new in Kotlin and having really a hard time fixing it due to resource constraints.
You have to import android.provider.Settings;
Tips: In Android Studio, wait for auto-complete to appear then press tab or enter. The required package will be imported automatically.

Android Studio - Auto Import won't work even after 'fixing' the problem

Straight forward -> The Auto import function won't work on my Android Studio.
Example: I declare a variable 'Button btn' and I get no option to auto import (ALT+Enter) the Button library.
I have tried by going to Settings->General->Auto Import and changed the settings to this:
Screen shot
It still ain't working. So I tried to Invalidate caches/restart, still not working.
I have been searching for help all day, without really finding any helpful solution.
Change the value of the option Insert imports on paste to Ask instead of All. It should normally ask you to import new librairies that you need to have.

R.layout.activity_find_contact cannot be resolved or is not a field

I am brand new to android development so please bear with me. I have encountered a problem when I create a new activity. In the newly created activity there is the auto-generated overridden method 'onCreate':
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_find_contact);
// Show the Up button in the action bar.
setupActionBar();
}
On the line setContentView(R.layout.activity_find_contact);, I get the error: activity_find_contact cannot be resolved or is not a field.
I have looked up other questions on this topic. Some say to just restart eclipse - this didn't work. Others said to try cleaning the project - this didn't work either. The most promising answer said to delete the line:
import android.R;
I tried this, and of course then R gets the error: R cannot be resolved to a variable. So I followed the advice to import your.application.package.R; - which in my context translates to import com.example.databasetest.R;. However this just brings up the error the import com.example.databasetest.R; cannot be resolved to a type.
So now I'm stumped and back to square one. Any ideas?
R files are automatically generated.. so you don't need to import it or do anything. The error is because there is something wrong in your xml file or files.Got through your xml files and see if you can find any errors.
These errors might even be typos.So make sure all of it is correct and cleaning and running the project again should get your code working
Do not use the following import
import android.R;
This errors comes because when we create new app we delete hello world textview but that is referenced in strings.xml in res > values > strings
go to that and remove hello world , clean project and errors should be gone ...

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...:)

Content won't resolve

I'm working through a book samples programs and i get the same problem whether I create and type the code or whether i download the code already typed, so i'm thinking it's a setup problem.
I get this error in each each class:
setContentView(R.layout.menu) where the "R" is underlined in red and the code won't compile. If i add import android.r like "QuickFix" suggests, the red line goes away from the "R", but then the red line appears under "menu" (in this example). The same behavior occurs in each of the 5 classes that make up the project.
I do have matching layouts for "menu" etc. And (to the best of my knowledge) I registered them as Application Nodes in the manifest file.
It's driving me nuts. Thanks for any suggestions.
You are not supposed to import android.R as it won't resolve your resources. Just remove that import and try to compile again.
If you are working off a tutorial then also check to have the same resources as in the tutorial and also if you decide to name thing different then keep that in mind an reference them by your names.
The R class is generated by Android and contains IDs for all resources in your res folder. Go to your AndroidManifest and locate the package= attribute on manifest. R is in this namespace. So if the namespace is com.yourpackage.blah, you'll want to import com.yourpackage.blah.R;
The problem was that for some reason Eclipse was not autogenerating the gen/R.java file. I don't know why. One time it did generate the file, and a after Project..Clean and Build All everything resolved. Thanks for the input.
Also make sure your file names under res, eg drawables, are OK. I had a file name with capital letter and that prevented the creation of R with the same reference errors that you got. I did not check the error messages and it took me a good 10-20 mns to find this out.
Sometimes this happens to me.
It usually happens that I have been working with some xml element, and before clicking to a java document to hit "run" i just hit "run" while on the xml. I don't really know what happens when you "run" an xml, but it makes this horible file called some_xml_name.out.xml.
DELETE THIS FILE!
This file is the reason why you get so many R related errors, since the Resources library is never really created, or something like that.
That is my advice, without actually seeing the error you're getting in the console.

Categories

Resources