I’m using Android-Query for the first time and I understand that it (takes care of the asynchronous tasks for you?) and simplifies/reduces code writing. Correct me if I’m wrong about the asynchronous tasks.
Also, if I am wrong, please help me write the method below so it is on another thread; I cant get it to work either way I do it.
I’m getting the following NPE:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.andaero.app/com.andaero.app.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
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:787)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)at dalvik.system.NativeStart.main(Native Method)
--->Caused by: java.lang.NullPointerException
at com.andaero.app.utili.AsyncJSON.async_list_array(AsyncJSON.java:24)
at com.andaero.app.MainActivity.onCreate(MainActivity.java:84)
at android.app.Activity.performCreate(Activity.java:4465)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
Within my MainActivity:
import com.androidquery.AQuery;
import com.androidquery.callback.AjaxCallback;
import com.androidquery.callback.AjaxStatus;
...
AQuery aq;
String json = null;
public class MainActivity extends Activity implements AnimationLayout.Listener
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
...
AsyncJSON.async_list_array();
}
}
My AsyncJSON class:
public class AsyncJSON
{
static AQuery aq = null;
static JSONArray jArray;
String json = null;
public static void async_list_array()
{
String url = "http://192.168.1.34/Andaero/php/regulatory_list.php";
aq.ajax(url, JSONArray.class, new AjaxCallback<JSONArray>()
{
@Override
public void callback(String url, JSONArray json, AjaxStatus status)
{
if (json != null)
{
// successful ajax call, show status code, json content
//jsonListCallback(json);
Toast.makeText(aq.getContext(), status.getCode() + ":" + json.toString(), Toast.LENGTH_LONG).show();
} else
{
// ajax error, show error code
Toast.makeText(aq.getContext(), "Error:" + status.getCode(), Toast.LENGTH_LONG).show();
}
}
});
}
I took this code directly from their example but I cant see what I have wrong.
Thnx for your help.
It looks like you never initialized
aq, so it’s null.