Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/308.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 我的Android程序有;“停止工作”;。调试问题_Java_Android_Eclipse_Debugging_Widget - Fatal编程技术网

Java 我的Android程序有;“停止工作”;。调试问题

Java 我的Android程序有;“停止工作”;。调试问题,java,android,eclipse,debugging,widget,Java,Android,Eclipse,Debugging,Widget,这是我的主要活动。我使用Log.d使它运行到停止运行的地方,即onCreate 4。我不知道为什么它会停在getReferences部分。我在模拟器中运行程序,但它会自动告诉我,我的程序已停止工作 package com.example.carloanbuddy4; import java.text.NumberFormat; import android.app.Activity; import android.content.SharedPreferences; import andro

这是我的主要活动。我使用Log.d使它运行到停止运行的地方,即onCreate 4。我不知道为什么它会停在getReferences部分。我在模拟器中运行程序,但它会自动告诉我,我的程序已停止工作

package com.example.carloanbuddy4;

import java.text.NumberFormat;

import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.view.View.OnClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Spinner;
import android.widget.AdapterView;
import android.widget.TextView.OnEditorActionListener;

public class MainActivity extends Activity implements OnClickListener,
        OnEditorActionListener, OnItemSelectedListener, OnFocusChangeListener,
        OnCheckedChangeListener {
    private TextView payment;
    private TextView interest;
    private EditText principle;
    private TextView interestText;
    private CheckBox interestBox;
    private EditText years;
    private TextView apr;
    Button plusbutton;
    Button minusbutton;
    private static String TAG = "CAR";
    private Spinner period;
    private double aprPercent;
    private int t;





    public static final String PREFS_NAME = "MyPrefsFile";


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.d(TAG, "onCreate1");
        this.getReferences();
        this.setListeners();        
    }



    @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;
    }

    @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();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    public void getReferences() {
        payment = (TextView) findViewById(R.id.paymentLabel);
        Log.d(TAG, "onCreate2");
        interest = (TextView) findViewById(R.id.interestLabel);
        Log.d(TAG, "onCreate3");
        apr = (TextView) findViewById(R.id.aprLabel);
        Log.d(TAG, "onCreate4");
        aprPercent = Double.parseDouble(apr.getText().toString());
        Log.d(TAG, "onCreate5");
        interestText = (TextView) findViewById(R.id.interestText);
        Log.d(TAG, "onCreate6");
        interestBox = (CheckBox) findViewById(R.id.checkBox1);
        Log.d(TAG, "onCreate7");
        interestBox.setChecked(false);
        principle = (EditText) findViewById(R.id.principleEditText);
        Log.d(TAG, "onCreate8");
        years = (EditText) findViewById(R.id.yearsEditText);
        Log.d(TAG, "onCreate9");
        period = (Spinner) findViewById(R.id.spinner1);
        Log.d(TAG, "onCreate10");
        minusbutton = (Button) findViewById(R.id.minusbutton);
        Log.d(TAG, "onCreate11");
        plusbutton = (Button) findViewById(R.id.plusbutton);
        Log.d(TAG, "onCreate12");
        ArrayAdapter<CharSequence> adapter = ArrayAdapter
                .createFromResource(this, R.array.options,
                        android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        period.setAdapter(adapter);
        Log.d(TAG, "onCreate13");


        // principle.setOnFocusChangeListener(this);
        Log.d(TAG, "getReferences principle: " + principle.getText()
                + " years:" + years.getText());

    }

    public void setListeners() { // where the event being consumed will be
                                    // responding
        principle.setOnFocusChangeListener(this);
        principle.setOnEditorActionListener(this);
        years.setOnFocusChangeListener(this);
        years.setOnEditorActionListener(this);
        interestBox.setOnCheckedChangeListener(this);
        period.setOnItemSelectedListener(this);

        Log.d(TAG, "setListeners principle: " + principle.getText() + " years:"
                + years.getText());
    }

    public void setPeriodValue() {
        if (period.getSelectedItem().toString().equalsIgnoreCase("Monthly")) {
            t = 12;
        } else if (period.getSelectedItem().toString()
                .equalsIgnoreCase("Quarterly")) {
            t = 4;
        } else if (period.getSelectedItem().toString()
                .equalsIgnoreCase("Annually")) {
            t = 1;
        }
    }

    public void updateResults() {
        double dblPrinciple = Double
                .parseDouble(principle.getText().toString());
        double dblYears = Double.parseDouble(years.getText().toString());

        double num, denom, dblPayment;
        double r = aprPercent / 100;
        NumberFormat nf = NumberFormat.getNumberInstance();
        NumberFormat curr = NumberFormat.getCurrencyInstance();
        apr.setText(nf.format(aprPercent));
        setPeriodValue();
        num = (r / t);
        denom = (1 - Math.pow((1 + num), (t * -dblYears)));
        dblPayment = dblPrinciple * (num / denom);
        payment.setText(curr.format(dblPayment));
        interest.setText(curr
                .format((dblPayment * t * dblYears) - dblPrinciple));

    }

    public void onFocusChange(View v, boolean hasfocus) {
        Log.d(TAG, "Focus Change principle: " + principle.getText() + " years"
                + years.getText());
        switch (v.getId()) {
        case R.id.principleEditText:
        case R.id.yearsEditText:
            updateResults();
        default:
            updateResults();

        }
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if(interestBox.isChecked()) {
            interest.setVisibility(View.VISIBLE);
            interestText.setVisibility(View.VISIBLE);
        }
        else {
            interest.setVisibility(View.INVISIBLE);
            interestText.setVisibility(View.INVISIBLE);
        }
        if (interestBox.isChecked()!=true){
            interest.setVisibility(View.INVISIBLE);
            interestText.setVisibility(View.INVISIBLE);
        }
        else {
            interest.setVisibility(View.VISIBLE);
            interestText.setVisibility(View.VISIBLE);
        }       
    }

    @Override
    public void onNothingSelected(AdapterView<?> parent) {
        updateResults();
    }

    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        updateResults();
        return false;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.minusbutton:
            if (aprPercent == 1) {
                break;
            } else {
                aprPercent = aprPercent - 1.0;
                updateResults();
                break;
            }
        case R.id.plusbutton:
            if (aprPercent == 20) {
                break;
            } else {
                aprPercent = aprPercent + 1.0;
                updateResults();
                break;
            }

        }
    }

    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position,
            long id) {
        updateResults();
    }

}
package com.example.carloanbuddy4;
导入java.text.NumberFormat;
导入android.app.Activity;
导入android.content.SharedReferences;
导入android.content.SharedReferences.Editor;
导入android.os.Bundle;
导入android.preference.PreferenceManager;
导入android.util.Log;
导入android.view.KeyEvent;
导入android.view.Menu;
导入android.view.MenuItem;
导入android.view.view;
导入android.view.view.OnFocusChangeListener;
导入android.view.view.OnClickListener;
导入android.widget.AdapterView.OnItemSelectedListener;
导入android.widget.ArrayAdapter;
导入android.widget.Button;
导入android.widget.CheckBox;
导入android.widget.CompoundButton;
导入android.widget.CompoundButton.OnCheckedChangeListener;
导入android.widget.EditText;
导入android.widget.TextView;
导入android.widget.Spinner;
导入android.widget.AdapterView;
导入android.widget.TextView.OnEditorActionListener;
公共类MainActivity扩展活动实现OnClickListener,
OnEditorActionListener、OnItemSelectedListener、OnFocusChangeListener、,
OnCheckedChangeListener{
私人文本视图支付;
私人文本视图兴趣;
私人编辑文本原则;
私有文本查看兴趣文本;
私人复选框兴趣框;
私人编辑年;
私有文本视图;
按钮加上按钮;
按钮和按钮;
私有静态字符串TAG=“CAR”;
私人纺纱机时期;
私人双保险;
私人int t;
公共静态最终字符串PREFS\u NAME=“MyPrefsFile”;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(标记为“onCreate1”);
这个.getReferences();
this.setListeners();
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
//为菜单充气;这会将项目添加到操作栏(如果存在)。
getMenuInflater().充气(R.menu.main,menu);
返回true;
}
@凌驾
公共布尔值onOptionsItemSelected(菜单项项){
//处理操作栏项目单击此处。操作栏将
//自动处理Home/Up按钮上的点击,只要
//在AndroidManifest.xml中指定父活动时。
int id=item.getItemId();
if(id==R.id.action\u设置){
返回true;
}
返回super.onOptionsItemSelected(项目);
}
public void getReferences(){
payment=(TextView)findViewById(R.id.paymentLabel);
Log.d(标记为“onCreate2”);
兴趣=(TextView)findViewById(R.id.interestLabel);
Log.d(标记为“onCreate3”);
apr=(TextView)findViewById(R.id.aprLabel);
Log.d(标记为“onCreate4”);
aprPercent=Double.parseDouble(apr.getText().toString());
Log.d(标记为“onCreate5”);
interestText=(TextView)findViewById(R.id.interestText);
Log.d(标记为“onCreate6”);
interestBox=(复选框)findViewById(R.id.checkBox1);
Log.d(标记为“onCreate7”);
利息箱设置检查(假);
principle=(EditText)findViewById(R.id.principleEditText);
Log.d(标记为“onCreate8”);
年份=(编辑文本)findViewById(R.id.yearsEditText);
Log.d(标记为“onCreate9”);
周期=(微调器)findViewById(R.id.spinner1);
Log.d(标记为“onCreate10”);
minusbutton=(按钮)findViewById(R.id.minusbutton);
Log.d(标记“onCreate11”);
plusbutton=(按钮)findViewById(R.id.plusbutton);
Log.d(标记“onCreate12”);
ArrayAdapter适配器=ArrayAdapter
.createFromResource(此,R.array.options,
android.R.layout.simple\u微调器(项目);
setDropDownViewResource(android.R.layout.simple\u微调器\u下拉菜单\u项);
period.setAdapter(适配器);
Log.d(标记为“onCreate13”);
//原理。setOnFocusChangeListener(本);
Log.d(标记“getReferencesPrinciple:+principle.getText())
+“年:“+years.getText());
}
public void setListeners(){//将在其中使用事件
//回应
原理。setOnFocusChangeListener(本);
原理。setOnEditorActionListener(此);
年。setOnFocusChangeListener(本);
年。setOnEditorActionListener(此);
setOnCheckedChangeListener(这个);
period.setOnItemSelectedListener(此);
Log.d(标记“setListeners原则:”+principle.getText()+“年份:”
+年。getText());
}
public void setPeriodValue(){
if(period.getSelectedItem().toString().equalsIgnoreCase(“每月”)){
t=12;
}else if(period.getSelectedItem().toString()期间)
.equalsIgnoreCase(“季度”)){
t=4;
}else if(period.getSelectedItem().toString()期间)
.equalsIgnoreCase(“每年”)){
t=1;
}
}
public void updateResults(){
双dblPrinciple=双dblPrinciple
.parseDouble(principle.getText().toString());
double dblYears=double.parseDouble(years.getText().toString());
double num、denom、dblPayment;
双r=1/100;
NumberFormat nf=NumberFormat.getNumberInstance();
NumberFormat curr=NumberFormat.getCurrencyInstance();
apr.setText(nf.format(aprPercent));
setPeriodValue();
num=(r/t);
denom=(1-Math.pow((1+num),(t*-dblYears));
dblPayment=dblPrinci
<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="com.example.carloanbuddy4.MainActivity" >

    <TableLayout
        android:id="@+id/mainTable"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:shrinkColumns="0, 1"
        android:stretchColumns="0, 1">

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:text="@string/principleText"
                android:ems="5"
                android:textStyle="bold" />

            <EditText
                android:id="@+id/principleEditText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:ems="10"
                android:inputType="numberDecimal" 
                android:text="@string/principle_entered"
                android:textSize="12sp" >
                 <requestFocus />
            </EditText>

        </TableRow>

        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:text="@string/yearsText"
                android:ems="5"
                android:textStyle="bold" />

            <EditText
                android:id="@+id/yearsEditText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:ems="5"
                android:inputType="number"
                android:labelFor="@id/yearsEditText"
                android:text="@string/years_entered"
                android:textSize="12sp" >

                 <requestFocus />
            </EditText>


        </TableRow>

        <TableRow
            android:id="@+id/tableRow3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

             <TextView
                 android:id="@+id/textView3"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:padding="5dp"
                 android:text="@string/aprText"
                 android:ems="5"
                 android:textSize="12sp"
                 android:textStyle="bold" />

             <TextView
                 android:id="@+id/aprLabel"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_marginLeft="5dp"
                 android:ems="5"
                 android:labelFor="@id/aprLabel"
                 android:paddingLeft="12dp"
                 android:textSize="20sp" >

             </TextView>

             <Button
                 android:id="@+id/minusbutton"
                 android:onClick="onClick"
                 style="?android:attr/buttonStyleSmall"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:text="@string/minus_button" />

            <Button
                 android:id="@+id/plusbutton"
                 android:onClick="onClick"
                 style="?android:attr/buttonStyleSmall"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:text="@string/plus_button" />

        </TableRow>

        <TableRow
            android:id="@+id/tableRow4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

             <TextView
                 android:id="@+id/textView4"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:padding="5dp"
                 android:text="@string/periodText"
                 android:textSize="12sp"
                 android:textStyle="bold" />

               <Spinner
                    android:id="@+id/spinner1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@android:drawable/btn_dropdown"
                    android:spinnerMode="dropdown" />



        </TableRow>

        <TableRow
            android:id="@+id/tableRow5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingTop="10dp" >

        </TableRow>

        <TableRow
            android:id="@+id/tableRow6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <CheckBox
                android:id="@+id/checkBox1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:checked="false"
                android:focusableInTouchMode="false"
                android:text="@string/interest_checkbox"
                android:textSize="12sp"/>

        </TableRow>

        <TableRow
            android:id="@+id/tableRow7"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingTop="10dp" >

            <TextView
                android:id="@+id/paymentText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:text="@string/paymentText"
                android:textSize="12sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/paymentLabel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="10dp"
                android:text="@string/payment_total"
                android:textSize="12sp"
                android:textStyle="bold" />

        </TableRow>

        <TableRow
            android:id="@+id/tableRow8"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/interestText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:text="@string/interestText"
                android:textSize="12sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/interestLabel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="10dp"
                android:text="@string/interest_total"
                android:textSize="12sp"
                android:textStyle="bold" />
        </TableRow>

         <TableRow
            android:id="@+id/tableRow9"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingTop="10dp" >

          <CheckBox
                android:id="@+id/checkBox2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:checked="true"
                android:focusableInTouchMode="false"
                android:text="@string/save_checkbox"
                android:textSize="12sp" />
         </TableRow>
    </TableLayout>

</RelativeLayout>
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Log.d(TAG, "onCreate1");

    try {
        this.getReferences();
    } catch (Exception e){
        StringWriter errors = new StringWriter();
        e.printStackTrace(new PrintWriter(errors));
        Log.i("Exception", errors.toString());
    }

    this.setListeners();        
}