The following imports are in yellow but no error is thrown, clicking on them takes me to respective class of support-annotations jar as well:
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
Message on hover:
How can I mark code inside android.support.annotation as depricated, it is not my code.
Yellow lines for these imported class signifies annotation class , it is by default yellow in color , therefore there is nothing wrong in your coding .
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
Related
Android Studio doesn't see these annotations, now I can't make my AsyncTask works. What's wrong?
import android.annotation.MainThread;
import android.annotation.Nullable;
import android.annotation.WorkerThread;
You have to add the support-annotations dependency in your build.gradle e.g
dependencies {
compile 'com.android.support:support-annotations:24.2.0'
}
See here Improve Code Inspection with Annotations
Try to replace using of android.annotation.* by android.support.annotation.*
see https://developer.android.com/studio/write/annotations.html
The problem is because you are incorrectly using import code.
Instead of this:
import android.annotation.MainThread;
import android.annotation.Nullable;
import android.annotation.WorkerThread;
It should be:
import android.support.annotation.Nullable;
import android.support.annotation.Nullable;
import android.support.annotation.WorkerThread;
I want to use android wheel to choose from some items. I just downloaded some library code from google. I am using it in my app, but it is giving some error.
import kankan.wheel.widget.OnWheelChangedListener;
import kankan.wheel.widget.OnWheelScrollListener;
import kankan.wheel.widget.WheelView;
import kankan.wheel.widget.adapters.AbstractWheelTextAdapter;
import kankan.wheel.widget.adapters.ArrayWheelAdapter;
Giving following error:
The import kankan.wheel.widget cannot be resolved
Can anyone tell me why this error is coming.
Thanks.
I have also used that library in my code and it is working fine.
possibility of error
You can't configure lib properly
In build path add lib
Clean eclipse.
Restart eclipse
import kankan.wheel.widget.OnWheelChangedListener;
import kankan.wheel.widget.OnWheelScrollListener;
import kankan.wheel.widget.WheelView;
import kankan.wheel.widget.adapters.NumericWheelAdapter;
WheelView wheel = getWheel(id);
i added this line.but it gives error.how to import it?
import org.andengine.opengl.texture.atlas.TextureAtlas;
TextureAtlas is an abstract class, try importing
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
or
import org.andengine.opengl.texture.atlas.bitmap.BuildableBitmapTextureAtlas;
depending on which one you are using
If you using Eclipse and it is configured properly, you should be able to just delete that line and Eclipse will add the correct import statements - at least it does on my system.
Right now I am able to get access to the hidden and internal android APIs, but now I want access to things like AlarmManagerService which is in server. I used adb pull system/framework/services.jar changed services.jar to services.zip which unpacked a directory of all the server classes (including AlarmManagerService which I was looking for). My question now is how can I add those server classes to my android.jar file which I can then use in Eclipse?
I hope that makes sense the way I worded it. Let me know if there is any confusion I can clear up.
EDIT: Essentially, when all is said and done, I want to be able to do something like below without any errors:
import com.android.server.AlarmManagerService;
public class TestActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
AlarmManagerService ams = new AlarmManagerService(this.getApplicationContext());
ams.setTime(1313);
}
}
ANOTHER EDIT:
I figured this out after looking at all the source code.
Classes like AlarmManagerService just have package visibility which is why it cannot be imported. Some classes are public, but many other com.android.server classes have package constructors so they can't be instantiated.
Here are the com.android.server.* I was able to import and successfully create an object of:
import com.android.server.AttributeCache;
import com.android.server.BootReceiver;
import com.android.server.BrickReceiver;
import com.android.server.ClipboardService;
import com.android.server.ConnectivityService;
import com.android.server.DevicePolicyManagerService;
import com.android.server.DiskStatsService;
import com.android.server.DropBoxManagerService;
import com.android.server.EntropyService;
import com.android.server.InputMethodManagerService;
import com.android.server.LocationManagerService;
import com.android.server.MasterClearReceiver;
import com.android.server.NativeDaemonConnectorException;
import com.android.server.NetStatService;
import com.android.server.NotificationPlayer;
import com.android.server.ProcessMap;
import com.android.server.ProcessStats;
import com.android.server.SystemBackupAgent;
import com.android.server.SystemServer;
import com.android.server.ThrottleService;
import com.android.server.TwilightCalculator;
import com.android.server.Watchdog;
import com.android.server.connectivity.Tethering;
import com.android.server.status.AnimatedImageView;
import com.android.server.status.CloseDragHandle;
import com.android.server.status.DateView;
import com.android.server.status.ExpandedView;
import com.android.server.status.IconMerger;
import com.android.server.status.LatestItemView;
import com.android.server.status.NotificationData;
import com.android.server.status.NotificationLinearLayout;
import com.android.server.status.StatusBarService;
import com.android.server.status.StatusBarView;
import com.android.server.status.StorageNotification;
import com.android.server.status.TickerView;
import com.android.server.status.TrackingPatternView;
import com.android.server.status.TrackingView;
import com.android.server.status.UsbStorageActivity;
android.jar contains only the public API's class files and I think you made changes in 'com.android' package or its internal packages. So to reflect the changes in eclipse you have to add the path explicitly to your service.jar to your project. But remeber this will not reflected at run time, since the emulator or the device you are using have not been updated your changes. And you can't update them by simply modifying the jar file, since the device or emulator uses the image 'system.img' which internally have .dex file as library not the .jar file for internal APIs. To make changes for device/emulator you have to build the whole code and for that you can refer the http://source.android.com/source/index.html.
package com.ustr.eMIRnew;
import java.util.ArrayList;
import java.util.HashMap;
import android.R;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;
public class eMIRnew extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}`
This is my code. But it is showing the error R cannot be resolved.
I have tried many methods like clean-and-build, closed-and-open the project, changed import android.R to import your.package.name.R etc. But nothing helped. Can anybody help me, please?
You are Importing android.R package, which is default one provided by Android.
If you want to access your own Layout, assets, String. . . then
Remove the import android.R statement.
No need to import your Package.R, By default, R file is generated during built.
You are using the android R file you have to use you package R file if you want to access the main layout for you app. import you_package.R
Remove the import statement:
import android.R;
In the onCreate method where you set the content view to R.layout.main, your project should be using this file:
com.ustr.eMIRnew.R
This file is generated when you build your project. Are you using Eclipse for building? Then this should not be a problem.