我登錄活動給予
該文件的build.gradle下面給出如下:
package com.project.myproject;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class loginActivity extends AppCompatActivity {
Button login,forg,use;
EditText uid ,pass ;
TextView tv ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
login=(Button)findViewById(R.id.login);
forg=(Button)findViewById(R.id.forg);
use=(Button)findViewById(R.id.use);
uid=(EditText) findViewById(R.id.uid);
pass=(EditText) findViewById(R.id.pass);
tv=(TextView) findViewById(R.id.textView2);
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String u = uid.getText().toString();
String p = pass.getText().toString();
if(u.isEmpty()|| p.isEmpty())
{
tv.setText("PROVIDE VALUE");
tv.setTextColor(Color.RED);
tv.setTextSize(30);
}
else {
Intent i2=getIntent();
String type=i2.getStringExtra("type");
if (u.equals(p) && (type != "Faculty")) {
Intent i = new Intent(loginActivity.this, studentLoginActivity.class);
//i.putExtra("uid",u);
startActivity(i);
}
else if(u.equals(p) && (type != "Student")) {
Intent i = new Intent(loginActivity.this, facultyLoginActivity.class);
//i.putExtra("uid",u);
startActivity(i);
}
else {
tv.setText("Login Failed");
tv.setTextColor(Color.RED);
tv.setTextSize(30);
}
}
}
});
forg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i1=new Intent(loginActivity.this,forgetPasswordActivity.class);
startActivity(i1);
}
});
use.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i2=new Intent(loginActivity.this,newUserActivity.class);
startActivity(i2);
}
});
}
}
當我從登錄活動到新用戶的活動去那麼getslotfrombufferlocked發生以下我的新用戶活動代碼給出:
package com.project.myproject;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class newUserActivity extends AppCompatActivity {
private ProgressDialog pDialog;
JSONParser jsonParser = new JSONParser();
EditText uid, pass, ans, con;
Spinner sp1, sp2;
public String[] type = {"Select type", "Faculty", "Student"};
//String passw,cpass,answ,spin1,spin2;
//int id1;
private static String url_insertion = "http://localhost/insertion.php";
private static final String TAG_SUCCESS = "success";
Button reg;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_user);
Intent i2 = getIntent();
Intent i5 = new Intent(getApplicationContext(), loginActivity.class);
i5.putExtra("type", type);
//startActivity(i5);
uid = (EditText) findViewById(R.id.uid);
pass = (EditText) findViewById(R.id.pass);
ans = (EditText) findViewById(R.id.ans);
con = (EditText) findViewById(R.id.con);
sp1 = (Spinner) findViewById(R.id.spinner3);
sp2 = (Spinner) findViewById(R.id.spinner2);
Button reg = (Button) findViewById(R.id.reg);
String[] quest = {"Select Question", "What is your pet's name", "What is your favorite color", "What is the place do you like most", "Which is your favorite book"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, quest);
sp1.setAdapter(adapter);
sp1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (position == 0) {
} else {
Toast.makeText(newUserActivity.this, "You Have Selected" + sp1.getSelectedItem(), Toast.LENGTH_SHORT).show();
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, type);
sp2.setAdapter(adapter1);
sp2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (position == 0) {
} else {
Toast.makeText(newUserActivity.this, "You Have Selected" + sp2.getSelectedItem(), Toast.LENGTH_SHORT).show();
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
reg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
int ID = Integer.parseInt(uid.getText().toString());
String Password = pass.getText().toString();
String Question = sp1.getAdapter().toString();
String Answer = ans.getText().toString();
String Type = sp2.getAdapter().toString();
new BackgroundTask().execute(ID,Password,Question,Answer,Type);
}
});
}
class BackgroundTask extends AsyncTask<String, String, String> {
private ProgressDialog pDialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(newUserActivity.this);
pDialog.setMessage("Creating Account...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
@Override
protected String doInBackground(String... args){
String ID = String.valueOf(Integer.parseInt(args[0]));
String Password = args[1];
String Question = args[2];
String Answer = args[3];
String Type = args[4];
List<NameValuePair>params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("ID",ID));
params.add(new BasicNameValuePair("Password",Password));
params.add(new BasicNameValuePair("Question",Question));
params.add(new BasicNameValuePair("Answer",Answer));
params.add(new BasicNameValuePair("Type",Type));
JSONObject json = jsonParser.makeHttpRequest(url_insertion,"POST",params);
Log.d("Create Response",json.toString());
try{
int success = json.getInt(TAG_SUCCESS);
if(success==1) {
Intent i = new Intent(getApplicationContext(),loginActivity.class);
startActivity(i);
finish();
} else {
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {
pDialog.dismiss();
}
public void execute(int id, String password, String question, String answer, String type) {
}
}
}
請給我回答解決這個問題。
請爲您的主要活動添加代碼,以便我們可以檢查並提出可能的解決方案。另外,請確認您的設備正在運行「Android 6.0.1」或更高版本。 – ishmaelMakitla
我有Android 6.0而不是6.0.1,所以我該如何解決這個問題?我的主要活動如下: – A10
感謝您的更新 - 順便說一句,您應該將它添加到您的問題,而不是作爲答案發布。 – ishmaelMakitla