R cannot be resolved - android

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.

Related

android cannot find symbol error

Heres my code
package ${YYAndroidPackageName};
import android.util.Log;
import java.lang.String;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.content.BroadcastReceiver;
import com.yoyogames.runner.RunnerJNILib;
import ${YYAndroidPackageName}.R;
import ${YYAndroidPackageName}.RunnerActivity;
public class fglads extends BroadcastReceiver
{
public void showads ()
{
sendBroadcast(
new Intent("com.fgl.INVOKE").putExtra("command", "showAd")
);
}
}
I am getting cannot find symbol error when trying to compile my android game. I dont know much about java
Can any1 tell me whats wrong
I had the same error code, do you have any xml layout files that go with the java file? if so right click your extension in gamemaker, select open extension directory, then open your extension folder, and open the AndroidSource folder (in my case GM:S had put the xml layout files here, which is incorrect) so you need to create a folder called res inside the AndroidSource folder, open it, and create another folder called layout, then put your xml layout files in here (leave your java file in the AndroidSource folder) hope that helps

R.layout.main not recognized

I'm trying to create the simplest hello world program but as soon as I create a new project, I get the following error: "main cannot be resolved or is not a field".
package com.example.helloworld;
import android.R;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = new TextView(this);
tv.setText("Hello World!");
setContentView(tv);
}
}
I've tried adding import.android.R;, cleaning and restarting. I've also deleted import.android.R and included import.com.example.helloworld.R; (my package name). Keep getting the same error.
You've imported the Android's "R" class. You need to import your own.
Replace
import android.R;
With:
import com.example.helloworld.R;
If your R file doesn't resolve, then you have a problem in one of the files in your res folder. Check that all file names are lower case, have no illegal chars and that any XML files don't have syntax problems.
check your error logs or lint messages. I was facing this problem a couple of times.
Last time it was an improperly generated menu.xml file. Removing helped

Why android.os.IServiceManager in Android not resolving

I am coding for DialerDemo, But import android.os.IServiceManager;import android.os.ServiceManagerNative; import android.telephony.IPhone; are not resolving
CODE:
package com.umesh.umeshfilereadwritedemo1;
import android.app.Activity;
import android.os.Bundle;
import android.os.DeadObjectException;
import android.os.IServiceManager;
import android.os.ServiceManagerNative;
import android.telephony.IPhone;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class DialerDemo extends Activity
{
...
...
}
These are all internal classes of the SDK, and are not available publicly.
You cannot build source.android.com applications on their own. They can only be built as part of a firmware image. Please follow the instructions to build the entire firmware. While you can use Eclipse to edit the firmware source, you will still use make to build the firmware.

How to import BitmapTextureAtlas in Andengine?

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.

Add Server classes to android.jar

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.

Categories

Resources