At this point of the code A and B are null: iA = Integer.parseInt(A.trim()); iB = Integer.parseInt(B.trim());
The computation part should be in your onClick method. On Tue, Jun 15, 2010 at 6:30 PM, Aaron <amd2...@gmail.com> wrote: > Trying to get my first android app up and running. It's a basic GCF > calculator, but I can't get it to run. Can anyone help me out? > > > package com.example.GCF; > > import java.util.Arrays; > > import android.app.Activity; > import android.os.Bundle; > import android.view.View; > import android.view.View.OnClickListener; > import android.widget.Button; > import android.widget.EditText; > import android.widget.TextView; > > public class GCF extends Activity { > private TextView mAnswer; > private EditText mA, mB; > private Button ok; > private String A, B; > private int iA, iB; > > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(R.layout.main); > > mA = (EditText) findViewById(R.id.entry); > mB = (EditText) findViewById(R.id.entry1); > ok = (Button) findViewById(R.id.ok); > mAnswer = (TextView) findViewById(R.id.answer1); > > ok.setOnClickListener(new OnClickListener() { > public void onClick(View v) > { > A = mA.getText().toString(); > B = mB.getText().toString(); > } > }); > > // the String to int conversion happens here > iA = Integer.parseInt(A.trim()); > iB = Integer.parseInt(B.trim()); > > while (iA != iB) { > int[] nums={ iA, iB, Math.abs(iA-iB) }; > Arrays.sort(nums); > iA=nums[0]; > iB=nums[1]; > } > updateDisplay(); > } > private void updateDisplay() { > mAnswer.setText( > new StringBuilder().append(iA)); > > } > > } > > -- > You received this message because you are subscribed to the Google > Groups "Android Beginners" group. > > NEW! Try asking and tagging your question on Stack Overflow at > http://stackoverflow.com/questions/tagged/android > > To unsubscribe from this group, send email to > android-beginners+unsubscr...@googlegroups.com<android-beginners%2bunsubscr...@googlegroups.com> > For more options, visit this group at > http://groups.google.com/group/android-beginners?hl=en > -- YuviDroid http://android.yuvalsharon.net -- You received this message because you are subscribed to the Google Groups "Android Beginners" group. NEW! Try asking and tagging your question on Stack Overflow at http://stackoverflow.com/questions/tagged/android To unsubscribe from this group, send email to android-beginners+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en