Java Android联盟应用程序不断崩溃

Java Android联盟应用程序不断崩溃,java,android,android-intent,counter,Java,Android,Android Intent,Counter,需要一点帮助,创建一个应用程序,发送十个球队名称、赢得的比赛和平局的结果,并进行计算得出总积分,然后显示它们 但单击“继续”按钮后,应用程序总是崩溃。 这是代码,有什么错误的指南吗 非常感谢 package com.example.leaguetest; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.widget.TextView; public

需要一点帮助,创建一个应用程序,发送十个球队名称、赢得的比赛和平局的结果,并进行计算得出总积分,然后显示它们 但单击“继续”按钮后,应用程序总是崩溃。 这是代码,有什么错误的指南吗 非常感谢

package com.example.leaguetest;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;


public class Display extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_display);

    //get the the BUNDLE inside the intent
    Bundle m = this.getIntent().getExtras();

    String [] TeamName = m.getStringArray("TeamName");
    String[] SWin = m.getStringArray("Win");
    String[] SDraw =  m.getStringArray("Draw");
    int [] Win = new int[10];
    int [] Draw = new int [10];


    // Convert to from string to integer Win
    Win[1] = Integer.parseInt(SWin[1]);
    Win[2] = Integer.parseInt(SWin[2]);
    Win[3] = Integer.parseInt(SWin[3]);
    Win[4] = Integer.parseInt(SWin[4]);
    Win[5] = Integer.parseInt(SWin[5]);
    Win[6] = Integer.parseInt(SWin[6]);
    Win[7] = Integer.parseInt(SWin[7]);
    Win[9] = Integer.parseInt(SWin[8]);
    Win[9] = Integer.parseInt(SWin[9]);
    Win[10] = Integer.parseInt(SWin[10]);
    // Convert to from string to integer Draw
    Draw[1] = Integer.parseInt(SDraw[1]);
    Draw[2] = Integer.parseInt(SDraw[2]);
    Draw[3] = Integer.parseInt(SDraw[3]);
    Draw[4] = Integer.parseInt(SDraw[4]);
    Draw[5] = Integer.parseInt(SDraw[5]);
    Draw[6] = Integer.parseInt(SDraw[6]);
    Draw[7] = Integer.parseInt(SDraw[7]);
    Draw[8] = Integer.parseInt(SDraw[8]);
    Draw[9] = Integer.parseInt(SDraw[9]);
    Draw[10] = Integer.parseInt(SDraw[10]);


    //Calculation

    int Result1 = (Win[1]* 3)+Draw[1];



    TextView Result1T=(TextView)findViewById(R.id.TextView1);
    Result1T.setText(TeamName[1] );         

    TextView Result2T=(TextView)findViewById(R.id.TextView2);
    Result2T.setText( Result1);










}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.display, menu);
    return true;
}




}

package com.example.leaguetest;
导入android.app.Activity;
导入android.content.Intent;
导入android.os.Bundle;
导入android.view.Menu;
导入android.view.view;
导入android.widget.EditText;
公共类MainActivity扩展了活动{
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
//为菜单充气;这会将项目添加到操作栏(如果存在)。
getMenuInflater().充气(R.menu.main,menu);
返回true;
}
//全局变量
String[]TeamName=新字符串[9];
字符串[]Win=新字符串[9];
String[]Draw=新字符串[9];
int计数器=0;
公共作废保存(视图){
EditText团队=(EditText)findViewById(R.id.editTeamName);
EditText WinG=(EditText)findViewById(R.id.editWin);
EditText DrawG=(EditText)findViewById(R.id.editDraw);
EditText LossG=(EditText)findViewById(R.id.editLoss);
//如果团队人数不超过10人,则
如果(计数器<9){
//将输入放入数组
TeamName[计数器]=Team.getText().toString();
Win[counter]=WinG.getText().toString();
Draw[counter]=DrawG.getText().toString();
计数器++;
}
//重置文本框
Team.setText(“”);
翼.长边(“”);
图纸setText(“”);
LossG.setText(“”);
}//如果结束
公共作废继续(查看){
//捆
Bundle myBundle=新Bundle();
Intent myIntent=新的Intent(这个,Display.class);
//将数组放入捆绑包中
myBundle.putStringArray(“名称”,团队名称);
myBundle.putStringArray(“Win”,Win);
putStringArray(“Draw”,Draw);
//把包裹放进你的意图中
myIntent.putExtras(myBundle);
//按照意图中的定义启动活动
星触觉(myIntent);
}//结束saveNameGrade

}

Java数组索引是基于零的

这行代码:

int [] Win = new int[10];
Win[10] = Integer.parseInt(SWin[10]);
Delcares包含10个项目的数组。这些项目的索引范围为0到9

这行代码:

int [] Win = new int[10];
Win[10] = Integer.parseInt(SWin[10]);
尝试为数组指定超出范围的值。我还怀疑,在此之前,访问SWin[10]会崩溃

我想你想说的是:

for (int index = 0; index < (SWin.length) && (index < 10); index++)
{
   Win[index] = Integer.ParseInt(SWin[index]);   
}
for(int index=0;index<(摆动长度)和&(index<10);index++)
{
Win[index]=Integer.ParseInt(SWin[index]);
}

您会遇到什么错误?请编辑您的问题以包含您收到的任何错误消息。“应用程序崩溃”的信息不足以让人们像@selbie试图做的那样,在不进行有根据的猜测的情况下诊断您的问题。如果应用程序真的崩溃了,您是否尝试过自己调试它?包括您尝试过的内容的更多细节将改进您的问题,并帮助您更好地回答未来的问题。按“继续”后,项目仍然会崩溃。我不打算为您调试程序。我怀疑您在上面的代码路径中有多个bug。我希望看到您努力学习编程、调试、设置断点、分析异常(和日志)的基础知识,以及您正在使用的语言/工具。