I am developing an Android app using Phonegap and jQueryMobile, working in Eclipse. I want the app, with the user's permission, to auto-install a launcher icon on the user's "desktop". I've found the example LauncherShortcuts.java on Android Developers, and I am almost to the point of getting it to work. That's a big achievement, since I know extremely little of Java programming.
Almost.
This is the example code online:
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/LauncherShortcuts.html
One string or thingy in the code refuses to cooperate. Line 83...
TextView intentInfo = (TextView) findViewById(R.id.txt_shortcut_intent);
...has this constant or variable in it called "R.id.txt_shortcut_intent", and Eclipse says it doesn't recognize the id part. If I follow its suggestion of adding a class 'id' in R., it tells me there is no field txt_shortcut_intent in 'R.id'. That doesn't surprise me.
I've been able to fix a few similar errors involving R.something_or_other. But not this one. My R.java only contains the classes attr,drawable,layout, and string.
What is going on here and most importantly, what should I do to get this thing up and running? The launcher icon is all that stands between here and actually launching the app (how ironic).
If you find any errors in the project. Sometimes id of R.java entries will be shifted to string folder or R.java.
For this choose
project → clean
file → close all
click on your project
See the entries in id of R.java your ids will be in this folder
An android app uses an xml to define the layout of all the elements you want to display. In this case, you're missing an element that displays text called TextView. You don't have the Textview 'txt_shortcut_intent' defined in the xml, probably.
Here's the xml you're looking for (just copy and paste it into your main.xml):
http://developer.android.com/resources/samples/ApiDemos/res/layout/launcher_shortcuts.html
The ADT Plugin in Eclipse can only rebuild the R class if there are no (Java) errors.
Therefore, fix all errors and check if your layout ressource has the correct id (txt_shortcut_intent).
It's worth a try to clean the project and restart Eclipse.
Related
I am new to programming and trying to learn android development with android studio. I updated Java and tried to update android SDK when it crashed. I finally got the Android SDK update fixed but now I have this error in an app I was working on. It's in the activity_main.xml file
The error says "cannot resolve this symbol: MainActivity.java"
Here's the line where the error shows up.
tools:context="com.example.android.justjava.MainActivity.java"
MainActivity.java is red. I feel like it's directory tree issue, but I can't tell what the program wants so I can fix it.
Remove .java at the end, and make sure that MainActivity.java exists inside the package com.example.android.justjava.
What is the purpose of writing that line?
tools:context
This attribute is typically set on the root element in a layout XML
file, and records which activity the layout is associated with (at
designtime, since obviously a layout can be used by more than one
layout). This will for example be used by the layout editor to guess a
default theme, since themes are defined in the Manifest and are
associated with activities, not layouts.
Source: http://tools.android.com/tech-docs/tools-attributes
Where is the R.java file in Android Studio? Can someone please help with this? I already tried google for the answer but can't find any solution.
Based on the new stable release of Android Studio (3.6) we have:
So, now to find your generated resource classes you need the following steps:
1) Open your project.
2) Go to your module build path.
3) Open the outputs/apk/debug/app-name-debug.apk file.
4) Choose your classes.dex file.
5) Look at the down placed area and go to your full package path.
6) You can see all bytecoded resource classes. So, scroll down to what you are looking for.
7) Expand the resource class you need to proceed (for example, let it be R.id)
8) Go to you id's.
That's it.
UPDATE:
If you would like to see actual id integer number you should follows steps below:
1) By (7) Go to the resource class you need to proceed and right click to show the context menu
2) Choose "Show Bytecode" to see the flexible dialog "DEX Byte Code for R$id", for example, for id class
3) Scroll down to the actual id to look its number
Although the current Android Gradle Plugin doesn't generate a R.java anymore you can still inspect the corresponding class file (see Sergey V.`s answer).
However, if you (like probably in most cases) just want to look up the generated IDs for your resources, there is an easier way:
In the project pane on the left hand side switch from Android to Project view using the drop-down at the top. Then navigate to app/build/intermediates/runtime_symbol_list/<insert build type here>/R.txt. This file lists all IDs generated by AGP during the build process.
I use Android Studio 3.3.2
\app\build\generated\not_namespaced_r_class_sources\debug\processDebugResources\r\android\support\constraint\R.java
As noted above, "The new Android Gradle Plugin generates the corresponding bytecode directly and does not make the intermediate R.java file".
Using the ubuntudroid solution you can find an id also this way. Find R.txt and copy absolute path. Project > app > build > intermediates > runtime_symbol_list > debug > R.txt. Then right click and select Copy Path..., 1. Absolute Path Ctrl+Shift+C.
This way you will obtain a path to R.txt, for instance, "C:\Users\user\AndroidStudioProjects\your_project\app\build\intermediates\runtime_symbol_list\debug\R.txt". Copy the path without R.txt to a text file for future references, for example, with Notepad++.
Press Ctrl+Shift+F to find in directory. Insert an id and the path.
== Old answer ==
Change a project view from Android to Project or Project Files. Find one of these two files.
Then you can revert back to Android view.
I use Android Studio 2.3.3. The R.java file is shown in the picture above.
In the left upper side, there is a select list. Select the [project] option so that you can see all the folders and files.
R.java is the generated file by ADT or Android studio. It will be located under app\build\generated\source\r directory.
./app/build/generated/source/r/debug/android/support/v7/appcompat/R.java
./app/build/generated/source/r/debug/your/packagename/name/R.java
I am using Android Studio 2.2.3 , the R.java file is shown in the picture below.
Goto in the left upper side there is a selecting list ,
select [package]
Open "App Folder"
com.example.saeedanwar.myapplication;
r
In my project in Android Studio 4.1
R.jar that you can actually unzip resides in app build folder, as follows:
jar -xf R.jar
Once the jar is unpacked you can find R.java inside of app package:
If you're using Mac or Linux, try the following command line on your terminal:
find . -name "R.*"
It will print something like:
./app/build/intermediaries/runtime_symbol_list/debug/R.txt
./app/build/intermediaries/compile_and_runtime_not_namespaced_r_class_jar/debug/R.jar
It is inside app\build\generated\source\r folder
Project/app/build/generated/source/r/debug/com.android.'projectname'/R.java
--The R.Java that contains your xml layouts and views id's in Android Studio 3.5.3 -- Project/app/build/generated/not_namespaced_r_class_sources/debug/r/com/"your package"/R.java
This answer will be in a constant state of flux until Android standardize a method of matching their annoying decimal/hexadecimal id references to a tangible resource such as my_layout.xml.
For Android Studio Dolphin | 2021.3.1 Patch 1 have a look at this file:
/project/package/build/intermediates/stable_resource_ids_file/debug/stableIds.txt
It is produced by RUN (not just BUILD). Sample:
layout/mtrl_picker_header_fullscreen = 0x7f0d00de
string/cancel = 0x7f1101f0
style/ThemeOverlay.MaterialComponents.MaterialCalendar = 0x7f1202f3
id/gpxBtn = 0x7f0a0346
I've got a problem with Eclipse. I use the ADT to develop Android apps directly in Eclipse. But right after creating a new project, I got an error in my "MainActivity.java"-file.
I googled and everywhere its said that I have to import an ".R" class from my project folder, which didnt work for me. I also completetely redownloaded Eclipse+ADT in one package this morning.
The line which gives the error is the following:
setContentView(R.layout.main);
Without the "import com.example.myapp.R" statement I've got the same error. Cleaning and rebuilding also didnt have any effect.
Do you have any ideas?
Thanks!
Try to type R r; in your code. Hover your mouse over the 'R' and Eclipse will say "R cannot be resolved to a type". Click import R (com.example.myapp). If this doesn't work then check for the folder gen to say Generated Java Files. Also check to see if they have the classes inside.
R.layout.main refers to a layout XML file in your "res/layout" directory. This seems like the layout file you are trying to reference is named something else.
.
You just need to make sure that your referencing the correct layout in your onCreate method.
setContentView(R.layout.activity_main);
Post the main.xml. Make sure you import your application's R file and not android.R. Restart eclipse, do a clean up by going to your menu Project-> Clean , refresh and tell us if it is fixed.
When in the middle of developing a small app, I noticed that Eclipse searches in some other R.java instead of the R.java file in my project.
Ex : I created a TextView (android:id="#+id/title").When I tried to access it through my class (by using findViewById(R.id.title)), it showed some other R.java class which contained some id's I've never even used and doesn't contain the "title" id I gave my TextView. When I checked my R.java class, it's absolutely fine (there's the "title" id in it). And when I gave findViewById(my.package.R.id.title) instead of findViewById(R.id.title), it works fine.
Anybody know why?
PS : I tried cleaning the project and restarting Eclipse. Didn't work.
I have been having a lot of trouble because of an apparent bug in the latest java release, that has stopped me and many other people it seems, from referencing images. For example, the following code will not compile, even though this is the code given by many sites:
ImageView imageView = (ImageView) findViewById(R.id.myimageview);
imageView.setImageResource(R.drawable.myimage);
(or to a similar effect)
What I'm looking for is an alternate way to access an image from the file system, without using said "R.drawable.*".
2 possibilities:
Clean your project (Project>Clean). This will probably also fix your R.java file.
Check your imports! Possible that you've imported the R class. Had lots of trouble with that too.
If you're really looking for an alternative, look at Assets.
EDIT
If the above doesn't fix it, check your res folder (incl subfolders) for suspicious files, and delete them. like for example files that won't open, have no extension, or have errors in them.
Is that the error that you're getting when you compile the code that you've posted? I've never seen this error before. I would suggest doing a Project --> Clean and if that doesn't work delete the R file in the gen folder and then rebuild.
seen the same problem,make sure you have not imported the .R package,if so remove it from th list of imports,delete the R.java class ,clean then rebulid the project.