2012-02-11 2 views
1
package dum.de.dum; 

import android.app.Activity; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.EditText; 
import android.os.Bundle; 

수입 보통 수입?내 안드로이드 복리 계산 계산기가 계속 충돌합니다

public class CalcActivity extends Activity { 


    Button finish; 
    double total; 
    double interest2; 
    double time2; 
    double base2; 


    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 




     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     finish = (Button) findViewById(R.id.total); 
     finish.setOnClickListener(new OnClickListener(){ 
      public void onClick(View V) { 

       EditText base; 
       base = (EditText) findViewById(R.id.base); 
       String baseValue = base.getText().toString(); 
       double BaseNum = Double.parseDouble(baseValue); 

       EditText interest; 
       interest = (EditText) findViewById(R.id.interest); 
       String interestValue = interest.getText().toString(); 
       double interestNum = Double.parseDouble(interestValue); 

       EditText time; 
       time = (EditText) findViewById(R.id.time); 
       String timeValue = time.getText().toString(); 
       double timeNum = Double.parseDouble(timeValue); 

       double total = BaseNum * Math.pow(interestNum + 1, timeNum);   

은 그게 문제가 될 수 있는지 잘 모르겠어요 그래서 그들은 숫자를 구문 분석 할 때 사람들이 문제가 있었다 들었어요하고 있는지 나는 그것을 해결하는 방법을 모르고에게이 없다

 EditText Output; 
     Output = (EditText) findViewById(R.id.total); 
     Output.setText("Your total is: " + total); 

     }; 

    }); 
} 
} 

내가 에뮬레이터에서 실행하려고 할 때마다 즉시 강제 종료합니다. 나는 new-ish 프로그래머이고 Eclipse 코드에서 오류 코드를 얻지 못한다.

답변

2

시도와

Output.setText("Your total is: " + total); 

교체 : 당신의 finish 버튼의 ID가 R.id.total하지

Output.setText("Your total is: " + String.valueOf(total)); 
+0

총 ID/: main.xml에 버튼 ID에 한 번

finish = (Button) findViewById(R.id.total); finish.setOnClickListener(new OnClickListener(){ 

검사는 안드로이드> 된 직후 주어진다. 정답이 아닙니다. – kosa

+0

나는 그걸 넣었고 나는 여전히 같은 오류가 나옵니다. –

+0

둘 다 동일하다는 것은 무엇을 의미합니까? 그것들에는 명백한 차이가 있습니다. – FabianCook

3
finish = (Button) findViewById(R.id.total); 

을 - ... 즉,이에 따라 EditText있어

Output = (EditText) findViewById(R.id.total); 

해당 ID를 사용하여 버튼을 찾으려고 할 때 ClassCastException이 표시됩니다. 즉시

+0

대단히 고맙습니다. 정확하게 : –

+0

와우는 전혀 눈치 채지 못했습니다. – FabianCook

+0

@SmartLemon : 내가하기 전에 조금 시간이 걸렸습니다. : D – Squonk

0

당신은 메뉴 -> 창 -> showView-> 로그 캣에 의해 이클립스보기를 openeing하여 오류를 볼 수 있습니다, 귀하의 설명에서 같이

, 해당 응용 프로그램 충돌이 활동을 시작, 문제가있는 지역이 될 수있다 : 모두 동일

관련 문제