I'm new to android app development and I've been trying to solve this problem since a long time but couldnt get a solution,plz help me out.I have created a simple app which accepts data in 5 variables and den calculates the addition of those variables.There is no error while compiling the code but while running the app on the emulator it gives an error source not found error
MainActivity.java
package com.example.totalmarks;
import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Button;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
public class MainActivity extends Activity
{
//TextWatcher
private TextWatcher textWatcher = new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3)
{
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
checkFieldsForEmptyValues();
}
@Override
public void afterTextChanged(Editable editable) {
}
};
EditText regno;
EditText cat1;
EditText cat2;
EditText quiz1;
EditText quiz2;
EditText quiz3;
TextView tt;
Button calculate;
float a=0;
float b=0;
float c=0;
float d=0;
float e=0;
float f=0;
String reg;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
regno=(EditText)findViewById(R.id.regno);
cat1=(EditText)findViewById(R.id.cat1);
cat2=(EditText)findViewById(R.id.cat2);
quiz1=(EditText)findViewById(R.id.quiz1);
quiz2=(EditText)findViewById(R.id.quiz2);
quiz3=(EditText)findViewById(R.id.quiz3);
tt=(TextView)findViewById(R.id.tt);
//set listeners
cat1.addTextChangedListener(textWatcher);
cat2.addTextChangedListener(textWatcher);
quiz1.addTextChangedListener(textWatcher);
quiz2.addTextChangedListener(textWatcher);
quiz3.addTextChangedListener(textWatcher);
regno.addTextChangedListener(textWatcher);
// run once to disable if empty
checkFieldsForEmptyValues();
calculate=(Button) findViewById(R.id.calculate);
calculate.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
calculate();}});
}
private void calculate()
{
a=Float.parseFloat(cat1.getText().toString());
b=Float.parseFloat(cat2.getText().toString());
c=Float.parseFloat(quiz1.getText().toString());
d=Float.parseFloat(quiz2.getText().toString());
e=Float.parseFloat(quiz3.getText().toString());
f=a+b+c+d+e;
tt.setText(Float.toString(f));
}
private void checkFieldsForEmptyValues(){ Button b = (Button) findViewById(R.id.calculate); String s1 = cat1.getText().toString(); String s2 = cat2.getText().toString(); String s3 = quiz1.getText().toString(); String s4 = quiz2.getText().toString(); String s5 = quiz3.getText().toString(); String s6 = regno.getText().toString(); String s7=s6.substring(0,2); int digits=Integer.parseInt(s7); if(s1.equals("") || s2.equals("") || s3.equals("") || s4.equals("") ||
s5.equals("") || s6.equals("") )
b.setEnabled(false);
else if(digits<10 || digits>14)
{
regno.setError("Enter Correct Registration number");
b.setEnabled(false);
}
else
b.setEnabled(true);
}
}
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://ift.tt/nIICcg"
package="com.example.totalmarks"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Aucun commentaire:
Enregistrer un commentaire