2014-01-18 373 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。 –