I have copied and pasted the code from the Form stuff example on this website. I am getting an error when i try and run the project, the project has a little red square with a white cross on it but when drilling down into the elements of the project (using eclipse) there is element with an error. In the problems tab of eclipse I have the following text
Description Resource Path Location Type Unparsed aapt error(s)! Check the console for output. HelloFormStuff2 Unknown Android Packaging Problem
But there is nothing in the console!! Here is the code and elements that I am using...
HelloFormStuff2.java
package com.android.HelloLinearLayouts;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class HelloFormStuff2 extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button butto开发者_JAVA技巧n = (Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Perform action on clicks
Toast.makeText(HelloFormStuff2.this,
"Beep Bop",
Toast.LENGTH_SHORT).show();
}
});
}
}
**res/drawable-hdpi/android-button.xml**
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/android_pressed"
android:state_pressed="true"/>
<item android:drawable="@drawable/android_focused"
android:state_focused="true"/>
<item android:drawable="@drawable/android_normal"/>
</selector>
**res/layout/main.xml**
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:background="@drawable/android_button" />
</LinearLayout>
Not sure what happened to your code in the question, but check under res/layout/ and make sure there's not a main-out.xml. If there is, delete it, do Project > Clean, and then run the application by right-clicking the project and selecting Run As > Android Application.
Coming from Visual Studio, I kept trying to just do a "run as" from anywhere, which doesn't work in Eclipse (unless I'm doing something else wrong); instead, it tries to run the xml file, which gave me that error all the time.
If I'm completely off-base, just try Project > Clean..., then Project > Build All (if it's not set to automatic).
In eclipse just go to Project>>Clean then select the project you want and hit clean... just like magic it works.
This happened to me after I imported an image that didn't really have a proper extension... weird.
精彩评论