Hello guys am new to android but am having problem connection my android app to sqlServer using JSON..i load the emulator i get these errors when am invoking the authetication function..
07-20 20:55:48.871: D/AndroidRuntime(2082): Shutting down VM
07-20 20:55:48.872: E/AndroidRuntime(2082): FATAL EXCEPTION: main
07-20 20:55:48.872: E/AndroidRuntime(2082): Process: com.example.tropical, PID: 2082
07-20 20:55:48.872: E/AndroidRuntime(2082): java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference
07-20 20:55:48.872: E/AndroidRuntime(2082): at android.widget.Toast.<init>(Toast.java:101)
07-20 20:55:48.872: E/AndroidRuntime(2082): at android.widget.Toast.makeText(Toast.java:250)
07-20 20:55:48.872: E/AndroidRuntime(2082): at com.example.tropical.Login$AsyncLogin.onPreExecute(Login.java:87)
07-20 20:55:48.872: E/AndroidRuntime(2082): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:587)
07-20 20:55:48.872: E/AndroidRuntime(2082): at android.os.AsyncTask.execute(AsyncTask.java:535)
07-20 20:55:48.872: E/AndroidRuntime(2082): at com.example.tropical.Login$1.onClick(Login.java:49)
07-20 20:55:48.872: E/AndroidRuntime(2082): at android.view.View.performClick(View.java:4756)
07-20 20:55:48.872: E/AndroidRuntime(2082): at android.view.View$PerformClick.run(View.java:19749)
07-20 20:55:48.872: E/AndroidRuntime(2082): at android.os.Handler.handleCallback(Handler.java:739)
07-20 20:55:48.872: E/AndroidRuntime(2082): at android.os.Handler.dispatchMessage(Handler.java:95)
07-20 20:55:48.872: E/AndroidRuntime(2082): at android.os.Looper.loop(Looper.java:135)
07-20 20:55:48.872: E/AndroidRuntime(2082): at android.app.ActivityThread.main(ActivityThread.java:5221)
07-20 20:55:48.872: E/AndroidRuntime(2082): at java.lang.reflect.Method.invoke(Native Method)
07-20 20:55:48.872: E/AndroidRuntime(2082): at java.lang.reflect.Method.invoke(Method.java:372)
07-20 20:55:48.872: E/AndroidRuntime(2082): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
07-20 20:55:48.872: E/AndroidRuntime(2082): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
07-20 20:55:51.497: D/gralloc_goldfish(2101): Emulator without GPU emulation detected.
07-20 20:55:59.339: I/Choreographer(2101): Skipped 54 frames! The application may be doing too much work on its main thread.
And this is my code..
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
etUserName = (EditText) findViewById(R.id.txtUserID);
etPassword = (EditText) findViewById(R.id.txtpswd);
btnLogin = (Button) findViewById(R.id.btnlogin);
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String username=etUserName.getText().toString();
String password=etPassword.getText().toString();
AsyncLogin xx = new AsyncLogin();
xx.execute(username,password);
}
});
}
protected class AsyncLogin extends AsyncTask<string,> {
String userName=null;
@Override
protected Boolean doInBackground(String... params) {
RestAPI api = new RestAPI();
boolean userAuth = false;
try {
JSONObject jsonObj = api.UserAuthetication(params[0],
params[1]);
JSONParser parser = new JSONParser();
userAuth = parser.parseUserAuth(jsonObj);
userName=params[0];
} catch (Exception e) {
Log.d("AsyncLogin", e.getMessage());
}
return userAuth;
}
code in the JSONObject java class
public JSONObject UserAuthetication(String UserName,String Pin) throws Exception {
JSONObject result = null;
JSONObject o = new JSONObject();
JSONObject p = new JSONObject();
o.put("interface","RestAPI");
o.put("method", "UserAuthetication");
p.put("UserName",mapObject(UserName));
p.put("Pin",mapObject(Pin));
o.put("parameters", p);
String s = o.toString();
String r = load(s);
result = new JSONObject(r);
return result;
}