你好,我试图运行一个Android应用程序,我从android工作室制作到我的moto g手机......但它一直在告诉,不幸的是," Expence已停止" ...它指向我的android maifest文件请帮助我
这是主要活动
package com.example.vikki.expense;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
EditText salary ;
EditText net;
EditText petrol;
EditText cw;
EditText food;
EditText expence;
Button next;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//find the value by id
salary = (EditText) findViewById(R.id.editText);
net = (EditText) findViewById(R.id.editText2);
petrol = (EditText) findViewById(R.id.editText3);
cw = (EditText) findViewById(R.id.editText4);
food = (EditText) findViewById(R.id.editText5);
next = (Button) findViewById(R.id.button);
next.setOnClickListener((View.OnClickListener) this);
}
public void onClick(View v ) {
// TODO Auto-generated method stub
float num1 = 0;
float num2 = 0;
float num3 = 0;
float num4 = 0;
float num5 = 0;
float result = 0;
// read EditText and fill variables with numbers
num1 = Float.parseFloat(salary.getText().toString());
num2 = Float.parseFloat(net.getText().toString());
num3 = Float.parseFloat(petrol.getText().toString());
num4 = Float.parseFloat(cw.getText().toString());
num5 = Float.parseFloat(food.getText().toString());
result = num1+num2+num3+num4+num5;
Intent intent = new Intent(getApplicationContext(),Activity2.class);
startActivity(intent);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
这是我的清单文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.vikki.expense"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="21"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.vikki.expense.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>
<activity
android:name="com.example.vikki.expense.Activity2"
android:label="@string/title_activity_activity2" >
</activity>
</application>
这是xml
<RelativeLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/Expense"
android:id="@+id/textView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="@+id/editText"
android:layout_below="@+id/textView"
android:layout_toEndOf="@+id/textView"
android:layout_marginTop="49dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="@+id/editText2"
android:layout_marginTop="29dp"
android:layout_below="@+id/editText"
android:layout_alignStart="@+id/editText" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="@+id/editText3"
android:layout_centerVertical="true"
android:layout_alignStart="@+id/editText2" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="@+id/editText4"
android:layout_marginTop="37dp"
android:layout_below="@+id/editText3"
android:layout_alignStart="@+id/editText3" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="@+id/editText5"
android:layout_marginTop="30dp"
android:layout_below="@+id/editText4"
android:layout_alignStart="@+id/editText4" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/ex1"
android:id="@+id/textView2"
android:layout_above="@+id/editText2"
android:layout_toStartOf="@+id/textView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/ex2"
android:id="@+id/textView3"
android:layout_alignBottom="@+id/editText2"
android:layout_alignStart="@+id/textView2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/textView4"
android:layout_alignBottom="@+id/editText3"
android:layout_alignStart="@+id/textView3"
android:text="@string/ex3" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/ex4"
android:id="@+id/textView5"
android:layout_above="@+id/editText5"
android:layout_alignStart="@+id/textView4" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/ex5"
android:id="@+id/textView6"
android:layout_alignBottom="@+id/editText5"
android:layout_alignStart="@+id/textView5" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/next"
android:id="@+id/button"
android:layout_below="@+id/textView6"
android:layout_centerHorizontal="true" />
</RelativeLayout>
答案 0 :(得分:2)
如果您使用View.OnClickListener
next.setOnClickListener(this);
答案 1 :(得分:0)
我觉得很有趣,在没有崩溃的情况下调试这个问题...
我认为问题在于布局。
在您的布局中使用 editText2 ,您正在使用 TextView -s并将它们转换为代码中的 EditText 。恕我直言,它不会工作。 在代码中使用TextView或在需要时将TextView更改为布局文件中的EditText