R.java is not being created? - android

I dowloaded google-play-services from sdk manager and copy pasted all the code from admob samplebut it is not working. Everything seems perfect only errors produced are R can't be resolved to a variable.
Here is a sample error
Error: No resource found that matches the given name (at 'text' with value '#string/load_interstitial').
Here is strings.xml file
<resources>
<string name="app_name">Google Ads SDK Sample</string>
<string name="ad_unit_id">INSERT_YOUR_AD_UNIT_ID_HERE</string>
<string name="load_interstitial">Load Interstitial</string>
<string name="interstitial_not_ready">Interstitial Not Ready</string>
<string name="banner_in_xml">Banner in XML</string>
<string name="banner_in_code">Banner in Code</string>
<string name="interstitial">Interstitial</string>
</resources>

Try to delete the import line import com.your.package.name.app.R, then, any resource calls such as mView= (View) mView.findViewById(R.id.resource_name); will highlight the 'R' with an error, a 'Quick fix' will prompt you to import R, and there will be at least two options:
android.R
your.package.name.R
Select the R corresponding to your package name, and you should be good to go. Hope that helps.
Or.....second region,
Each time I had a problem with R not been generated, or even disappeared, this was due to some problem in the XML layout file that prevented the application from being built.

The error in res folder cause missing of R.java filevso please check your res folder for any error.
The error may be with image too any capital letter or blank space can cause missing of R.java file.
Also check all the XML file ,error with res files only

Related

Android instrumented test - test resource not resolved

I want to have androidTest resources specific to each app flavor. I found an answer on this site that indicated you can just make a resource directory androidTestFlavorName and it will be managed like all the other resources. So I have a directory app/src/androidTestFlavorName/res/values and a file strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="test_sec_code">aStringValue</string>
</resources>
I have a test class app/src/androidTest/java/com/company/package/StartupTest.kt. In that class:
val code = context.getString(R.string.test_sec_code)
test_sec_code is red, so the IDE doesn't like it, and the compiler reports: Unresolved reference: test_sec_code
My selected build variant is flavorNameDebug. So am I setting up these resources wrong, or is my goal not possible?
Edit:
I tried putting the resource in app/src/androidTest/res/values/strings.xml and it can't be found there either. Surely there must be a way to define test resources right? Hello, is this thing on?

how to resolve Error Cannot find symbol variable youtube_url in android studio

I am Stuck in Error: Cannot find symbol variable youtube_url in android studio everything is fine but this error stopping me to build gradle please help.
Remove
activity.getString(R.string.youtube_url)
and write url of youtube video to be shown "www.youtube.com/key"
or
define a string value with name youtube_url in your strings and place url to load
Under your app folder, look for a folder called res then a folder called values then a file called Strings.xml (app/res/values/Strings.xml).
The file likely looks like this:
<resources>
<string name="app_name">My App</string>
</resources>
Inside there you need create another String!
<string name="youtube_url">Hello World</string>
You can read more here:
https://developer.android.com/guide/topics/resources/providing-resources

Compiling error with Android Phonegap app

I'm using Phonegap and Barcode Scanner plugin. I'm trying to build an test application. I'm following below tutorial.
http://www.mobiledevelopersolutions.com/home/start/twominutetutorials/tmt3
I have paste the BarcodeScanner.java to the correct path, as you see in the image.
But when compiling following error happens:
Android Packager: [phonegapbarcode] C:\Users\achintha_s\IdeaProjects\Barcode PhoneGap\AndroidManifest.xml:59: error: Error: No resource found that matches the given name (at 'label' with value '#string/share_name').
How can I solve this? I'm using IntelliJ Studio.
Check the strings.xml in values folder of res folder whether there is a string with name share_name as below:
<string name="share_name">My App Name</string>
and the strings.xml file should like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="share_name">My app Name</string>
</resources>
Make sur you've a stringname share_name in your String.xml file.
<string name="share_name">My App</string>

Android R.java Syntax error on token "int", VariableDeclaratorId expected after this token

I am getting the following constantly generating in the R.java file:
public static final class id {
public static final int =0x7f0500ae;
I have done research and it all pointing to the strings file. I have checked my strings file and there is no errors. The application is not producing errors anywhere else, its just this single line that is being generated.
Can someone please help.
I had the same issue and found it odd that my strings.xml file didn't show any errors, but was able to resolve by searching through the strings.xml file for empty string name values.
Found:
<string name="">Username</string>
Changed to:
<string name="lblUsername">Username</string>
Worked and was able to compile, hope this helps.
One or more xml files might have compilation problem. Can you check?
If you are using eclipse, sometimes the xml file or folder wont show it has error (red * icon in the file or folder.
If this is not the case then delete the R.java file and rebuild the project.
or
Clean your project and rebuild it again.

Android tutorial error: R cannot be resolved to a variable

http://developer.android.com/training/basics/firstapp/building-ui.html
I have been following this tutorial, but I have two errors, both "R cannot be resolved to a variable". I have made android apps (easy ones) in the past, and I remember this problem being fixed by checking whether or not I have an import R statement (which I don't) and whether or not the project has been cleaned before being built again (I cleaned it and I still get the error). I am at a loss as to what to do. Thanks!
*I also want to mention I did see the thread of the same title with 170 hits, and the solution of "delete the import R statement" does not apply to my problem (I don't think)
Thanks again
All code is straight from the link above, but here it is for convenience
activity_my_first.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<EditText android:id="#+id/edit_message"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="#string/edit_message" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_send" />
</LinearLayout>
MyFirstActivity.java
package com.example.myfirstapp;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;
public class MyFirstActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_first);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_my_first, menu);
return true;
}
}
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">My First App</string>
<string name="edit_message">Enter a message</string>
<string name="button_send">Send</string>
<string name="menu_settings">Menu Settings</string>
</resources>
edit: When I clean the project, I get this message in the Console:
[2012-06-29 11:12:38 - MyFirstApp] W/ResourceType( 6140): Bad XML
block: header size 91 or total size 0 is larger than data size 0
[2012-06-29 11:12:38 - MyFirstApp]
C:\Users\zhong\workspace\eclipse\MyFirstApp\res\menu\activity_my_first.xml:2:
error: Error: No resource found that matches the given name (at
'title' with value '#string/menu_settings').
edit: added a line to layout xml file <string name="menu_settings">Menu Settings</string>
Fixed cleaning project errors, but I still can't run the project from the two R errors.
I'm working my way through the same example, and had the same (or very similar) problem.
Finally I noticed that there was a tiny little red x on the manifest.xml.
Sure enough, it was complaining about this:
android:label="#string/title_activity_hello_world" >
So I added:
<string name="title_activity_hello_world">Hello World</string>
to strings.xml and now it works.
I had the same issue while following the tutorial.
Cleaning the project or cleaning the imports did not solve the problem.
How the problem was (simply) solved : I quit Eclipse and relaunched it.
2 possible things
The package name specified in the Android Manifest isn't the same as the in the Java files.
Or, your IDE hasn't generated the R.java file in the gen/ folder. Try building again (despite the error) and it will usually clear it up.
Basically the R.java file is generated for you and in the same package so you can refer to it as simply R.
I had android:text="#string/button_send"
Which gave the error: No resource found that matches the given name (at 'text' with value '#string/button_send').
I tried to solve the error using the tuturial. But the tutorial fails to tell me to write all the lines required one by one. So I miss to write "<string name="button_send">Send</string>" in the strings.xml.
After adding the previous line the error disappear! Which I believe is something similar to the original problem in this thread.
So if I had copied the whole lines from the given tutorial it may had not happened, but by typing our-self is how I think is the best way of learning.
I found the solution:
go to your project->res->menu than open the XML file there and delete this line:
android:title="#string/menu_settings"
I deleted it and it start to work,after 3 hours of the same warning in the problem section.
It even make sense when you read it, "at title with value #string/menu_settings"
Pleas confirm there is no error in
1- Project folder
2- Problem View of eclipse
3- Console
4- error log as in image
You have to make sure to
Clean your project Project-->Clean
The /res directory doesn't contain errors (some files will show up
with a red icon on the file explorer)
Your imports doesn't contain this line import android.R;
Check that in AndroidManifest.xml, the attribute package has the
correct value. <manifestxmlns:android="http://schemas.android.com/apk/res/android"
package="your.correct.package.name"
This fixed it for me:
https://stackoverflow.com/a/3259974/1538785
Seems like eclipse likes to add an import line to java files for no reason. Go onto your java file, hit ctrl+shift+o and all the import statements will appear. Delete the line that says import andriod.R
Right click on the Project, select "Android Tools" > "Add Support Library" > "Android Support Library, revision 11" > "Install"
In my case, the problem was that I was on 64-bit Linux, and the required 32-bit libraries were not installed, meaning that the build tools could not generate R.java.
Running this command, then cleaning the project, fixed the problem:
sudo apt-get install ia32-libs
Make sure the executables (aapt etc.) in sdk/build-tools/android-xyz/* are executable if you are running the default download on your Linux box...
I had the same error trying to do the first tutorial. To get the app to run I edited MainActivity.java so it looked like this
package com.example.myfirstapp;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}

Categories

Resources