1

I developed an app.. it is a numerology app.. where user's firstname, second name and third name is collected and calculated... values from 1 -9 are assigned for each values and when calculating these value for all letters has to be added together and make into a one digit 1 - 9. after that this value is given to textview in another activity and the result is displayed.... my problem is i did the programming .. but when adding .. correct value is not displaying.. i used switch case for giving values for each letter... i gave 0 as default value.. when result is displayed the value is displaying as 0 . if i change it to 1 then 1 is added to the value and that value is isplaying.. please check my code and if ther any mistake pls point it out 4 me... thanks...

MainActivity.java

public void gReport(View V) { long sum1 = 0; long sum2 = 0; long sum3 = 0; long sum7 = 0; long sum8 = 0; long sum9 = 0; long sum10 = 0; EditText et1 = (EditText) findViewById (R.id.editText1); EditText et2 = (EditText) findViewById (R.id.editText2); EditText et3 = (EditText) findViewById (R.id.editText3); EditText et7 = (EditText) findViewById (R.id.editText7); EditText et8 = (EditText) findViewById (R.id.editText8); EditText et9 = (EditText) findViewById (R.id.editText9); sum1 = getSum1(et1.getText().toString()); sum2 = getSum2(et2.getText().toString()); sum3 = getSum3(et3.getText().toString()); /*sum7 = getSum7(et7.getText().toString()); sum8 = getSum8(et8.getText().toString()); sum9 = getSum9(et9.getText().toString());*/ sum10 = getSum10 (et1.getText().toString() + et2.getText().toString() + et3.getText().toString()); Intent i = new Intent(this, FirstResult.class); i.putExtra("name10", sum10 + ""); startActivity(i); } private long getSum10(String text) { long sum10 = 0; char[] name10 = new char[text.length()]; name10 = text.toCharArray(); for(int i=0; i<text.length(); i++) { sum10 += value10( name10[i] ); } while (sum10>9) { sum10 = findDigitSum10(sum10); } return sum10; } private long value10(char a) { switch(a) { case 'A': return 1; case 'B': return 2; case 'C': return 3; case 'D': return 4; case 'E': return 5; case 'F': return 6; case 'G': return 7; case 'H': return 8; case 'I': return 9; case 'J': return 1; case 'K': return 2; case 'L': return 3; case 'M': return 4; case 'N': return 5; case 'O': return 6; case 'P': return 7; case 'Q': return 8; case 'R': return 9; case 'S': return 1; case 'T': return 2; case 'U': return 3; case 'V': return 4; case 'W': return 5; case 'X': return 6; case 'Y': return 7; case 'Z': return 8; default: return 0; } } private long findDigitSum10(long n) { int sum10=0; while (n != 0) { sum10 += n % 10; n = n / 10; } return sum10; } } 

ResultActivity.java

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.firstresult_xm); TextView txt1 = (TextView) findViewById (R.id.textView2); txt1.setText(getIntent().getStringExtra("name10")); } 
3
  • What encoding are you using in eclipse? Commented Nov 5, 2013 at 9:27
  • what encoding means...? Java Commented Nov 5, 2013 at 9:37
  • Project->Propeties-> Resources -> Text File Encoding -> choose UTF8 Commented Nov 5, 2013 at 9:39

2 Answers 2

5

you have no key sum10 inside your intent, but only name10. You should see the String int first TextView and nothing in the second one

Sign up to request clarification or add additional context in comments.

5 Comments

how it will give can u pls show and I edited it nw also not working
help me to understand, in your ResultActivty you are able to see the correct value for "name10", but not the one for sum10? Have I understand correctly?
No.. .. I am getting the result as 0; .... that is teh problem .. suppose if first name is black and second name belt then b=2,l=3,a=1,c=3,k=2 so total 12 then it has to make single digit so 2 + 1 = 3 and same for the second name b=2,e=5,l=3,t=2 so 2+5+1+2 = 10 so making it to one digit 1 + 0 = 1, and add first and last name together so 3 + 1 = 4 .. so answer is 4 and 4 has to be displayed.. but instead of that 0 is displaying every answer ... I gave default value as zero... when i changed it to 1 then instead of zero 5 is getting 4 + 1
I see. But your switch is only with upper case chars. The ascii number for uppercase and lowercase is different. Have you tried putting only uppercase chars inside your edittext? Also are you sure that the edittext contains something before you call the method value10?
there is no need to give the code in the edittext all caps. You can convert it to upper case with String.toUpperCase().
0

May be encoding in eclipse is different that Android? Try to change it to UTF-8 in propreties of project.

I tried such concole code. Your function of value10 works correctly.

public class HelloWorld { public static void main(String[] args) { HelloWorld hw = new HelloWorld(); long a = hw.value10('F'); System.out.println("val: " + a); } private long value10(char a) { // TODO Auto-generated method stub switch(a) { case 'A': return 1; case 'B': return 2; case 'C': return 3; case 'D': return 4; case 'E': return 5; case 'F': return 6; case 'G': return 7; case 'H': return 8; case 'I': return 9; case 'J': return 1; case 'K': return 2; case 'L': return 3; case 'M': return 4; case 'N': return 5; case 'O': return 6; case 'P': return 7; case 'Q': return 8; case 'R': return 9; case 'S': return 1; case 'T': return 2; case 'U': return 3; case 'V': return 4; case 'W': return 5; case 'X': return 6; case 'Y': return 7; case 'Z': return 8; default: return 0; } } } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.