Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9024687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:05:13+00:00 2026-06-16T06:05:13+00:00

I have a problem with my project here is my LoginActivity import java.util.ArrayList; import

  • 0

I have a problem with my project

here is my LoginActivity

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<NameValuePair> postParameters = new ArrayList<NameValuePair>();
                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;
    }
}

and here is my KirimInfo.java

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<String> aa = new ArrayAdapter<String>(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<String> bb = new ArrayAdapter<String>(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<NameValuePair> postParameters = new ArrayList<NameValuePair>();
                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;
        }
    }
}

I want to send the username from LoginActivity.java to KirimInfo.java. because that I make method “uname” to pass the username.

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)

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?

because I don’t know how to make a method and initiate object in android correctly

please tell me how….any help will appreciate

Thank You

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T06:05:14+00:00Added an answer on June 16, 2026 at 6:05 am

    LoginActivity l = new LoginActivity();
    String y = l.uname();

    This is not right procedure for sending value from one activity to Another activity.

    Add the following in your program.

    in LoginActivity.java add :..

    Whaen you call the KirimInfo.java Activity

    add

    Intent intent = new Intent(LoginActivity.this,KirimInfo.class);
    intent.putExtra("username",""+uname());
    

    in KirimInfo actrivity add the following

    Intent intent = getIntent();
    Bundle bundle = intent.getExtras();
    String userName = bundle.getString("username");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

everyone i have a problem with my project here is my search.java code import
I have a problem with my project, let me explain a moment here and
I have a problem with pip && setuptools. I have a simple project here:
I have problem adding entity framework model to my project. Here is what I
i have a problem on a project I'm working on. I have to create
I working on project and have problem with threading and update of UI. I
I have a problem with captcha in my YII project. I included a captcha
We have the problem that we have the open project files in our SVN
i have a problem to distributing application with 2 project (one project with sub-project
I have this problem getting my newly created php project on Netbeans work on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.