unresolved reference "Settings" in Kotlin - android

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.

Related

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.

Android, Type argument listadapter

so i'm following a guide online to make a room db. In the adapter section i followed his way of doing it but when i did it, i keep having the "No Type Argument expected for Interface ListAdapter".
Error example: https://imgur.com/kPT7DkE
Here's the whole project so far on github.
https://github.com/OlivierLabelle/BudgetProject/tree/master/app/src/main/java/com/example/android/budgetproject
And the guide i was following.
https://medium.com/#trionkidnapper/recyclerview-more-animations-with-less-code-using-support-library-listadapter-62e65126acdb
So with the help of devboi, i found out i was using the wrong import.
In the top right corner on the Dev documentation it show the right import.
https://imgur.com/vGrCOVd
And here how the import on my project should look like.
import android.support.v7.recyclerview.extensions.ListAdapter
Just came across this very problem myself.
If you're using AndroidX/Jetpack/whatever the official name is I'm still new at this, Android Studio might
import android.widget.ListAdapter
automatically, but the one you want is
import androidx.recyclerview.widget.ListAdapter
From what I see in your code, you should replace ListAdapter<Transaction> with ListAdapter<Transaction, Viewholder>.
You can see an example in the docs here :(https://developer.android.com/reference/android/support/v7/recyclerview/extensions/ListAdapter.html), where ListAdapter has 2 arguments inside the diamonds: one for the list-object and the other for your custom viewholder.
Hope this helps.

Android - IContentService cannot be resolved

In my project I need to use IContentService, and I've used the right import (import android.content.IContentService) and yet android studio tells me 'Cannot resolve symbol IContentService'.
I know IContentService is an actual class, because it is used in ContentResolver.getContentService();
Anyone know how I can get this import to work?
You cannot use this class directly.
You can see in the source code (e.g. here for Marshmallow) that this class is tagged with the #hide annotation.
The class can only be used by reflection as shown here (with all it's disadvantages).
BTW: ContentResolver.getContentService() is also a hidden method (see here).

Android: cannot find symbol for my own imported class

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.

eclipse error with android: id cannot be resolved or is not a field

I just started playing around with android development, and already with just an attempt at making a button, I have encountered a problem.
The error I'm given in the following code is right on "R.id.button1".
It says id cannot be resolved or is not a field.
Do I need to manually reference every single object I make in the layout xml file? I found that this did work, but it does seem to be a bit much for every button I want to make...
package com.example.helloandroid;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
private Button button1;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button1 = (Button)findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
finish();
}
});
}
}
I've been wasting a lot of time (two weeks) because of the same problem until I discovered the problem wasn't mine but Eclipse's.
I guess there's a lot of people with the same problem.
Just try this: Save your project, close Eclipse and then open it again. So simple.
Do I need to manually reference every single object I make in the layout xml file
Yes, otherwise you won't be able to do anything with those views. It's not that bad actually. So, each time you create a view in your XML, and you want to reference it, put an ID:
<View
android:id="#+id/the_id"/>
And then, from your code you can reference it using the R class. You can type, in the example, R.id.the_id and then Ctrl+Shift+O to make Eclipse auto import the needed files.
You can speed up your productivity by using frameworks like Roboguice; I think it's for lazy people, though.
This answer is not applicable to this question (looking at code you have provided). Just adding it if someone else stumbles here and above mentioned answers do not help.
If cleaning (Project --> clean) doesn't helps or saving and restarting eclipse doesn't help either, check for the following incorrect import.
import android.R;
Which Eclipse sometimes add by mistake on auto-import (Ctrl+Shift+O).
Remove that line (import) and it's done :D
Following this EXCELLENT tutorial , I encountered the same problem. After reading Carmello's answer (Sept 17, 2011. 07:23) I simply clicked File->Save All, and voila, 'button0' was automagically defined, and even syntax highlighted.
If "R.id.button1" is not defined, then you'll get a compile error, just as you saw. If you don't define this in the layout, then it won't be defined.
You don't have to specify every object you create in the layout, but you do if you try to reference it from "R.*". You can manually create buttons and other objects that are not specified in the layout.
I ran through the same issues for time being. Plz, do not forget to define as follows:
<View
android:id="#+id/button1" />
if you are using the id in your .java class.
Button b =(Button) findViewById(R.id.button1);
Being said that, the id defined in xml file must match with the id in findViewById().
Go to the 'R.java' file under the 'gen' folder and check whether your 'button1' is present under the class 'id'.If not,then this could be the reason you got that error.When you use the statement " R.id. " make sure that the is present under the appropriate class,in this case under the 'id' class.
R.id is a generated object that assigns int numbers to resources. Try this go to your gen/mypackage/R.java and delete the file. As you can see it is re-generated. This file provides static references where as the context is more of the dynamic state of your app. If you have syntax errors that will prevent automatic re-generation of that R.java file so you will get lots or R. errors. As everyone else has said you can click save all icon or ctl+shift+s on windows. You can clean the project project/clean and that will clean up 95% of those exceptions. Yes eclipse is buggy that way but netbeans does not support android that well. this link may help
Good luck
Do these things,anyone of this will help you
Project -> Clean,
Right click -> Fix Project Properties
Restart Eclipse
make some fake modification in manifest and save
check your console for any error message
check your drawable folder, check the image names satisfy the rules

Categories

Resources