Unable to call methods of a java class from the activity classs
<p>i am making an sms application where the user types in the contact and the message and then clicks the button butenc. The button has to send the variable phone number and message to another java class where a method receives the data and manipulates it. The Ecc java file is a standalone java class that is linked to various other java classes for operations on the message. I some times get a stackoverflow error and when i manipulate a few things in the code, the application runs and when i click the enc button nothing happens but when i click the send button the message is sent. I am sure i am having a problem in passing the variable to the Ecc class. I went through various questions here on OS but none of them solve the issue. The changes i make give either of the problems i mentioned above. Can some one suggest me how do i get over this problem? Bin on it since a week. </p>

<p>SMSTest.java(main android activity)</p>

<pre><code>package com.example.smsTest;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;


@TargetApi(Build.VERSION_CODES.DONUT)
@SuppressLint("NewApi")
public class SMSTest extends Activity 
{
    public final static String SMS_Message = "com.example.SMSTest.MESSAGE";
public final static String SMS_Phone = "com.example.SMSTest.MESSAGE";
Button btnSendSMS;
Button btnEnc;
EditText txtPhoneNo;
EditText txtMessage;
</code></pre>

<p>Ecc ecc; </p>

<pre><code>/** Called when the activity is first created. */

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);        
    btnSendSMS = (Button) findViewById(R.id.btnSendSMS);
    btnEnc = (Button) findViewById(R.id.btnEnc);
    txtPhoneNo = (EditText) findViewById(R.id.txtPhoneNo);
    txtMessage = (EditText) findViewById(R.id.txtMessage);

    ecc=new Ecc(this);

    /*
    Intent sendIntent = new Intent(Intent.ACTION_VIEW);
    sendIntent.putExtra("sms_body", "Content of the SMS goes here..."); 
    sendIntent.setType("vnd.android-dir/mms-sms");
    startActivity(sendIntent);
    */

    btnEnc.setOnClickListener(new View.OnClickListener() 
    {
        public void onClick(View v) 
        {               
            String phoneNo = txtPhoneNo.getText().toString(); 
            String message = txtMessage.getText().toString();
            if (phoneNo.length()&gt;0 &amp;&amp; message.length()&gt;0){
                System.out.println("details verified");
                ecc.recv(phoneNo, message);    
                Toast.makeText(getBaseContext(), 
                    "Ecc started", 
                    Toast.LENGTH_SHORT).show();
            }
        });

    btnSendSMS.setOnClickListener(new View.OnClickListener() 
    {
        public void onClick(View v) 
        {               
            String phoneNo = txtPhoneNo.getText().toString(); 
            String message = txtMessage.getText().toString();               
            if (phoneNo.length()&gt;0 &amp;&amp; message.length()&gt;0)                
                sendSMS(phoneNo, message);
            else
                Toast.makeText(getBaseContext(), 
                    "Please enter both phone number and message.", 
                    Toast.LENGTH_SHORT).show();
        }
    });        
}

//---sends a SMS message to another device---
@TargetApi(Build.VERSION_CODES.DONUT)
@SuppressLint("NewApi")    
public void sendSMS(String phoneNumber, String message)
{      
    /*
    PendingIntent pi = PendingIntent.getActivity(this, 0,
            new Intent(this, test.class), 0);                
        SmsManager sms = SmsManager.getDefault();
        sms.sendTextMessage(phoneNumber, null, message, pi, null);        
    */

    String SENT = "SMS_SENT";
    String DELIVERED = "SMS_DELIVERED";

    PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
        new Intent(SENT), 0);

    PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
        new Intent(DELIVERED), 0);

    //---when the SMS has been sent---
    registerReceiver(new BroadcastReceiver(){
        @Override
        public void onReceive(Context arg0, Intent arg1) {
            switch (getResultCode())
            {
                case Activity.RESULT_OK:
                    Toast.makeText(getBaseContext(), "SMS sent", 
                            Toast.LENGTH_SHORT).show();
                    break;
                case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                    Toast.makeText(getBaseContext(), "Generic      failure", 
                            Toast.LENGTH_SHORT).show();
                    break;
                case SmsManager.RESULT_ERROR_NO_SERVICE:
                    Toast.makeText(getBaseContext(), "No service", 
                            Toast.LENGTH_SHORT).show();
                    break;
                case SmsManager.RESULT_ERROR_NULL_PDU:
                    Toast.makeText(getBaseContext(), "Null PDU", 
                            Toast.LENGTH_SHORT).show();
                    break;
                case SmsManager.RESULT_ERROR_RADIO_OFF:
                    Toast.makeText(getBaseContext(), "Radio off", 
                            Toast.LENGTH_SHORT).show();
                    break;
            }
        }
    }, new IntentFilter(SENT));

    //---when the SMS has been delivered---
    registerReceiver(new BroadcastReceiver(){
        @TargetApi(Build.VERSION_CODES.DONUT)
        @SuppressLint("NewApi")
        @Override
        public void onReceive(Context arg0, Intent arg1) {
            switch (getResultCode())
            {
                case Activity.RESULT_OK:
                    Toast.makeText(getBaseContext(), "SMS delivered", 
                            Toast.LENGTH_SHORT).show();
                    break;
                case Activity.RESULT_CANCELED:
                    Toast.makeText(getBaseContext(), "SMS not delivered", 
                            Toast.LENGTH_SHORT).show();
                            break;                  
            }
        }
    },new IntentFilter(DELIVERED));        

    SmsManager sms = SmsManager.getDefault();
    sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);               
    }  
}
</code></pre>

<p>Here my other class (Ecc.java)</p>

<pre><code>package com.example.smsTest;
import java.util.*;
public class Ecc{

//code
private SMSTest smsTest;


// Constructor
public Ecc(SMSTest smsTest) {
    this.smsTest = smsTest;
}


public void recv(String phn, String smsg){

/*performs manipulation on phn and msg taken 
from the main activity using various other 
java files linked with it and again sends it 
back to themaina ctivities sendSMS method*/
smsTest.sendSMS(pnh,smsg)
}

//code
}
</code></pre>

<p>my main.xml file</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
&gt;
&lt;TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Enter the phone number of recipient"
    /&gt;     
&lt;EditText 
    android:id="@+id/txtPhoneNo"  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"        
    /&gt;
&lt;TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"         
    android:text="Message"
    /&gt;     
&lt;EditText 
    android:id="@+id/txtMessage"  
    android:layout_width="fill_parent" 
    android:layout_height="150px"
    android:gravity="top"         
    /&gt;

&lt;Button
    android:id="@+id/btnEnc"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Ecc" /&gt;

&lt;Button 
    android:id="@+id/btnSendSMS"  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:text="Send SMS"
    /&gt;

&lt;/LinearLayout&gt;
</code></pre>

<p>when i click send button the message is being sent but when i click ecc the ecc class load start... </p>

<p>here is my logcat</p>

<pre><code>02-26 13:04:36.337: W/Trace(1265): Unexpected value from nativeGetEnabledTags: 0
02-26 13:04:36.447: W/Trace(1265): Unexpected value from nativeGetEnabledTags: 0
02-26 13:04:36.447: W/Trace(1265): Unexpected value from nativeGetEnabledTags: 0
02-26 13:04:36.797: W/Trace(1265): Unexpected value from nativeGetEnabledTags: 0
02-26 13:04:36.797: W/Trace(1265): Unexpected value from nativeGetEnabledTags: 0
02-26 13:04:37.077: W/Trace(1265): Unexpected value from nativeGetEnabledTags: 0
02-26 13:04:37.117: W/Trace(1265): Unexpected value from nativeGetEnabledTags: 0
02-26 13:04:37.247: W/Trace(1265): Unexpected value from nativeGetEnabledTags: 0
02-26 13:04:37.247: W/Trace(1265): Unexpected value from nativeGetEnabledTags: 0
02-26 13:04:37.318: W/Trace(1265): Unexpected value from nativeGetEnabledTags: 0
02-26 13:04:37.391: I/Choreographer(1265): Skipped 74 frames!  The application may be doing too much work on its main thread.
02-26 13:04:37.416: W/Trace(1265): Unexpected value from nativeGetEnabledTags: 0
02-26 13:04:37.416: W/Trace(1265): Unexpected value from nativeGetEnabledTags: 0
02-26 13:04:37.427: W/Trace(1265): Unexpected value from nativeGetEnabledTags: 0
02-26 13:04:37.427: W/Trace(1265): Unexpected value from nativeGetEnabledTags: 0
02-26 13:04:37.437: W/Trace(1265): Unexpected value from nativeGetEnabledTags: 0
02-26 13:04:37.447: W/Trace(1265): Unexpected value from nativeGetEnabledTags: 0
</code></pre>
