Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 不幸的是[应用程序]已停止--请帮助我解决未知问题_Java_Android_Xml - Fatal编程技术网

Java 不幸的是[应用程序]已停止--请帮助我解决未知问题

Java 不幸的是[应用程序]已停止--请帮助我解决未知问题,java,android,xml,Java,Android,Xml,这是我第一次尝试Android应用程序。但是,当我尝试在emulator中运行它时,会出现一个错误,指示应用程序在加载之前已经停止。我已经倾注了大量资源,无法找到解决方案,因此我将代码发布在这里,希望有人能够识别我的问题。如果你能帮助我,那就提前谢谢你了!我将发布我不经意遗漏的任何内容 AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schema

这是我第一次尝试Android应用程序。但是,当我尝试在emulator中运行它时,会出现一个错误,指示应用程序在加载之前已经停止。我已经倾注了大量资源,无法找到解决方案,因此我将代码发布在这里,希望有人能够识别我的问题。如果你能帮助我,那就提前谢谢你了!我将发布我不经意遗漏的任何内容

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.atillalabs.debatebreakrounds"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="18" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.debatebreakrounds.MainActivity"
            android:label="@string/app_name" 
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

MainActivity.java

package com.atillalabs.debatebreakrounds;

import java.util.ArrayList;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import com.atillalabs.debatebreakrounds.R;

public class MainActivity extends Activity
{

    boolean continues;
    String prst;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        setContentView(R.layout.activity_main);

        RelativeLayout container = (RelativeLayout)findViewById(R.id.maincontainer);
        Button calculate = (Button)container.findViewById(R.id.calculated);
        calculate.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View arg0) {

                simulate();
            }

        });
    }

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

    private void simulate()
    {
        try
        {
            continues = true;

            EditText numbreak1 = (EditText)findViewById(R.id.editText1);  
            int numbreak = Integer.parseInt(numbreak1.getText().toString());
            EditText numrds1 = (EditText)findViewById(R.id.editText2);  
            int numrds = Integer.parseInt(numrds1.getText().toString());
            EditText pmrds1 = (EditText)findViewById(R.id.editText3);  
            int pmrds = Integer.parseInt(pmrds1.getText().toString());
            EditText numrdsknown1 = (EditText)findViewById(R.id.editText4); 
            int numrdsknown = Integer.parseInt(numrdsknown1.getText().toString());
            EditText numexpectedwin1 = (EditText)findViewById(R.id.editText5);  
            int numexpectedwin = Integer.parseInt(numexpectedwin1.getText().toString());
            int presentwinct;

            int[] knownrslts;
            ArrayList<Integer> inp = new ArrayList<Integer>();

            for (int i = 0; i <= numrdsknown; i++)
            {
                if (numrdsknown == 0)
                    inp.add(Integer.parseInt(promptBox("How Many Entries", "How many entries are there?")));
                else
                    inp.add(Integer.parseInt(promptBox("Teams by Record", "How many teams have a " + (numrdsknown-i) + "-" + i + " record?")));
                if (inp.get(inp.size()-1) < 0) throw new Exception("Input may not be negative");
                if (!continues) return;
            }

            if (numrdsknown > 0)
                presentwinct = Integer.parseInt(promptBox("Your record", "How many of " + numrdsknown + " known rounds have you won?"));
            else
                presentwinct = 0;

            if (!continues) return;

            knownrslts = new int[inp.size()];
            for (int j = 0; j < inp.size(); j++)
                knownrslts[j] = inp.remove(0);

            Breakcalc calulator = new Breakcalc();

            double probabilityOfBreakingGivenCurrentPerformance = 
                    calulator.probabilityOfBreakingGivenCurrentPerformance(numbreak, presentwinct, numrds, pmrds, knownrslts);
            double expectedNumFinalWinsGivenCurrentPerformance = 
                    calulator.expectedNumFinalWinsGivenCurrentPerformance(numbreak, presentwinct, numrds, pmrds, knownrslts);
            double probabilityOfBreakingGivenExpectedFinalPerformance = 
                    calulator.probabilityOfBreakingGivenExpectedFinalPerformance(numbreak, numexpectedwin, numrds, pmrds, knownrslts);


            // temp - show results
            messageBox(probabilityOfBreakingGivenCurrentPerformance + " " + expectedNumFinalWinsGivenCurrentPerformance + " " + probabilityOfBreakingGivenExpectedFinalPerformance);
        }
        catch (Exception e)
        {
            messageBox("The numbers you entered do not add up.");
        }
    }

    public void nocontinue()
    {
        continues = false;
    }

    public String promptBox(String title, String text)
    {
        prst = new String();
        AlertDialog.Builder alert = new AlertDialog.Builder(this);
        alert.setTitle(title);
        alert.setMessage(text);
        final EditText input = new EditText(this);
        alert.setView(input);
        alert.setPositiveButton("Continue", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            String value = input.getText().toString();
            setpromptretstr(value);     
         }
        });
        alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
         public void onClick(DialogInterface dialog, int whichButton) {
             nocontinue();
        }
        });
        alert.show();
        return prst;
    }

    public void setpromptretstr(String x)
    {
        prst = x;
    }

    public void messageBox(String message)
    {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(message)
               .setCancelable(false)
               .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                        //do nothing
                   }
               });
        AlertDialog alert = builder.create();
        alert.show();
package com.atillalabs.debatebreakrounds;
导入java.util.ArrayList;
导入android.app.Activity;
导入android.app.AlertDialog;
导入android.content.DialogInterface;
导入android.content.pm.ActivityInfo;
导入android.os.Bundle;
导入android.view.Menu;
导入android.view.view;
导入android.view.view.OnClickListener;
导入android.widget.Button;
导入android.widget.EditText;
导入android.widget.RelativeLayout;
导入com.atillalabs.debatebreakrounds.R;
公共类MainActivity扩展了活动
{
布尔继续;
字符串prst;
@凌驾
创建时受保护的void(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN\u ORIENTATION\u Picture);
setContentView(R.layout.activity_main);
RelativeLayout容器=(RelativeLayout)findViewById(R.id.maincontainer);
Button calculate=(Button)container.findViewById(R.id.calculated);
calculate.setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图arg0){
模拟();
}
});
}
@凌驾
公共布尔onCreateOptions菜单(菜单)
{
//为菜单充气;这会将项目添加到操作栏(如果存在)。
getMenuInflater().充气(R.menu.main,menu);
返回true;
}
私有void模拟()
{
尝试
{
继续=正确;
EditText numbreak1=(EditText)findViewById(R.id.editText1);
int numbreak=Integer.parseInt(numbreak1.getText().toString());
EditText numrds1=(EditText)findViewById(R.id.editText2);
int numrds=Integer.parseInt(numrds1.getText().toString());
EditText pmrds1=(EditText)findViewById(R.id.editText3);
int pmrds=Integer.parseInt(pmrds1.getText().toString());
EditText numrdsnown1=(EditText)findViewById(R.id.editText4);
int numrdsnown=Integer.parseInt(numrdsnown1.getText().toString());
EditText numexpectedwin1=(EditText)findViewById(R.id.editText5);
int numexpectedwin=Integer.parseInt(numexpectedwin1.getText().toString());
int presentwinct;
int[]已知的NRSLTS;
ArrayList inp=新的ArrayList();
对于(int i=0;i 0)
presentwinct=Integer.parseInt(promptBox(“您的记录”,“您赢得了多少”+numrdsknown+“已知回合?”);
其他的
presentwinct=0;
如果(!继续)返回;
knownrslts=新整数[inp.size()];
对于(int j=0;j
}

}

activity_main.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: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" 
    android:id="@+id/maincontainer">

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="22dp"
        android:layout_marginTop="17dp"
        android:text="Number that will break:"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView3"
        android:layout_below="@+id/textView3"
        android:layout_marginTop="15dp"
        android:text="Number of rounds with known results:"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <EditText
        android:id="@+id/editText3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/textView3"
        android:layout_alignParentRight="true"
        android:ems="2"
        android:inputType="number" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/textView1"
        android:layout_alignParentRight="true"
        android:ems="2"
        android:inputType="number" >

        <requestFocus />

        <requestFocus />

    </EditText>

    <EditText
        android:id="@+id/editText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignBottom="@+id/textView2"
        android:ems="2"
        android:inputType="number" >
    </EditText>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_below="@+id/editText1"
        android:layout_marginTop="14dp"
        android:text="Total number of rounds:"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView2"
        android:layout_below="@+id/editText2"
        android:layout_marginTop="14dp"
        android:text="Number of power-matched rounds:"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <EditText
        android:id="@+id/editText4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/textView4"
        android:layout_alignParentRight="true"
        android:ems="2"
        android:inputType="number" />

    <TextView
        android:id="@+id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView4"
        android:layout_below="@+id/editText4"
        android:layout_marginTop="15dp"
        android:text="Number of rounds you expect to win:"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <EditText
        android:id="@+id/editText5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/textView5"
        android:layout_alignParentRight="true"
        android:ems="2"
        android:inputType="number" />

    <Button
        android:id="@+id/calculated"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView5"
        android:layout_alignRight="@+id/editText5"
        android:layout_below="@+id/textView5"
        android:layout_marginTop="14dp"
        android:text="Simulate Tournament" />

</RelativeLayout>

<activity
            android:name="com.atillalabs.debatebreakrounds.MainActivity"
            android:label="@string/app_name" 
            android:screenOrientation="portrait">
....