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 :)
Related
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!
I want to change the structure of my android application to have the activites in a subfolder called activities. So, my code structure will become
com.example.myapp.activities.MainActivity
and all the activities will reside within com.example.myapp.activities
How do I achieve this ? Also, What changes will have to be made in the manifest for this to work ? How will I access other activity classes from within other activities ?
<activity
android:name=".activities.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>
EDIT : I achieved this using dragging and dropping the activities in the folders but now I am getting this error on setContentView(R.layout.main); : main cannot be resolved or is not a
field
If you organize all activities in same packages, then you have to define the activity without package declaration in Manifest file, example
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp.activities"
android:versionCode="1"
android:versionName="1.0" >
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:name=".WorldClockApplication"
<activity
android:name=".WorldClockHomeActivity"
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=".AddLocationActivity"/>
<activity android:name=".EditPreference"/>
</application>
</manifest>
Then you should call that activity inside another activity using intent. Consider I'm calling WorldClockHomeActivity from WorldClockApplication activity as follows:
Intent myIntent=new Intent(WorldClockApplication.this,WorldClockHomeActivity.class);
startActivity(myIntent);
Then do clean, refresh your project you wont get error in your project. If get error on
setContentView(R.layout.main);
that means you have problem in res/strings or res/layout or res/drawable folders not in manifest file
If you are using Eclipse create a new packet in your project and drag and drop your activities files in there. Eclipse will take care of all the necessary changes.
The changes are in your directory structure and in the manifest as you have posted in the question.
Activities can be launched (or new Intents can be sent to them) as usual through Intent(context, YourActivity.class);
I wouldn't move the activities though, rather I'd organize other Java classes in separate packages.
I'm new to Android programming and i'm doing tutorial from layouts from http://developer.android.com/resources/tutorials/views/index.html . Relative layout tutorial exactly. I did everything they say but when I try to start app in android emulator there are no buttons, textfields etc. Only name of app shows at the top. What is wrong? Is this a problem with emulator? I'm using Eclipse Version: 3.7.1.
EDIT:
package pchot.tutorial;
import android.app.Activity;
import android.os.Bundle;
public class Tutorial1Activity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pchot.tutorial"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".Tutorial1Activity"
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>
Layout is copy/paste from http://developer.android.com/resources/tutorials/views/hello-relativelayout.html
EDIT:
Ok, problem solved. I needed to delete "Hello World, Tutorial1Activity!" from string.xml file which was autocreated during creation of project in Eclipse.
Have you modified you manifest.xml file? Maybe you haven't modify it to make it aware that the launched main activity is the activity you've just created.
You didn't declare anything in your onCreate() method.
For Button declare Button btn = (Button)findViewById(R.id.btnSubmit)
Implement onClickListener if you want the button to listen to clicks.
For TextView, declare TextView tv = (TextView)findViewById(R.id.textview)
I am using Win 7.0, Eclipse and android SDK. I want to add new activity in AndroidManifest.xml Application tab as it is shown in this tutorial Android Development – Adding Screens & Button Handlers
I add an Activity name to my manifest but it does not automatically turn it into a link. e.g. I cannot click the "Name"(It is not a hyperlink as shown in the article), thus I cannot create my class.
Can You Help me? what is the problem ?
1.Go to the Androidmanifest.xml file and add the activity inside the tag
if your activity name is secondAct.
2.Create a class named secondAct.
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".Project1Activity"
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=".secondAct"></activity>
<activity android:name=".third"></activity>
</application>
3 . if you are using a button for going to next activity, use the following code in secondAct.java
Button fbtn=(Button)findViewById(R.id.sbtn);
fbtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent sec=new Intent(secondAct.this,com.asish.third.class);
startActivity(sec);
}
});
Go to the small tab underneath that says AndroidManifest.xml and shows you the XML code for it. It should look like this:
<application android:label="#string/app_name" android:icon="#drawable/icon">
<activity android:name=".ApplicationName"
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=".AnotherActivity"></activity>
</application>
Okay, click on ADD, then select the top box that says "Create a new element at the top level, in Application" and then you should get a box with linkable NAME*.
You need to create the class first, then point to that class in your manifest... just putting the class name in the manifest is not enough. It will not automatically create it for you.
Also, it is easier to create the class first because then Eclipse will autocomplete the class name/path for you.
EDIT: AH HAH! I see what link you are talking about...
Yeah, you need to actually create the class first for that to appear.