i'm trying to do a login code but for now i'm trying to check the response by getting a message that its sucessful but instead it keeps saying that the app has stopped
the main layout code :
public class newjava extends Activity {
private EditText mUsernameET ;
private EditText mPasswordET ;
private Button mSigninBtn ;
private JSONParser jsonParser= new JSONParser();
private String LOGIN_URL = "10.0.2.2:1234/noura/login.php";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.newlayout);
mUsernameET=(EditText) findViewById(R.id.first);
mPasswordET=(EditText) findViewById(R.id.second);
mSigninBtn=(Button) findViewById(R.id.button);
mSigninBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
fields();
}
});
mUsernameET.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId== EditorInfo.IME_ACTION_NEXT || actionId== EditorInfo.IME_ACTION_DONE)
{
mPasswordET.requestFocus();
}
return false;
}
});
Toast.makeText(getApplicationContext(),"onCreate",Toast.LENGTH_SHORT).show();
}
private void fields()
{
String username = mUsernameET.getText().toString();
String password = mPasswordET.getText().toString();
if (TextUtils.isEmpty(username))
{
mUsernameET.setError(" this field is required ");
}
else if (TextUtils.isEmpty(password))
{
mPasswordET.setError(" this field is required ");
}
new login(username,password).execute();
}
private class login extends AsyncTask<Void,Void,Boolean>
{
private ProgressDialog progress;
private JSONObject result = null;
private String username ;
private String password ;
private login(String username, String password) {
this.username = username;
this.password = password;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
progress=progress.show(getApplicationContext(),
"Processing ..", "Checking username and password", false , false
);
}
@Override
protected Boolean doInBackground(Void... params) {
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("user_name",username));
pairs.add(new BasicNameValuePair("password",password));
result = jsonParser.makeHttpRequest(LOGIN_URL,pairs);
try
{
if (result.getInt("success") == 1)
{
Log.e("result",result + "");
return true;}
}
catch (Exception ex )
{
}
return false;
}
}
@Override
protected void onStart() {
super.onStart();
Toast.makeText(getApplicationContext(),"onStart",Toast.LENGTH_SHORT).show();
}
@Override
protected void onResume() {
super.onResume();
Toast.makeText(getApplicationContext(),"onResume",Toast.LENGTH_SHORT).show();
}
@Override
protected void onPause() {
super.onPause();
Toast.makeText(getApplicationContext(),"onPause",Toast.LENGTH_SHORT).show();
}
@Override
protected void onStop() {
super.onStop();
Toast.makeText(getApplicationContext(),"onStop",Toast.LENGTH_SHORT).show();
}
@Override
protected void onRestart() {
super.onRestart();
Toast.makeText(getApplicationContext(),"onRestart",Toast.LENGTH_SHORT).show();
}
@Override
protected void onDestroy() {
super.onDestroy();
Toast.makeText(getApplicationContext(),"onDestroy",Toast.LENGTH_SHORT).show();
}
}
i dont have a program that reads php files i used notepad to open and edit ready ones , could that be the problem ? what program can i use ?
04-18 14:03:17.469 641-647/noura.hello I/dalvikvm﹕ threadid=3: reacting to signal 3
04-18 14:03:17.669 641-647/noura.hello I/dalvikvm﹕ Wrote stack traces to '/data/anr/traces.txt'
04-18 14:03:17.948 641-647/noura.hello I/dalvikvm﹕ threadid=3: reacting to signal 3
04-18 14:03:17.968 641-647/noura.hello I/dalvikvm﹕ Wrote stack traces to '/data/anr/traces.txt'
04-18 14:03:18.298 641-645/noura.hello D/dalvikvm﹕ GC_CONCURRENT freed 83K, 3% free 6837K/7047K, paused 4ms+3ms
04-18 14:03:18.479 641-647/noura.hello I/dalvikvm﹕ threadid=3: reacting to signal 3
04-18 14:03:18.519 641-647/noura.hello I/dalvikvm﹕ Wrote stack traces to '/data/anr/traces.txt'
04-18 14:03:18.749 641-641/noura.hello D/gralloc_goldfish﹕ Emulator without GPU emulation detected.
04-18 14:03:18.929 641-647/noura.hello I/dalvikvm﹕ threadid=3: reacting to signal 3
04-18 14:03:18.949 641-647/noura.hello I/dalvikvm﹕ Wrote stack traces to '/data/anr/traces.txt'
04-18 14:03:39.559 641-641/noura.hello D/AndroidRuntime﹕ Shutting down VM
04-18 14:03:39.559 641-641/noura.hello W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x2ba041f8)
04-18 14:03:39.619 641-641/noura.hello E/AndroidRuntime﹕ FATAL EXCEPTION: main
android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
at android.view.ViewRootImpl.setView(ViewRootImpl.java:517)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:301)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)
at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140)
at android.app.Dialog.show(Dialog.java:278)
at android.app.ProgressDialog.show(ProgressDialog.java:116)
at android.app.ProgressDialog.show(ProgressDialog.java:104)
at noura.hello.Activity.newjava$login.onPreExecute(newjava.java:96)
at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:561)
at android.os.AsyncTask.execute(AsyncTask.java:511)
at noura.hello.Activity.newjava.fields(newjava.java:77)
at noura.hello.Activity.newjava.access$000(newjava.java:31)
at noura.hello.Activity.newjava$1.onClick(newjava.java:48)
at android.view.View.performClick(View.java:3512)
at android.view.View$PerformClick.run(View.java:14106)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
04-18 14:03:40.639 641-647/noura.hello I/dalvikvm﹕ threadid=3: reacting to signal 3
04-18 14:03:40.689 641-647/noura.hello I/dalvikvm﹕ Wrote stack traces to '/data/anr/traces.txt'
04-18 14:03:44.338 641-641/noura.hello I/Process﹕ Sending signal. PID: 641 SIG: 9
Aucun commentaire:
Enregistrer un commentaire