我是 Android 新手,我正在开发一个应用程序,它从 QR 码获取一些信息,然后连接一个 php 页面。但是,应用程序在读取 QR 码后崩溃,并且 logCat 在我运行它时会给出致命异常 AsyncTask #1。
这是doInBackground()
代码:
class CreateNewProduct extends AsyncTask<String, String, String>
{
protected String doInBackground(String... args)
{
String tc= new String();
tc= "3123";
String no = new String();
no = "3";
/*String tcKimlik = "3123";
String hatNo = "3";*/
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("tc", tc));
params.add(new BasicNameValuePair("no", no ));
JSONObject json = jsonParser.makeHttpRequest(url_create_product, "POST", params);
try
{
int success = json.getInt(TAG_SUCCESS);
if (success == 1)
{
//qrCodeText.setText("DONE!");
}
else
{
//qrCodeText.setText("Nope...");
}
}
catch (JSONException e)
{
e.printStackTrace();
}
return null;
}
} // End of CreateNewProduct
CreateNewProduct
在另一个读取 QR 码的类中,我在读取 QR 码new CreateNewProduct().execute();
后调用它。
这是 LogCat:
更新:
在我添加http://
并setTexT()
作为评论后,JSON 错误被添加到 LogCat:
05-16 01:00:08.900: E/JSON Parser(11835): Error parsing data org.json.JSONException: Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject
05-16 01:00:08.900: W/dalvikvm(11835): threadid=14: thread exiting with uncaught exception (group=0x410572a0)
05-16 01:00:08.910: E/AndroidRuntime(11835): FATAL EXCEPTION: AsyncTask #1
05-16 01:00:08.910: E/AndroidRuntime(11835): java.lang.RuntimeException: An error occured while executing doInBackground()
05-16 01:00:08.910: E/AndroidRuntime(11835): at android.os.AsyncTask$3.done(AsyncTask.java:299)
05-16 01:00:08.910: E/AndroidRuntime(11835): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
05-16 01:00:08.910: E/AndroidRuntime(11835): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
05-16 01:00:08.910: E/AndroidRuntime(11835): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
05-16 01:00:08.910: E/AndroidRuntime(11835): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
05-16 01:00:08.910: E/AndroidRuntime(11835): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
05-16 01:00:08.910: E/AndroidRuntime(11835): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
05-16 01:00:08.910: E/AndroidRuntime(11835): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
05-16 01:00:08.910: E/AndroidRuntime(11835): at java.lang.Thread.run(Thread.java:856)
05-16 01:00:08.910: E/AndroidRuntime(11835): Caused by: java.lang.NullPointerException
05-16 01:00:08.910: E/AndroidRuntime(11835): at com.example.yoritreader.MainActivity$CreateNewProduct.doInBackground(MainActivity.java:442)
05-16 01:00:08.910: E/AndroidRuntime(11835): at com.example.yoritreader.MainActivity$CreateNewProduct.doInBackground(MainActivity.java:1)
05-16 01:00:08.910: E/AndroidRuntime(11835): at android.os.AsyncTask$2.call(AsyncTask.java:287)
05-16 01:00:08.910: E/AndroidRuntime(11835): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
05-16 01:00:08.910: E/AndroidRuntime(11835): ... 5 more
谢谢您的帮助!