问题描述
|
我正在创建一个登录应用程序
登录脚本正常,返回正确和错误
如果响应返回true或1,我想使其转到另一个名为inputBarcode的活动,则日食在我的Intent行上显示错误,我不知道该怎么办
我不知道制作意图的其他变化
这是我的完整代码,我要调用的Intent在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.setonClickListener(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\");
}
}
});
}
}
对不起,我的英语不好,我来自印度尼西亚。
解决方法
您是否确定将inputBarCode活动添加到AndroidManifiedt?如果您没有这样做,那么将给出运行时错误。如果那不是问题,那么可能会改变
Intent doBarcode = new Intent(parent,inputBarcode.class);
至
Intent doBarcode = new Intent(this,inputBarcode.class);
将解决您的问题。我不熟悉所使用的父变量。
希望对您有所帮助。
, 尝试代替
Intent doBarcode = new Intent(parent,inputBarcode.class);
使用此代码:
Intent doBarcode = new Intent(login.this,inputBarcode.class);