2013-04-11 65 views
0

我已經通過了很多例子,但仍找不到解決方案。即時通訊新的Android開發,所以即時通訊在線基本教程。 每次在AVD上啓動應用程序時,都會顯示「不幸的應用程序已停止」。不幸的應用程序名稱已停止

AndroidManifest.xml中

<?xml version="1.0" encoding="utf-8"?> 
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" 
     package="com.example.androidbmi" 
     android:versionCode="1" 
     android:versionName="1.0" > 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
     <uses-sdk 
      android:minSdkVersion="9" 
      android:targetSdkVersion="17" /> 

     <application 
      android:allowBackup="true" 
      android:icon="@drawable/ic_launcher" 
      android:label="@string/app_name" 
      android:theme="@style/AppTheme" > 
      <activity 
       android:name="com.example.androidbmi.BMICalculator" 
       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> 
    <supports-screens android:anyDensity="true" 
      android:largeScreens="true" 
      android:smallScreens="true" /> 
    </manifest> 

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:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/weightLabel" 
     android:textAppearance="?android:attr/textAppearanceMedium" /> 

    <EditText 
     android:id="@+id/weightText" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:ems="10" 
     android:inputType="numberDecimal" > 

     <requestFocus /> 
    </EditText> 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/heightLabel" 
     android:textAppearance="?android:attr/textAppearanceMedium" /> 

    <EditText 
     android:id="@+id/heightText" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:ems="10" 
     android:inputType="numberDecimal" /> 

    <Button 
     android:id="@+id/calculateButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:onClick="calculateClickHandler" 
     android:text="@string/calculateButton" /> 

    <TextView 
     android:id="@+id/resultLabel" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/emptyString" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 
</LinearLayout> 

BMICalculatorActivity.xml

package com.example.androidbmi; 

import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 

import android.widget.EditText; 
import android.widget.TextView; 

public class BMICalculatorActivity extends Activity { 
    /** Called when the activity is first created. */ 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
    } 


    public void calculateClickHandler(View view) { 
    // make sure we handle the click of the calculator button 

    if (view.getId() == R.id.calculateButton) { 

     // get the references to the widgets 
     EditText weightText = (EditText)findViewById(R.id.weightText); 
     EditText heightText = (EditText)findViewById(R.id.heightText); 
     TextView resultText = (TextView)findViewById(R.id.resultLabel); 

     // get the users values from the widget references 

     float weight = Float.parseFloat(weightText.getText().toString()); 
     float height = Float.parseFloat(heightText.getText().toString()); 

     // calculate the bmi value 

     float bmiValue = calculateBMI(weight, height); 

     // interpret the meaning of the bmi value 
     String bmiInterpretation = interpretBMI(bmiValue); 

     // now set the value in the result text 

     resultText.setText(bmiValue + "-" + bmiInterpretation); 
    } 
    } 

    // the formula to calculate the BMI index 

    // check for http://en.wikipedia.org/wiki/Body_mass_index 
    private float calculateBMI (float weight, float height) { 

    return (float) (weight * 4.88/(height * height)); 
    } 


    // interpret what BMI means 
    private String interpretBMI(float bmiValue) { 

    if (bmiValue < 16) { 
     return "Severely underweight"; 
    } else if (bmiValue < 18.5) { 

     return "Underweight"; 
    } else if (bmiValue < 25) { 

     return "Normal"; 
    } else if (bmiValue < 30) { 

     return "Overweight"; 
    } else { 
     return "Obese"; 
    } 

    } 
} 

我的AVD是一個歌Nexus S採用Android 4.2.2 請幫傢伙,這讓我發瘋了

+5

您在Eclipse中轉到Windows的>顯示視圖> logcat中錯過了重要的一部分。它崩潰日誌 – Krishnabhadra 2013-04-11 11:48:45

+1

。它會顯示你的應用程序錯誤。 – Akhil 2013-04-11 11:50:23

+2

' Selvin 2013-04-11 11:50:58

回答

0

該活動被錯誤地命名。

<?xml version="1.0" encoding="utf-8"?> 
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" 
     package="com.example.androidbmi" 
     android:versionCode="1" 
     android:versionName="1.0" > 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
     <uses-sdk 
      android:minSdkVersion="9" 
      android:targetSdkVersion="17" /> 

     <application 
      android:allowBackup="true" 
      android:icon="@drawable/ic_launcher" 
      android:label="@string/app_name" 
      android:theme="@style/AppTheme" > 
      <activity 
       android:name="com.example.androidbmi.BMICalculatorActivity" 
       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> 
    <supports-screens android:anyDensity="true" 
      android:largeScreens="true" 
      android:smallScreens="true" /> 
    </manifest> 
0

在您的活動清單文件中定義正確的名稱。

 <activity 
      android:name="com.example.androidbmi.BMICalculatorActivity" 
      android:label="@string/app_name" > 
相關問題