Android 我能';在我的LogCat文件中找不到错误
我的程序崩溃了,我真的不知道。我有logcat错误,但在那里找不到。如蒙协助,将不胜感激。我收到一个空指针异常,但我不知道它会发生在哪里Android 我能';在我的LogCat文件中找不到错误,android,crash,android-logcat,Android,Crash,Android Logcat,我的程序崩溃了,我真的不知道。我有logcat错误,但在那里找不到。如蒙协助,将不胜感激。我收到一个空指针异常,但我不知道它会发生在哪里 package com.example.puremmacompetitionjiujitsuscorer; //~--- non-JDK imports -------------------------------------------------------- import android.app.Activity; import android.
package com.example.puremmacompetitionjiujitsuscorer;
//~--- non-JDK imports --------------------------------------------------------
import android.app.Activity;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity { // Starts the main activity
private int blueScore = 0;
private int redScore = 0;
String flag = "";
Button start = (Button) findViewById(R.id.play);
Button stop = (Button) findViewById(R.id.stop);
final ImageButton reset = (ImageButton) findViewById(R.id.resetButton1);
final ImageButton blue = (ImageButton) findViewById(R.id.imageButton9);
final ImageButton red = (ImageButton) findViewById(R.id.imageButton10);
final ImageButton sweep = (ImageButton) findViewById(R.id.imageButton5);
final ImageButton pass = (ImageButton) findViewById(R.id.imageButton8);
final ImageButton mount = (ImageButton) findViewById(R.id.imageButton4);
final ImageButton backMount = (ImageButton) findViewById(R.id.imageButton3);
final ImageButton kneeOnBelly = (ImageButton) findViewById(R.id.imageButton7);
final ImageButton takeDown = (ImageButton) findViewById(R.id.imageButton6);
final TextView blueScoreCount = (TextView) findViewById(R.id.blueScore1);
final TextView redScoreCount = (TextView) findViewById(R.id.redScore1);
TextView timerOnScreen = (TextView) findViewById(R.id.timer);
EditText editTimerOnScreen = (EditText) findViewById(R.id.editTimer);
private CountDownTimer countDownTimer;
private long totalTimeCountInMilliseconds;
private long timeBlinkInMilliseconds;
private boolean blink;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
start = (Button) findViewById(R.id.play);
stop = (Button) findViewById(R.id.stop);
timerOnScreen = (TextView) findViewById(R.id.timer);
editTimerOnScreen = (EditText) findViewById(R.id.editTimer);
stop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (v.getId() == R.id.stop) {
timerOnScreen.setTextAppearance(getApplicationContext(), R.style.normalText);
setTimer();
stop.setVisibility(View.VISIBLE);
start.setVisibility(View.GONE);
editTimerOnScreen.setVisibility(View.GONE);
editTimerOnScreen.setText("");
startTimer();
} else if (v.getId() == R.id.play) {
countDownTimer.cancel();
start.setVisibility(View.VISIBLE);
stop.setVisibility(View.GONE);
editTimerOnScreen.setVisibility(View.VISIBLE);
}
}
private void setTimer() {
int time = 0;
if (!editTimerOnScreen.getText().toString().equals("")) {
time = Integer.parseInt(editTimerOnScreen.getText().toString());
} else {
Toast.makeText(MainActivity.this, "Please Enter Minutes...", Toast.LENGTH_LONG).show();
}
totalTimeCountInMilliseconds = 60 * time * 1000;
timeBlinkInMilliseconds = 30 * 1000;
}
private void startTimer() {
countDownTimer = new CountDownTimer(totalTimeCountInMilliseconds, 500) {
// 500 means, onTick function will be called at every 500
// milliseconds
@Override
public void onTick(long leftTimeInMilliseconds) {
int seconds = (int) (leftTimeInMilliseconds / 1000);
if (leftTimeInMilliseconds < timeBlinkInMilliseconds) {
timerOnScreen.setTextAppearance(getApplicationContext(), R.style.blinkText);
// change the style of the textview .. giving a red
// alert style
if (blink) {
timerOnScreen.setVisibility(View.VISIBLE);
// if blink is true, textview will be visible
} else {
timerOnScreen.setVisibility(View.INVISIBLE);
}
blink = !blink; // toggle the value of blink
}
timerOnScreen.setText(String.format("%02d:%02d:%02d", seconds / 3600,
(seconds % 3600) / 60, (seconds % 60)));
// format the textview to show the easily readable format
}
@Override
public void onFinish() {
// this function will be called when the timecount is finished
timerOnScreen.setText("Time up!");
timerOnScreen.setVisibility(View.VISIBLE);
start.setVisibility(View.VISIBLE);
stop.setVisibility(View.GONE);
editTimerOnScreen.setVisibility(View.VISIBLE);
}
}.start();
}
});
reset.setOnClickListener(new View.OnClickListener() { // resets the score values in the top corners back to 0
public void onClick(View u) {
redScore = 0;
redScoreCount.setText("" + redScore);
blueScore = 0;
blueScoreCount.setText("" + blueScore);
}
});
blue.setOnClickListener(new View.OnClickListener() { // assigns the value of flag to the blueScore when the blue button is clicked
public void onClick(View g) {
flag = "blue";
}
});
red.setOnClickListener(new View.OnClickListener() { // assigns the value of flag to the redScore when the red button is clicked
public void onClick(View m) {
flag = "red";
}
});
takeDown.setOnClickListener(new View.OnClickListener() { // adds 2 points to either the blue or red score depending on which flag was hit last
public void onClick(View v) {
if (!flag.equals("")) {
;
}
{
if ("red".equals(flag)) {
redScore += 2;
redScoreCount.setText("" + redScore);
} else {
blueScore += 2;
blueScoreCount.setText("" + blueScore);
}
}
}
});
sweep.setOnClickListener(new View.OnClickListener() { // adds 2 points to either the blue or red score depending on which flag was hit last
public void onClick(View w) {
if (!flag.equals("")) {
;
}
{
if ("red".equals(flag)) {
redScore += 2;
redScoreCount.setText("" + redScore);
} else {
blueScore += 2;
}
blueScoreCount.setText("" + blueScore);
}
}
});
pass.setOnClickListener(new View.OnClickListener() { // adds 3 points to either the blue or red score depending on which flag was hit last
public void onClick(View q) {
if (!flag.equals("")) {
;
}
{
if ("red".equals(flag)) {
redScore += 3;
redScoreCount.setText("" + redScore);
} else {
blueScore += 3;
}
blueScoreCount.setText("" + blueScore);
}
}
});
mount.setOnClickListener(new View.OnClickListener() { // adds 4 points to either the blue or red score depending on which flag was hit last
public void onClick(View t) {
if (!flag.equals("")) {
;
}
{
if ("red".equals(flag)) {
redScore += 4;
redScoreCount.setText("" + redScore);
} else {
blueScore += 4;
}
blueScoreCount.setText("" + blueScore);
}
}
});
backMount.setOnClickListener(new View.OnClickListener() { // adds 4 points to either the blue or red score depending on which flag was hit last
public void onClick(View s) {
if (!flag.equals("")) {
;
}
{
if ("red".equals(flag)) {
redScore += 4;
redScoreCount.setText("" + redScore);
} else {
blueScore += 4;
}
blueScoreCount.setText("" + blueScore);
}
}
});
kneeOnBelly.setOnClickListener(new View.OnClickListener() { // adds 2 points to either the blue or red score depending on which flag was hit last
public void onClick(View g) {
if (!flag.equals("")) {
;
}
{
if ("red".equals(flag)) {
redScore += 2;
redScoreCount.setText("" + redScore);
} else {
blueScore += 2;
}
blueScoreCount.setText("" + blueScore);
}
}
});
}
public boolean onCreateOptionsMenu(Menu menu) { // I have no idea what this does. It's just automatically generated
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
package com.example.puremcompetitionjiujitsuscorer;
//~---非JDK导入--------------------------------------------------------
导入android.app.Activity;
导入android.os.Bundle;
导入android.os.CountDownTimer;
导入android.view.Menu;
导入android.view.view;
导入android.widget.Button;
导入android.widget.EditText;
导入android.widget.ImageButton;
导入android.widget.TextView;
导入android.widget.Toast;
公共类MainActivity扩展活动{//启动主活动
私有整数蓝核=0;
私有整数redScore=0;
字符串标志=”;
按钮开始=(按钮)findViewById(R.id.play);
按钮停止=(按钮)findViewById(R.id.stop);
最终ImageButton reset=(ImageButton)findViewById(R.id.resetButton1);
最终ImageButton蓝色=(ImageButton)findViewById(R.id.imageButton9);
最终ImageButton红色=(ImageButton)findViewById(R.id.imageButton10);
最终ImageButton扫描=(ImageButton)findViewById(R.id.imageButton5);
最终ImageButton过程=(ImageButton)findViewById(R.id.imageButton8);
最终ImageButton安装=(ImageButton)findViewById(R.id.imageButton4);
最终ImageButton背面安装=(ImageButton)findViewById(R.id.imageButton3);
最终ImageButton KneeonBell=(ImageButton)findViewById(R.id.imageButton7);
最终ImageButton取下=(ImageButton)findViewById(R.id.imageButton6);
最终TextView BlueCoreCount=(TextView)findViewById(R.id.BlueCore1);
最终TextView redScoreCount=(TextView)findViewById(R.id.redScore1);
TextView timerOnScreen=(TextView)findViewById(R.id.timer);
EditText editTimerOnScreen=(EditText)findViewById(R.id.editTimer);
私人倒计时;
私有长TotalTimeCountin毫秒;
私有长时间闪烁(毫秒);
私有布尔闪烁;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
开始=(按钮)findViewById(R.id.play);
停止=(按钮)findViewById(R.id.stop);
timerOnScreen=(TextView)findViewById(R.id.timer);
editTimerOnScreen=(EditText)findViewById(R.id.editTimer);
stop.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
if(v.getId()==R.id.stop){
timerOnScreen.settextearance(getApplicationContext(),R.style.normalText);
setTimer();
stop.setVisibility(View.VISIBLE);
start.setVisibility(View.GONE);
editTimerOnScreen.setVisibility(View.GONE);
editTimerOnScreen.setText(“”);
startTimer();
}else if(v.getId()==R.id.play){
倒计时。取消();
start.setVisibility(View.VISIBLE);
stop.setVisibility(View.GONE);
editTimerOnScreen.setVisibility(View.VISIBLE);
}
}
私有void setTimer(){
整数时间=0;
如果(!editTimerOnScreen.getText().toString().equals(“”){
time=Integer.parseInt(editTimerOnScreen.getText().toString());
}否则{
Toast.makeText(MainActivity.this,“请输入分钟…”,Toast.LENGTH_LONG.show();
}
TotalTimeCountinMillics=60*时间*1000;
TimeBlinkin毫秒=30*1000;
}
私有void startTimer(){
countDownTimer=新的countDownTimer(TotalTimeCountin毫秒,500){
//500表示每500次调用一次onTick函数
//毫秒
@凌驾
公共void onTick(长LeftTimein毫秒){
int秒=(int)(leftTimein毫秒/1000);
if(LeftTimeinMillions