2014-01-18 369 views
-1

我是編程新手,經過一段時間後,我終於修復了所有錯誤,但現在應用程序在啓動時崩潰!我沒有自己編寫所有這些代碼,但我編輯了它。另外,當我仍然收到錯誤的應用程序可以開始(但不明顯工作)。 清單啓動後Android應用程序崩潰

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="tk.iWeld.iweld" 
    android:versionCode="1" 
    android:versionName="1.0" > 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 

    <uses-sdk 
     android:minSdkVersion="14" 
     android:targetSdkVersion="22" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 

     <activity 
      android:name="tk.iWeld.iweld.MainActivity" 
      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> 

Activity_Main

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/RelativeLayout1" 
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/editText2" 
    android:layout_width="100dp" 
    android:layout_height="wrap_content" 
    android:layout_alignBaseline="@+id/editText2" 
    android:layout_alignBottom="@+id/editText2" 
    android:layout_alignParentRight="true" 
    android:layout_marginRight="20dp" 
    android:ems="10" 
    android:hint="Text2" 
    android:inputType="number" > 

    <requestFocus /> 
</EditText> 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBottom="@+id/editText2" 
    android:layout_centerHorizontal="true" 
    android:text="X" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:textColor="@android:color/holo_orange_dark" /> 

<TextView 
    android:id="@+id/textView2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/editText2" 
    android:layout_centerHorizontal="true" 
    android:text="_________________________" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:textColor="@android:color/holo_orange_dark" /> 

<EditText 
    android:id="@+id/Text3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/textView2" 
    android:layout_centerHorizontal="true" 
    android:ems="10" 
    android:hint="Text3" 
    android:inputType="number" /> 

<TextView 
    android:id="@+id/textView3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/textView1" 
    android:layout_below="@+id/Text3" 
    android:layout_marginTop="22dp" 
    android:text="=" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:textColor="@android:color/holo_orange_dark" 
    android:textColorHint="@android:color/holo_orange_dark" 
    android:textSize="30sp" /> 

<TextView 
    android:id="@+id/textRes" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBaseline="@+id/textView3" 
    android:layout_alignBottom="@+id/textView3" 
    android:layout_alignParentRight="true" 
    android:clickable="false" 
    android:longClickable="false" 
    android:text="Result" 
    android:textAppearance="?android:attr/textAppearanceMedium" /> 

<Button 
    android:id="@+id/resultbutton" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/textView2" 
    android:layout_alignTop="@+id/textView3" 
    android:text="Result" /> 

<EditText 
    android:id="@+id/editText1" 
    android:layout_width="89dp" 
    android:layout_height="wrap_content" 
    android:layout_alignBottom="@+id/textView1" 
    android:layout_alignLeft="@+id/textView2" 
    android:ems="10" 
    android:hint="Text1" 
    android:inputType="number" /> 

而在MainActivity

package tk.iWeld.iweld; 

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

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

public class MainActivity extends Activity { 

     /** Called when the activity is first created. */ 

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


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

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

      // get the references to the widgets 
      EditText text1Text = (EditText)findViewById(R.id.editText1); 
      EditText text2Text = (EditText)findViewById(R.id.editText2); 
      EditText text3Text = (EditText)findViewById(R.id.Text3); 
      TextView resultText = (TextView)findViewById(R.id.textRes); 

      // get the users values from the widget references 

      float text1 = Float.parseFloat(text1Text.getText().toString()); 
      float text2 = Float.parseFloat(text2Text.getText().toString()); 
      float text3 = Float.parseFloat(text3Text.getText().toString()); 

      // calculate the result value 

      float totalresult = calculateRESULT(text1, text2, text3); 


      // now set the value in the result text 

      resultText.setText("" + totalresult); 
     } 
     } 

     // the formula to calculate the result index 

     private float calculateRESULT (float text1, float text2, float text3) { 

     return (float) (text1 * text2/text3); 
     } 
    } 
+1

請張貼您的LogCat。 –

+2

你確定你的主佈局是'R.menu.main'嗎? –

回答

8

有在第二行是錯誤的的onCreate():

setContentView(R.menu.main); 

您不能設置菜單視圖。如果你想使用主佈局,使用這個:

setContentView(R.layout.main); 
+0

哦,是的,我首先鍵入佈局,但它給了我一個錯誤,我看到菜單中的主要文件,這就是爲什麼我這樣鍵入它。但是現在我意識到它不是所謂的「主」,而是activity_main。 – user3210676

+0

感謝您的幫助,但它現在可行! :D 編輯:按鈕不計算輸入,你知道最新的事情嗎? – user3210676

+0

你在哪裏調用'calculateClickHandler'? –

6

這...

android:targetSdkVersion="22" /> 

只是科學幻想!

最大API級別是當今

+2

似乎有多個問題... –

+2

正確,從我+1。 –

+3

+1。 –