method didn't work in android
<p>I have a problem with my project</p>

<p>here is my LoginActivity</p>

<pre><code>import java.util.ArrayList;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class LoginActivity extends Activity {
    private final Context context = this;
    EditText un;
    EditText pw,ds;
    TextView error;
    String i;
    String x;   

    /** Called when the activity is first created. */

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
        un=(EditText)findViewById(R.id.un);
        pw=(EditText)findViewById(R.id.pwd);
        error=(TextView)findViewById(R.id.tv_error);
    }

    public void clickHandler(View view){
        Intent i = null;    
        switch (view.getId()){
            case R.id.btnLogin:
                ArrayList&lt;NameValuePair&gt; postParameters = new ArrayList&lt;NameValuePair&gt;();
                postParameters.add(new BasicNameValuePair("username", un.getText().toString()));
                postParameters.add(new BasicNameValuePair("password", pw.getText().toString()));
/*            String valid = "1";*/      
                String response = null;
                try {
                    response = CustomHttpClient.executeHttpPost("http://10.0.2.2/android/cek.php", postParameters);
                    String res = response.toString();
                    res = res.trim();
                    res = res.replaceAll("\\s+","");
                    error.setText(res);

                    if (res.equals("1")){
                        i = new Intent (this, Menu.class);
                        startActivity(i);
                    } else { 
                        error.setText("Sorry!! Username or Password salah");
                    }
                } catch (Exception e) {
                    un.setText(e.toString());
                }
                break;

            case R.id.registerBtn:
                i = new Intent(this, RegisterActivity.class);
                startActivity(i);
                break;

            case R.id.btnExit:
                AlertDialog.Builder builder = new AlertDialog.Builder(context);
                builder.setMessage("Keluar dari aplikasi ini?");
                builder.setCancelable(false);
                builder.setPositiveButton("Ya", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent intent = new Intent(Intent.ACTION_MAIN);
                        intent.addCategory(Intent.CATEGORY_HOME);
                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        startActivity(intent);
                        finish();
                    }
                });
                builder.setNegativeButton("Tidak", new DialogInterface.OnClickListener() {
                    @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    });
                // Create and show the dialog
                builder.show();
                break;
        }
    }
    public  String uname(){
        x = un.getText().toString();
        return x;
    }
}
</code></pre>

<p>and here is my KirimInfo.java</p>

<pre><code>import java.util.ArrayList;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.TimePicker;

public class KirimInfo extends Activity {

    String time,date,type,jln,y;
    EditText usrn,ket,ds;
    Spinner nj,st1;
    TextView error;
    String[] jalan = {"A.Yani","Ambengan", "Anjasmoro","Baliwerti","Basuki Rahmat","Bintoro","Ciliwung","Darmo Raya","Darmokali","Diponegoro Raya","Dharmawangsa","Dinoyo","Embong Kemiri","Embong Malang"};
    String[] stat = {"Macet Total", "Padat", "Padat Merayap","Padat Lancar","Lancar","Sepi"};
    /** Called when the activity is first created. */
    LoginActivity l = new LoginActivity();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.kirim_info);
        ket=(EditText)findViewById(R.id.keterangan);
        usrn=(EditText)findViewById(R.id.usrnm);
        error=(TextView)findViewById(R.id.tv_error3);
        nj=(Spinner)findViewById(R.id.namjal);
        ArrayAdapter&lt;String&gt; aa = new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_spinner_item, jalan);
        aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        nj.setAdapter(aa);
        st1=(Spinner)findViewById(R.id.statusKepadatan);
        ArrayAdapter&lt;String&gt; bb = new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_spinner_item, stat);
        aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        st1.setAdapter(bb);
    }

    public void clickHandler(View view){
        Intent i = null;
        switch (view.getId()){
            case R.id.btnKirimInfo:
                jln = jalan[nj.getSelectedItemPosition()];
                type = stat[st1.getSelectedItemPosition()];
                String y = l.uname();
                ArrayList&lt;NameValuePair&gt; postParameters = new ArrayList&lt;NameValuePair&gt;();
                postParameters.add(new BasicNameValuePair("username", y));
                postParameters.add(new BasicNameValuePair("nama_jalan", jln));
                postParameters.add(new BasicNameValuePair("keterangan", ket.getText().toString()));
                postParameters.add(new BasicNameValuePair("status", type));
/*            String valid = "1";*/      
                String response = null;
                try {
                    response = CustomHttpClient.executeHttpPost("http://10.0.2.2/android/kepadatan.php", postParameters);
                    String res = response.toString();
                    res = res.trim();
                    res = res.replaceAll("\\s+","");
                    error.setText(res);
                    if (res.equals("1")) 
                        error.setText("Data Berhasil Masuk");
                    else
                        error.setText("Gagal");
                } catch (Exception e) {
                    error.setText(e.toString());
                }
                break;
            case R.id.kembali:
                i = new Intent(this, Menu.class);
                startActivity(i);
                break;
        }
    }
}
</code></pre>

<p>I want to send the username from <code>LoginActivity.java</code> to <code>KirimInfo.java</code>. because that I make method "uname" to pass the username.</p>

<p>but when I run the program, it pass empty or NULL even though I have write the username (whereas I have write down username and password correctly from the database)</p>

<p>what I want to ask, am I write the method "uname" correct? can you tell me how to write a correct method and initiate object so I can pass the username?</p>

<p>because I don't know how to make a method and initiate object in android correctly</p>

<p>please tell me how....any help will appreciate</p>

<p>Thank You</p>
