i'm creating a login application the login script is ok it's returned true and false
if the response returns true or 1, i want to make it to go to another activity called inputBarcode, the eclipse showing an error on my Intent line and i don't know what to do
i didn't know the other variations of making Intents
this is my full code, the Intent that i want to call is on the bottom after if(res.equals("1")){ :
package com.nigmagrid.go;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
//import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
public class login extends Activity {
String lokasiTugas;
boolean status_npp;
boolean status_password;
boolean status_lokasi;
Button button;
EditText usernameEditText, passwordEditText;
TextView error;
Spinner lokasiSpinner;
final int minNPP = 3;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.login);
final Button button = (Button) findViewById(R.id.login_button);
final EditText usernameEditText = (EditText) findViewById(R.id.login_npp);
final EditText passwordEditText = (EditText) findViewById(R.id.login_password);
final Spinner lokasiSpinner = (Spinner) findViewById(R.id.spinner1);
final TextView error = (TextView) findViewById(R.id.login_status);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.lokasi_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
lokasiSpinner.setAdapter(adapter);
lokasiSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView adapter, View v, int i, long lng) {
//Toast.makeText(getApplicationContext(), adapter.getItemAtPosition(i).toString(), Toast.LENGTH_SHORT).show();
lokasiTugas = adapter.getItemAtPosition(i).toString();
}
@Override
public void onNothingSelected(AdapterView arg0) {
//do something else
}
});
button.setOnClic开发者_如何学PythonkListener(new View.OnClickListener() {
public void onClick(View v) {
error.setText("Menghubungkan ke server...");
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("username", usernameEditText.getText().toString()));
postParameters.add(new BasicNameValuePair("password", passwordEditText.getText().toString()));
String response = null;
String sNPP = usernameEditText.getText().toString().replace(" ", "");
String sPassword = passwordEditText.getText().toString();
// validasi NPP
if(sNPP.length()<=minNPP){
usernameEditText.setError("NPP minimal "+minNPP+" angka");
status_npp = false;
}else{
status_npp = true;
//Toast.makeText(getApplicationContext(), "NPP Anda : "+sNPP, Toast.LENGTH_SHORT).show();
}
// validasi Password
if(sPassword.length()<1){
passwordEditText.setError("Kata sandi diperlukan");
status_password = false;
}else{
status_password = true;
}
//validasi lokasiTugas
if(lokasiTugas.equals("Pilih Lokasi")){
Toast.makeText(getApplicationContext(), "Lokasi Tugas diperlukan", Toast.LENGTH_SHORT).show();
status_lokasi = false;
}else{
status_lokasi = true;
}
// pengecekan akhir
if(status_npp == true && status_password == true && status_lokasi == true){
//Toast.makeText(getApplicationContext(), "NPP Anda : "+sNPP+"\nLokasi : "+lokasiTugas, Toast.LENGTH_SHORT).show();
//fungsi login disini :D
try{
// variabel cek-nya ganti
String cek = "http://almezuflash.zxq.net/kspt-android/ceklogin.php";
response = CustomHttpClient.excecuteHttpPost(cek, postParameters);
String res = response.toString();
res = res.replaceAll("\\s", "");
Toast.makeText(getApplicationContext(), res, Toast.LENGTH_SHORT).show();
if(res.equals("1")){
error.setText("Login sukses");
Toast.makeText(getApplicationContext(), "Login Sukses", Toast.LENGTH_SHORT).show();
// i want to make Intent but eclipse says error, and i don't know what to do
Intent doBarcode = new Intent(parent, inputBarcode.class);
startActivity(doBarcode);
}else{
error.setText("Login gagal");
//Toast.makeText(getApplicationContext(), "Login Gagal", Toast.LENGTH_SHORT).show();
}
}catch (Exception e){
//error.setText(e.toString());
error.setText("Terjadi kesalahan, silahkan periksa koneksi internet anda");
}
}else{
//Toast.makeText(getApplicationContext(), "Otorisasi Gagal", Toast.LENGTH_SHORT).show();
status_npp = false;
status_password = false;
status_lokasi = false;
error.setText("Login gagal, silahkan periksa kembali");
}
}
});
}
}
Sorry for my bad english, i'm from Indonesia fyi :D
Did you make sure to add the inputBarCode activity to your AndroidManifiest? If you did not, then that will give a runtime error. If thats no the problem, then possibly changing
Intent doBarcode = new Intent(parent, inputBarcode.class);
to
Intent doBarcode = new Intent(this, inputBarcode.class);
will solve your problem. I'm not familiar with the parent variable being used.
I hope that helps.
Try instead of
Intent doBarcode = new Intent(parent, inputBarcode.class);
use this code:
Intent doBarcode = new Intent(login.this, inputBarcode.class);
精彩评论