这个程序我在华为mate8里面点击按钮会出现闪退,求助,多谢
package com.example.administrator.practice_clock;import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private Button btGetMoney;
private Button pic;
private Button btnLoseMoney;
private TextView tvGetMoney;
private EditText etGoalMoney;
private ImageView p;
private int[] images = {
R.drawable.a,
R.drawable.b,
R.drawable.c,
R.drawable.e,
R.drawable.f
};
private int imageIndex = 0;
private int money = 10;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btGetMoney = (Button) findViewById(R.id.btnGetMoney);
tvGetMoney = (TextView) findViewById(R.id.tvGetMoney);
btnLoseMoney = (Button) findViewById(R.id.btnLoseMoney);
pic = (Button) findViewById(R.id.pic);
etGoalMoney = (EditText)findViewById(R.id.etGoalMoney);
p = (ImageView)findViewById(R.id.p);
btGetMoney.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View arg0)
{
String s = etGoalMoney.getText().toString().trim();
int iMoney = Integer.parseInt(s);
if(iMoney == money)
{
Toast.makeText(MainActivity.this,"完成目标",Toast.LENGTH_SHORT).show();
}
else
{
money++;
tvGetMoney.setText("哈哈,我通过点击轻易赚了"+money+"元");
}
}
});
btnLoseMoney.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
if(money == 0)
{
Toast.makeText(MainActivity.this,"我现在是穷光蛋了",Toast.LENGTH_SHORT).show();
}
else
{
money--;
tvGetMoney.setText("哈哈,我通过点击轻易赚了"+money+"元");
}
}
});
pic.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View arg0)
{
imageIndex++;
if(imageIndex>4)
{
imageIndex = 0;
}
p.setImageResource(images[imageIndex]);
}
});
}
}