Reputation: 41
I'm trying to do the first app tutorial. After editing the 2 xml files, activity_main and strings, the instructions say, "In Eclipse, click Run from the toolbar."
First off, it showed me some problems. With the EditText set to android:layout_weight="1"
, it doesn't like the android:layout_height
set to wrap_content
and shows me on the Problems tab. The problem goes away if I set layout_height to 0dp like the width.
Second, now that it shows me nothing in the problems list, hitting run doesn't do anything, either on the windows computer or on my android device connected via usb and set up according to the previous instructions.
I found another thread with similar question. They suggested he look at his AndroidManifest.xml and MainActivity.java. Mine seem to contain what they suggested needed to be there. Oh! I see my avid is open, but it doesn't seem to say anything.
activity_main.xml
<LinearLayout 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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<EditText android:id = "@+id/edit_message"
android:layout_weight="1"
android:layout_width = "0dp"
android:layout_height = "0dp"
android:hint="@string/edit_message"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text = "@string/button_send"/>
</LinearLayout>
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">My First App</string>
<string name="action_settings">Settings</string>
<string name="edit_message">Edit your message, silly.</string>
<string name="button_send">Send</string>
<string name="title_activity_man">MainActivity</string>
</resources>
Upvotes: 3
Views: 4837
Reputation: 1328
Create an AVD for using emulator or make sure your phone is detected by eclipse. Also go to Run Configurations,create a new configuration for Android Application and select your Android project.
Upvotes: 1
Reputation: 450
Boy its not a problem. You just have to select your application and run it as an android app. Moreover, check in AVD manager that either you have your virtual machine up and running. If not then start it first. Assuming that you have already created your AVD. Now goto the main activity and hit the run button and yupiee. =P
Upvotes: 0
Reputation: 624
The Run button in Eclipse doesn't function when you're on an XML file. Open up one of the .java files, then hit Run - it should compile and run the app.
Upvotes: 8
Reputation: 171
I'm going to assume you're using Eclipse. Did you actually start your virtual device? When I created my first project, I created the virtual device but forgot to actually click start. Nothing happened when I clicked run.
Try right clicking on your project and going to Run As -> Android App.
Upvotes: 0
Reputation: 51581
Not able to reproduce this error:
First off, it showed me some problems. With the EditText set to android:layout_weight="1", it doesn't like the android:layout_height set to "wrap_content" and shows me on the Problems tab.
Even if your app runs, it will only show the button on the right side of the display. The EditText
will not be visible. This is because you are setting the EditText's
height to 0dp
.
Since you are setting the layout_weight
attribute of the EditText
to 1
, and the LinearLayout's
orientation is horizontal
(by default), you only need to set the width of EditText
to 0dp
. This will make the EditText
take as much width as it can with the rest taken by the button, whose width is set to wrap_content.
This should help you understand the options you have while working with LinearLayouts
: LinearLayout.LayoutParams.
Upvotes: 0