我第一次使用"http://code.google.com/p/android-query/" rel="nofollow">Android-Query ,我明白它(照顾你无序的任务?)和简化/减少代码的写法。如果我对无序的任务错了,请纠正我。
此外,如果我错了,请帮我写下下面的方法,这样它就会在另一条线上;无论我怎么做,我都不能让它工作。
我收到以下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)
在我的主要活动范围内:
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();
}
}
我的AsyncJSON班:
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();
}
}
});
}
我直接从他们的例子中取出了这个代码 但我看不出我有什么不对劲
麻烦你帮忙