I know many people have had this problem and I have searched Google/Stack Overflow, but I somehow still can’t figure out what I’m doing wrong.
package HelloWorld;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloWorldActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// TextView tv = new TextView(this);
// String hello = "Hello World!";
// tv.setText(hello);
// setContentView(tv);
}
}
I tried searching for unnecessary import android.R; statements, as well as building/cleaning/refreshing/etc, but I just can’t seem to figure it out. Maybe it’s a problem with the way I’ve installed my SDKs? I don’t think there is, but I’m very new to this so it’s likely I made a blunder somewhere.
Also, I am getting this error:
[2011-12-13 18:18:46 - com.android.ide.eclipse.adt.internal.project.AndroidManifestHelper] Parser exception for C:\Users\MYNAME\Android Development\Hello World\Hello World\AndroidManifest.xml: The processing instruction target matching "[xX][mM][lL]" is not allowed.
Can anyone help me? Thanks!
EDIT: My XML file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="HelloWorld Mylove"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".HelloWorldActivity"
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>
See this line in your manifest (at the opening of the
<manifest />tag)That’s not a valid package name and has to change. Usually a package name consists out of lowercase words, seperated by dots, e.g.:
See Naming a Package. Change this to a valid name.
Since this is overall a bit of work, because you have to change it in various places¹ (and sometimes failed for me for some reason), I’d recommend just creating a new project via the new android project wizard in eclipse. This will ask you for a package name in step 4. Make sure to follow the naming conventions mentioned above. You should end up with pretty much the same code. Alternatively you can try to right-click on your project in the project explorer and select
Android Tools -> Rename Application Package.¹ The manifest itself, the folders where your *.java files are stored, the
packagestatement within the source files