error android SDK in class R - android

I update my SDK, and now it is giving error in my whole project. Says that there is a class named R, which is where the layout call.
this with error in the line
import br.com.projeto_tcc.R;

R is the automatically generated with references to all your resources. It is used very frequently in android, so when it 'disappears', it seems to cause an error throughout the whole project.
As has been mentioned in comments above, a rebuild will sometimes solve the issue. However, if the issue is still persisting and the compiler is still unable to find the class 'R', then you need to start looking at your xml files (layouts, menus, etc).
When there is a syntax error in an android XML file, the error notification is not displayed as prominently as it is for errors in Java files (if you are using Eclipse with ADT plugin, as most android devs do). As such, it is pretty easy to miss a typo or other syntax error in one of these files unless you go through and look in each individual one (or check the errors tab in the window at the bottom of your screen if using eclipse/adt).
Syntax errors in these XML files prevent the generation of the R class; therefore, when the java compiler is looking at the references you make to the R class (for example, R.layout.foo or R.id.bar), it cannot find the class, and highlights those lines of code as errors.
So, make sure that your XML files are all well-formed, because this is a fairly common issue, especially if you are just learning your way around adt.

Related

Unable to see all the classes in an android application using AndBug tool

I tried to see the list of classes inside a package in an android application using AndBug command 'classes com.package.name.example'.
The output shows only one class file.
But when I decompile the apk using dex2jar and view the classes inside the package com.package.name.example using JD-GUI, I can see two class files.
The class file that I want to trace is not being shown in AndBug, while it is shown in JD-GUI.
What could be the possible issue?
It's very likely a bug with AndBug. You should at least submit an issue to the project page along with a dex file, if possible, so that they can reproduce the issue: https://github.com/swdunlop/AndBug/issues
For bonus points, debug the issue yourself and submit a pull request. :D
There are always bugs with disassemblers and decompilers. Some people intentionally find and exploit them to prevent others from reversing their applications.

Using R resources from an android jar file

This has been talked about a few times, with varying states of success but most of the answers I can find are several years in the past.
Essentially, I have an application which has moved to a point where isn't being shared with customers. Customers want to extend the application but we don't want them to have access to the original code -- protecting IP on all that.
The layouts, images, etc... well, we don't care about those as much, only the java code. I could easily compile the java code into a jar and distribute it, but that's only half the answer. The java code still references a whole pile of internal resources.
The scenario I'm working with is jar file contains the following:
In Jar file
- MyActivity extends Activity
- onCreate() within MyActivity sets the contentView to an R-referenced layout from within the jar file.
In client application
- MyClientActivity extends MyActivity
When this is run, I get a ClassNotFoundException on MyClientActivity.
Things I've noticed:
- If I attach the jar code as a library, instead of a jar file, it works.
- If I remove the R reference within onCreate() in MyActivity and remake my jar file, it works.
So, obviously, as pointed earlier, the R references are dead/not accessible. The thing is, this apparently can work, no? If you create an Android application and look at the auto-included APIs, the android.jar file has an R file, with internal layouts/strings/etc... which are being references from within its code.
As others have said before, this seems like a very basic and obvious usage pattern. The fact that it seemingly doesn't work is mind boggling enough to lead one to believe that it does in fact work, it's just not done in an obvious way.
Has anyone ever actually gotten it to work?
Thanks a lot,
-Cord Awtry

R cannot be resolved for inflating raw queries

I know this is a pretty common question and I looked around the web and this forum for an answer but none of them seem to be working for me. I did the typical stuff like deleted my R.java and cleaned my project, made sure my class did not have a import for the R.java class. I tried rebuilding my project etc.
So here is what I have going on. I am trying to inflate a database from some raw SQL statements. I am using the book The Busy Coders Guide to Advanced Android Development book as a guide to do this.
it gives the following line of code:
InputStream stream=ctxt.getResources().openRawResource(R.raw.packaged_db);
and says the file is located within the res/raw directory like so "res/raw/packaged_db.txt"
I have placed my sql dump file: res/raw/raw_game_data.sql
and here is my line of code that is throwing the error:
InputStream inputStream = context.getResources().openRawResource(R.raw.raw_game_data);
any ideas or suggestions on what I am missing?
Thanks,
Generally, only one R.java is built for your entire project, and it is built in only one place, with one package - the package of your app, declared in your manifest. If that package is com.example.trek, and you refer to R in a class in com.example.trek.tribbles - or any other package - you will need to explicitly import com.example.trek.R
You list off some corrective measures without indicating that you understood the actual problem they were intended to correct, or if you had that problem. I'm not unsympathetic to this attitude in the context of Eclipse, but you can waste a lot of time this way. If you understand Java, then you only need to learn aapt to be able to drop down to the command line and attempt the process yourself.
That said, developers.android.com seem to have removed the documentation for aapt. ...well, don't worry, I'm sure you'll never have problems with Eclipse!

What does this Eclipse error mean about my Android app?

I am using Eclipse to write my Android app and I keep getting this error when running it. I have no idea what the error means or how to go about debugging.
I should add that this all started when I wrote a method to parse an XML file. Before I wrote that, the app worked fine. I tried adding some try/catch block that contain "log.e" statements, but I don't see anything strange in the log.
Does anyone have any idea?
The error message is in the screen shot below:
It means you don't have the source files of the Android code in you eclipse workspace. check
Android source
By default you only have the compiled class files in you android.jar. if you want to see the source(*.java files) you need to add them yourself. So, you have no source files at all by default
I have had this error come up before for a lot of reasons. Almost always it is because I tried to refer to a resource that either is not there, or is incorrectly formatted. Seeing as how this started when you worked with one of your XML files I would check there for incorrect formatting.
Although this error is referring to the fact that you do not have the full android source code, having it will not fix the error, it will only allow you to see where the source code is failing either to find or open your XML file.

Why are my resources suddenly unresolved in my Android project?

Eclipse is complaining about my Android project saying all my references to resources are unresolved, even though R.java does exist. For example:
signin_btn=(Button)findViewById(R.id.signin_btn); signin_btn.setOnClickListener(this);
I definately have signin_btn defined in my resources. Dont know why Eclipse is not seeing my R class anymore. How to fix?
The thing that happens to me once in a while is that Eclipse decides to "help" me by adding the following statement to the top of the source file:
import android.R;
This means that all non-absolute references will now be matched against the Android built-in resources, instead of your own. Something like "R.id.layout" is now supposed to be in "android.R.id.layout" and not in "com.mydomain.myproject.R.id.layout". Just remove the line.
It happens to me, this is what I think happens:
Whatever process generates R.java starts at the top of your resources and works to the bottom. If it encounters an error somewhere, it just stops... leaving whatever resources haven't been added to R.java out. This is why some of them will say "unresolved", and others will be fine.
It seems that every time you save a file in your project, it regenerates R.java (maybe it's just the files in res/), so you probably fixed whatever the generator broke on, and when you saved AndroidManifest.xml, it regenerated R.java.

Categories

Resources