ok my app is to solve the Pythagorean theorem.
package com.example;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class TheoremappActivity extends Activity {
/** Called when the activity is first created. */
EditText field1;
EditText field2;
String num1;
String num2;
String RAnswer;
double num3;
double num4;
double num5;
double num6;
double fnum;
double snum;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button1 = (Button) findViewById(R.id.button1);
field1 = (EditText) findViewById(R.id.tf1);
field2 = (EditText) findViewById(R.id.tf2);
double fnum = Double.parseDouble(num1);
double snum = Double.parseDouble(num2);
final String RAnswer = Double.toString(num6);
num2 = field1.toString();
num1 = field2.toString();
num3 = fnum * fnum;
num4 = snum * snum;
num5 = num4 + num3;
num6 = sqrt(num5);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
RAnswer.toString();
}
});
}
private double sqrt(double num5) {
return num6;
}
}
here is the manifest
%26lt;?xml version="1.0" encoding="utf-8"?%26gt;
%26lt;manifest xmlns:android="http://schemas.android.co鈥?br>
package="com.example"
android:versionCode="1"
android:versionName="1.0"%26gt;
%26lt;uses-sdk android:minSdkVersion="4" /%26gt;
%26lt;application android:icon="@drawable/icon" android:label="@string/app_name"%26gt;
%26lt;activity android:name=".TheoremappActivity"
android:label="@string/app_name"%26gt;
%26lt;intent-filter%26gt;
%26lt;action android:name="android.intent.action.MAIN鈥?/%26gt;
%26lt;category android:name="android.intent.category.LA鈥?/%26gt;
%26lt;/intent-filter%26gt;
%26lt;/activity%26gt;
%26lt;/application%26gt;
%26lt;/manifest%26gt;|||It looks like you are solving the problem in your onCreate and may not have valid values in num1 and num2.
So maybe you might want to move some of that code to your onClick, and then test for valid values and then do you calcs.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment