2012-12-17 4 views
0

동일한 프로그램이 하나의 컴퓨터에서 실행되며 다른 컴퓨터에서 실행되지 않을 수도 있습니다. 그것은 다른 포인터에 널 포인터 예외를 기술합니다. CheckBox를 클릭하면 불행히도 활동이 중단되었다고 표시됩니다.하나의 컴퓨터에서 실행중인 Android 프로그램이 다른 컴퓨터에서 실행되지 않음

package com.example.gtbactivity; 

import android.app.Activity; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.CheckBox; 
import android.widget.CompoundButton; 
import android.widget.CompoundButton.OnCheckedChangeListener; 
import android.widget.TextView; 

public class MainActivity extends Activity implements OnCheckedChangeListener, OnClickListener { 

    CheckBox cb1,cb2; 
    TextView t1,t2,t3; 
    Button b; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     cb1=(CheckBox)findViewById(R.id.checkBox1); 
     cb2=(CheckBox)findViewById(R.id.checkBox2); 
     b=(Button)findViewById(R.id.button1); 
     t1=(TextView)findViewById(R.id.textView1); 
     t2=(TextView)findViewById(R.id.textView2); 
     t3=(TextView)findViewById(R.id.textView3); 


     b.setOnClickListener(this); 
       cb1.setOnCheckedChangeListener(this); 
       cb2.setOnCheckedChangeListener(this); 


    } 

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



    @Override 
    public void onCheckedChanged(CompoundButton arg0, boolean arg1) { 
     if(cb1.isChecked()) 
     { t1.setText("10");} 
     else 
     {t1.setText("0");} 


     if(cb2.isChecked()) 
     { t2.setText("15");} 
     else 
     {t2.setText("0");} 


    } 
    @Override 
    public void onClick(View arg0) { 
     int total,a,b; 
     a=Integer.parseInt(t1.getText().toString()); 
     b=Integer.parseInt(t2.getText().toString()); 

     total=a+b; 
     t3.setText(String.valueOf(total)); 

    } 

} 

답변

2

나는 어쩌면 당신이 nullpointer 예외를

대신

t2=(TextView)findViewById(R.id.textView1); 

사용

을 받고있는 이유는, 텍스트 뷰의 T1이 초기화되는 것을 볼 해달라고 -이 : 아래

코드입니다
t1=(TextView)findViewById(R.id.textView1); 
관련 문제