2010-02-02 43 views
6

Tôi đang tạo ứng dụng Android đầu tiên của mình nhưng ứng dụng không bắt đầu.Dự án thử nghiệm Android đầu tiên không bắt đầu

Trong src của tôi> android.SampleApp Tôi tạo ra một file java tên Main.java với:

public class Main extends Activity { 

// Will be connected with the buttons via XML 
public void myClickHandler(View view) { 
    switch (view.getId()) { 
    case R.id.btn1: 
     ((EditText) findViewById(R.id.txtContent)).setText("Button 1 Clicked"); 
     break; 
    case R.id.btn2: 
     ((EditText) findViewById(R.id.txtContent)).setText("Button 2 Clicked"); 
     break; 

    } 
} 
} 

Trong res của tôi> bố trí> 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" android:id="@+id/txtContent"/> 
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button One" android:id="@+id/btn1"></Button> 
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button Two" android:id="@+id/btn2"></Button> 

Nội dung AndroidManifest.xml của tôi:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="android.SampleApp" 
    android:versionCode="1" 
    android:versionName="1.0"> 
<application android:icon="@drawable/icon" android:label="@string/app_name"> 


</application> 
<uses-sdk android:minSdkVersion="7" /> 

tôi nhận được lỗi này:

  1. [2010/02/02 01:46:26 - SampleApp] Android Launch!
  2. [2010-02-02 01:46:26 - SampleApp] adb đang chạy bình thường.
  3. [2010-02-02 01:46:26 - SampleApp] Không tìm thấy hoạt động Launcher nào!
  4. [2010-02-02 01:46:26 - SampleApp] Việc khởi chạy sẽ chỉ đồng bộ hóa gói ứng dụng trên thiết bị!
  5. [2010/02/02 01:46:26 - SampleApp] Thực hiện đồng bộ

dòng 3 và 4 được đánh dấu màu đỏ.

Ai đó có thể dẫn tôi đi đúng hướng để chỉ hiển thị ứng dụng trên trình giả lập không?

Android 2.1 SDK với Eclipse

Trả lời

11

Bạn đang thiếu những điều sau trong thẻ <activity> của bạn trong file manifest của bạn:

 <intent-filter . . . > 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 

Để biết thêm thông thấy here

+0

bạn có thể chỉnh sửa của tôi ở trên và cung cấp cho các hoàn thành ting bởi vì tôi không biết nơi để đặt mã đó. –

+2

Nó nằm giữa '' và '', chính nó nằm trong thẻ '' của bạn. –

+0

Nếu bạn tìm kiếm "android.intent.action.MAIN" bên trong trang mà tôi đã liên kết, bạn sẽ thấy một ví dụ điển hình. –

Các vấn đề liên quan