I'm recently been trying to get R.JAVA to generate with no avail. I've tried the following
1. Adding spaces to the manifest file
2. Project--> Clean
So my last guess is that there is some error in my xml files that I/eclipse haven't been able to see. So I was hoping to have a second pair of eyes that might be able to check my xml files for review. There's only three and they should be pretty basic(I'm following a intro to android book).
Manifest File
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.activites"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Activity2"
android:label="Activity 2" >
<intent-filter>
<action android:name="com.example.ACTIVITY2" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/hello_world"
tools:context=".MainActivity" />
</RelativeLayout>
Activity2.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is Activity 2!" />
</RelativeLayout>
Again thanks to all of you that have taken time out of your busy day/night to help out a beginner like myself. Also if there's any suggestion other than errors in the xml feel free to bring them up.
As requested here are the problems appear in windows-> show view -> problems
R cannot be resolved to a variable
R cannot be resolved to a variable
R cannot be resolved to a variable
Tag is not that obvious it is used to show debug information in catlog with the following lines of code.
public class MainActivity extends Activity {
String tag = "Events";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
Log.d(tag, "In the onCreate() event");
}
In eclipse you can check the Problems view(windows-->show view-->Problems) or/and the Console view to help locate errors in Xml efficiently. If you remain need help you may want to post these errors to us
I get following error when I compile your code:
res\layout\Activity2.xml: Invalid file name: must contain only
[a-z0-9_.]
So remove capital A and rename "Activity2.xml" to "activity2.xml"
Also, if this doesn't help, try this:-
Rename your package name to some other. Clean. Restart Eclipse. Rename package back to the previous one. Again clean. Restart Eclipse.
check your imports. is import android.R anywhere there? if so, remove it. if you're indeed following some android tutorial in a book and it instructed you to organize or manage imports with Ctrl+shift+O or otherwise, that will cause that to pop up.
tag should be a String variable. What is it defined as? You should probably hard-code it there, unless you are using it as a global variable for your application.
http://developer.android.com/reference/android/util/Log.html#d%28java.lang.String,%20java.lang.String%29
EDIT: R cannot be resolved - Android error has a lot of different answers, try reading through those. If the first one doesn't solve your problem, another one might.
Related
Initially my Android project had only one activity named MainActivity. Then, I added a new activity named ChildActivity into my project. I'm trying to launch my new activity as startup activity when app gets launched. I changed AndroidManifest.xml file to achieve it. I moved the entire intent-filter tag from MainActivity to ChildActivity as shown below:
<activity android:name=".MainActivity">
</activity>
<activity android:name=".ChildActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Layout file of ChildActivity looks like this. I'm trying to show a TextView on the new activity I've just added:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ChildActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv_display"
android:text="Hello this is Rasik!"/>
</android.support.constraint.FrameLayout>
ChildActivity.java file:
package com.example.android.explicitintent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class ChildActivity extends AppCompatActivity {
private TextView mDisplayText;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_child);
}
}
Whenever I try to debug my app in Android AVD, nothing happens. It seems my app is crashing at start up. Can anyone help me in diagnosing the root cause?
The class android.support.constraint.FrameLayout not exists. Try LinearLayout, FrameLayout, android.support.constraint.ConstraintLayour or others
please try this !
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv_display"
android:text="Hello this is Rasik!"/>
</FrameLayout>
i think there is issue with root framelayout
You used wrong layout.
Just convert android.support.constraint.FrameLayout to FrameLayout.
Or convert to default android.support.constraint.ConstraintLayout
<FrameLayout
...>
<TextView
...
/>
</FrameLayout>
The Root layout android.support.constraint.FrameLayout you are using does not exist. Check out this link Android Developer guide.
Your Root layout can be:
FrameLayout
LinearLayout
RelativeLayout
ConstraintLayout
There are many layouts available which you can use based on your need.
I had seen a similar issue in another post. Just off the bat, it seems like your child activity is not within the enclosing terms of the ".MainActivity."
Put the child activity into the brackets of the ".MainActivity", in between the
<activity android:name=".MainActivity"> </actvitiy>. Hopefully that makes it run better. If that doesn't work, start the child activity during the onCreate() method of the MainActivity.
I have this error "Didn't find class "com.example.hello.hello" on path".
hello/AndroidManifest.xml is
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hello"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="hello"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
link is picture, show the code and error window
I think the problem is
android:name="hello"
How do I fix it?
You should put the full package name to your activity there. Example:
android:name="com.example.hello.MainActivity"
EDIT
Now that we know you have an empty src folder, you need to add a package that matches your Android package name in your manifest. Right click on your src folder and New -> Package. Name it "com.example.hello". Then right click on this new package and choose New -> Class.
Name this MainActivity.
You will probably want to read some tutorials on what you need to do to create the code for an activity.
Check the name of your activity class, it's probably Hello (Uppercase) or MainActivity (if you followed the wizard template), and as dcharms pointed out prepend the package name to it, "com.example.hello.Hello" or "com.example.hello.MainActivity"
there is a problem in your activity name in manifest and the class you crated.
your activity should be defined
android:name="com.example.hello.hello"
this way where hello is the activity you created in your hello package.
Go through your naming conventions once again and also try to post the whole stack-trace
According to your screenshots, your src folder is empty, which means you are minimum missing your "hello" activity.
Please implement if first, or read this. You could choose Blank Activity when creating android project with eclipse to have it generated.
When you specify the name of activity, mind the preceding dot :
<activity
android:name=".MyFirstActivity"
otherwise, you would need full class name, such as "com.example.hello.MyFirstActivity"
I've read up on forum posts about similar errors, but nothing I read works. It looks like my formatting is fine, but I keep getting the indicated error. I've tried refreshing the project and cleaning the project as well as restarting Eclipse entirely.
<manifest
... >
<application
... >
<activity
android:name="com.myNamespace.myPackage.MainActivity"
android:label="#string/app_name">
</activity>
</application>
</manifest>
In your manifest you must have forget to close one of the attribute. Check out your manifest file closely and make sure you have closed all the tags.
I also faced the same isssue but I found that it was coming because of copying and pasting the code in xml file.
Please try to type the code manually and see. Hope the error will not come.
try like this
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myNamespace.myPackage"
android:versionCode="12" android:versionName="2.2.0">
<uses-sdk android:minSdkVersion="3" />
<application android:icon="#drawable/icon" android:label="#string/app_name" android:debuggable="false">
<activity android:name="com.myNamespace.myPackage.MainActivity"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:label="#string/app_name"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I had the same error until I figured out that the activity tag needs to open and close on the same line. It's not a written syntax but my error was gone when I wrote the whole tag in one line instead of on separate lines. You should try it like this:
<application>
<activity android:name=".MainActivity" android:label="#string/app_name"> </activity>
</application>
</manifest>
I develop in Eclipse on a Mac. When I copy items (both from within Code and/or from a webpage (like Stackoverflow or so) I often get this error. I believe that the copy/paste mechanism is not functioning completely well.
What I do to solve this error, is just typing the complete line (no copy/paste!), all over again.
When I have copied a block I see that the error moves to the next line, which you have to retype also.
Very time consuming and frustrating, but this really works!
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How can I get device ID for Admob
My activity has a ListView and I've put an ad at the bottom. When I run the app on the emulator, I see the test ad. When I run on my phone, I get an actual ad. I want to test on my phone and not get real ads.
I followed the instructions on the AdMob site about looking in logcat for a message stating how to manually add the device ID to the AdRequest. The problem is this message would never appear in logcat. This is a RAZR running 4.1. In an SO post, answered by Aracem, I read that the encoded string is available in the Developer Options preference panel, and I found it. When I read the guide for this command, the format of the device ID was alphanumeric (e.g. "E83D20734F72FB3108F104ABC0FFC738"), but the value in my phone contains letters, numbers, and dashes (e.g. "MQKF-RB61-BBKS-E").
I've added the encoded device ID into the XML googleads:testDevices and I've also manually added an AdRequest into my onCreate and use addTestDevice with this string. Neither work.
One thing that I've noticed is the namespace that works is googleads, not ads as shown in the examples. When I use ads, I get prefix errors in the XML. I'm guessing with the switch from 4.x to 6.1, the namespace changed.
I can make this happen with the minimal project where onCreate does nothing more than call super and setContentView.
Layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/list"
android:layout_above="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<com.google.ads.AdView
xmlns:googleads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="#id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
googleads:adSize="BANNER"
googleads:adUnitId="#string/admob_id"
googleads:loadAdOnCreate="true"
googleads:testDevices="TEST_EMULATOR, MQKF-RB61-BBKS-E" />
Manifest
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="16" />
<application android:label="#string/app_name" >
<activity
android:name="mainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.google.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
</application>
In the Logcat, you will find the device ID. You will see something like
To get test ads on this device, call adRequest.addTestDevice("**")
I just got AVD up and running, and I got a "HelloWorld" to work.
Now I figure the next logical step would be to get a bit more familar with I/O, so, I want to create and input box and have a button (or some sort of trigger) to hit when the person finishes input, and then to read it in, and output responses based on the input.
I've tried to use the Android Developers Resources, and it said that to create and input method, I needed to edit the AndroidManifest.xml and to add the service into it. So, my xml now looks like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hunter.nance.escapetheroom"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".AndroidEscapeTheRoomActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="FastInputIME"
android:label="#string/fast_input_label"
android:permission="android.permission.BIND_INPUT_METHOD">
<intent-filter>
<action android:name="android.view.InputMethod" />
</intent-filter>
<meta-data android:name="android.view.im" android:resource="#xml/method" />
</service>
</application>
However, my Eclipse file says error:
[2012-02-27 11:44:41 - com.android.ide.eclipse.adt.internal.project.AndroidManifestHelper] Unable to read C:\Documents and Settings\java\workspace\AndroidEscapeTheRoom\AndroidManifest.xml: org.eclipse.core.internal.resources.ResourceException: Resource is out of sync with the file system: '/AndroidEscapeTheRoom/AndroidManifest.xml'.
[2012-02-27 11:44:41 - AndroidEscapeTheRoom] AndroidManifest.xml does not declare a Java package: Build aborted.
Not to mention, even after getting the XML to work, I'm not sure how to utilize it in my actual Java code. Are there any good tutorials for this or any suggestions?
Thanks a lot!
You don't need any permissions to put a textInput and manipulate it's data. Open your layouts folder, then your Main xml file and go to design view. You can then drag and drop a text input. About the Java code, you go to your src folder, then in your package you'll find one java file. To get a reference to your text input you'll need something like this.
EditText et = (EditText) findViewById(R.id.mytextinput); //considering your input id is mytextinput.
then you can get and set it's text by using two methods:
String myText = et.getText().toString();
et.setText("my new text for input box");
try watching this: http://www.youtube.com/watch?v=0sS-ylTxi40
UPDATE:
TextView tv = (TextView) findViewById(R.id.textView1);
Button b = (Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0)
{
tv.setText(et.getText().toString());
}
});
This code will do exactly what you want. Just don't forget to put the controls with same id-s in xml :)