有关如何将JSON成功解析为Textviews的任何想法
谢谢,
MainActivity.java
public class MainActivity extends Activity {
private static String url1 = "http://54.218.73.244:7002/RestaurantTimings";
private HashMap<Integer, String> contentsMap = new HashMap<Integer, String>();
ProgressDialog progressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//instantiating progressDialog
progressDialog=new ProgressDialog(MainActivity.this);
new ParsingAsync().execute();
}
private class ParsingAsync extends AsyncTask<Void, Void, Void>{
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
progressDialog=ProgressDialog.show(MainActivity.this, "", "Please Wait .. ", true, false);
}
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
JSONObjParser jParser=new JSONObjParser();
JSONArray json1=jParser.getJSONFromUrl(url1);
try{
for(int i=0;i<json1.length();i++){
JSONObject c=json1.getJSONObject(i);
int id = c.getInt("_id");
String TIME = c.getString("RestaurantTime");
contentsMap.put(id,TIME);
}
}catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
progressDialog.dismiss();
TextView TV1=(TextView) findViewById(R.id.restaurantTimings1);
TV1.setText(contentsMap.get(1));
TextView TV2=(TextView) findViewById(R.id.restaurantTimings2);
TV1.setText(contentsMap.get(2));
TextView TV3=(TextView) findViewById(R.id.restaurantTimings3);
TV1.setText(contentsMap.get(3));
}
}
}
登录
08-20 20:40:21.642: W/System.err(482): java.net.SocketException: Permission denied
08-20 20:40:21.642: W/System.err(482): at org.apache.harmony.luni.platform.OSNetworkSystem.socket(Native Method)
08-20 20:40:21.652: W/System.err(482): at dalvik.system.BlockGuard$WrappedNetworkSystem.socket(BlockGuard.java:335)
08-20 20:40:21.652: W/System.err(482): at org.apache.harmony.luni.net.PlainSocketImpl.create(PlainSocketImpl.java:216)
08-20 20:40:21.652: W/System.err(482): at java.net.Socket.checkOpenAndCreate(Socket.java:802)
08-20 20:40:21.652: W/System.err(482): at java.net.Socket.connect(Socket.java:948)
08-20 20:40:21.662: W/System.err(482): at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
08-20 20:40:21.662: W/System.err(482): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:143)
08-20 20:40:21.662: W/System.err(482): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
08-20 20:40:21.662: W/System.err(482): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
08-20 20:40:21.662: W/System.err(482): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:359)
08-20 20:40:21.662: W/System.err(482): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
08-20 20:40:21.662: W/System.err(482): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
08-20 20:40:21.682: W/System.err(482): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
08-20 20:40:21.692: W/System.err(482): at com.example.simpleasynctask.JSONObjParser.getJSONFromUrl(JSONObjParser.java:40)
08-20 20:40:21.692: W/System.err(482): at com.example.simpleasynctask.MainActivity$ParsingAsync.doInBackground(MainActivity.java:50)
08-20 20:40:21.692: W/System.err(482): at com.example.simpleasynctask.MainActivity$ParsingAsync.doInBackground(MainActivity.java:1)
08-20 20:40:21.692: W/System.err(482): at android.os.AsyncTask$2.call(AsyncTask.java:185)
08-20 20:40:21.692: W/System.err(482): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
08-20 20:40:21.692: W/System.err(482): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
08-20 20:40:21.702: W/System.err(482): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
08-20 20:40:21.702: W/System.err(482): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
08-20 20:40:21.702: W/System.err(482): at java.lang.Thread.run(Thread.java:1019)
08-20 20:40:21.712: E/Buffer Error(482): Error converting result java.lang.NullPointerException
08-20 20:40:21.712: E/JSON Parser(482): Error parsing data org.json.JSONException: End of input at character 0 of
08-20 20:40:21.722: W/dalvikvm(482): threadid=9: thread exiting with uncaught exception (group=0x40015560)
08-20 20:40:21.732: E/AndroidRuntime(482): FATAL EXCEPTION: AsyncTask #1
08-20 20:40:21.732: E/AndroidRuntime(482): java.lang.RuntimeException: An error occured while executing doInBackground()
08-20 20:40:21.732: E/AndroidRuntime(482): at android.os.AsyncTask$3.done(AsyncTask.java:200)
08-20 20:40:21.732: E/AndroidRuntime(482): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
08-20 20:40:21.732: E/AndroidRuntime(482): at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
08-20 20:40:21.732: E/AndroidRuntime(482): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
08-20 20:40:21.732: E/AndroidRuntime(482): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
08-20 20:40:21.732: E/AndroidRuntime(482): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
08-20 20:40:21.732: E/AndroidRuntime(482): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
08-20 20:40:21.732: E/AndroidRuntime(482): at java.lang.Thread.run(Thread.java:1019)
08-20 20:40:21.732: E/AndroidRuntime(482): Caused by: java.lang.NullPointerException
08-20 20:40:21.732: E/AndroidRuntime(482): at com.example.simpleasynctask.MainActivity$ParsingAsync.doInBackground(MainActivity.java:53)
08-20 20:40:21.732: E/AndroidRuntime(482): at com.example.simpleasynctask.MainActivity$ParsingAsync.doInBackground(MainActivity.java:1)
08-20 20:40:21.732: E/AndroidRuntime(482): at android.os.AsyncTask$2.call(AsyncTask.java:185)
08-20 20:40:21.732: E/AndroidRuntime(482): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
08-20 20:40:21.732: E/AndroidRuntime(482): ... 4 more
08-20 20:40:22.722: E/WindowManager(482): Activity com.example.simpleasynctask.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4051e148 that was originally added here
08-20 20:40:22.722: E/WindowManager(482): android.view.WindowLeaked: Activity com.example.simpleasynctask.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4051e148 that was originally added here
08-20 20:40:22.722: E/WindowManager(482): at android.view.ViewRoot.<init>(ViewRoot.java:258)
08-20 20:40:22.722: E/WindowManager(482): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
08-20 20:40:22.722: E/WindowManager(482): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
08-20 20:40:22.722: E/WindowManager(482): at android.view.Window$LocalWindowManager.addView(Window.java:424)
08-20 20:40:22.722: E/WindowManager(482): at android.app.Dialog.show(Dialog.java:241)
08-20 20:40:22.722: E/WindowManager(482): at android.app.ProgressDialog.show(ProgressDialog.java:107)
08-20 20:40:22.722: E/WindowManager(482): at android.app.ProgressDialog.show(ProgressDialog.java:95)
08-20 20:40:22.722: E/WindowManager(482): at com.example.simpleasynctask.MainActivity$ParsingAsync.onPreExecute(MainActivity.java:43)
08-20 20:40:22.722: E/WindowManager(482): at android.os.AsyncTask.execute(AsyncTask.java:391)
08-20 20:40:22.722: E/WindowManager(482): at com.example.simpleasynctask.MainActivity.onCreate(MainActivity.java:34)
08-20 20:40:22.722: E/WindowManager(482): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-20 20:40:22.722: E/WindowManager(482): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-20 20:40:22.722: E/WindowManager(482): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-20 20:40:22.722: E/WindowManager(482): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-20 20:40:22.722: E/WindowManager(482): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-20 20:40:22.722: E/WindowManager(482): at android.os.Handler.dispatchMessage(Handler.java:99)
08-20 20:40:22.722: E/WindowManager(482): at android.os.Looper.loop(Looper.java:123)
08-20 20:40:22.722: E/WindowManager(482): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-20 20:40:22.722: E/WindowManager(482): at java.lang.reflect.Method.invokeNative(Native Method)
08-20 20:40:22.722: E/WindowManager(482): at java.lang.reflect.Method.invoke(Method.java:507)
08-20 20:40:22.722: E/WindowManager(482): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-20 20:40:22.722: E/WindowManager(482): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-20 20:40:22.722: E/WindowManager(482): at dalvik.system.NativeStart.main(Native Method)
08-20 20:45:21.996: I/Process(482): Sending signal. PID: 482 SIG: 9
08-20 20:47:11.752: W/System.err(519): java.net.SocketException: Permission denied
08-20 20:47:11.772: W/System.err(519): at org.apache.harmony.luni.platform.OSNetworkSystem.socket(Native Method)
08-20 20:47:11.782: W/System.err(519): at dalvik.system.BlockGuard$WrappedNetworkSystem.socket(BlockGuard.java:335)
08-20 20:47:11.782: W/System.err(519): at org.apache.harmony.luni.net.PlainSocketImpl.create(PlainSocketImpl.java:216)
08-20 20:47:11.782: W/System.err(519): at java.net.Socket.checkOpenAndCreate(Socket.java:802)
08-20 20:47:11.782: W/System.err(519): at java.net.Socket.connect(Socket.java:948)
08-20 20:47:11.782: W/System.err(519): at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
08-20 20:47:11.782: W/System.err(519): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:143)
08-20 20:47:11.782: W/System.err(519): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
08-20 20:47:11.792: W/System.err(519): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
08-20 20:47:11.792: W/System.err(519): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:359)
08-20 20:47:11.803: W/System.err(519): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
08-20 20:47:11.803: W/System.err(519): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
08-20 20:47:11.803: W/System.err(519): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
08-20 20:47:11.803: W/System.err(519): at com.example.simpleasynctask.JSONObjParser.getJSONFromUrl(JSONObjParser.java:40)
08-20 20:47:11.812: W/System.err(519): at com.example.simpleasynctask.MainActivity$ParsingAsync.doInBackground(MainActivity.java:50)
08-20 20:47:11.812: W/System.err(519): at com.example.simpleasynctask.MainActivity$ParsingAsync.doInBackground(MainActivity.java:1)
08-20 20:47:11.812: W/System.err(519): at android.os.AsyncTask$2.call(AsyncTask.java:185)
08-20 20:47:11.853: W/System.err(519): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
08-20 20:47:11.853: W/System.err(519): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
08-20 20:47:11.853: W/System.err(519): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
08-20 20:47:11.853: W/System.err(519): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
08-20 20:47:11.862: W/System.err(519): at java.lang.Thread.run(Thread.java:1019)
08-20 20:47:11.862: E/Buffer Error(519): Error converting result java.lang.NullPointerException
08-20 20:47:11.892: E/JSON Parser(519): Error parsing data org.json.JSONException: End of input at character 0 of
08-20 20:47:11.904: W/dalvikvm(519): threadid=9: thread exiting with uncaught exception (group=0x40015560)
08-20 20:47:11.912: E/AndroidRuntime(519): FATAL EXCEPTION: AsyncTask #1
08-20 20:47:11.912: E/AndroidRuntime(519): java.lang.RuntimeException: An error occured while executing doInBackground()
08-20 20:47:11.912: E/AndroidRuntime(519): at android.os.AsyncTask$3.done(AsyncTask.java:200)
08-20 20:47:11.912: E/AndroidRuntime(519): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
08-20 20:47:11.912: E/AndroidRuntime(519): at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
08-20 20:47:11.912: E/AndroidRuntime(519): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
08-20 20:47:11.912: E/AndroidRuntime(519): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
08-20 20:47:11.912: E/AndroidRuntime(519): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
08-20 20:47:11.912: E/AndroidRuntime(519): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
08-20 20:47:11.912: E/AndroidRuntime(519): at java.lang.Thread.run(Thread.java:1019)
08-20 20:47:11.912: E/AndroidRuntime(519): Caused by: java.lang.NullPointerException
08-20 20:47:11.912: E/AndroidRuntime(519): at com.example.simpleasynctask.MainActivity$ParsingAsync.doInBackground(MainActivity.java:53)
08-20 20:47:11.912: E/AndroidRuntime(519): at com.example.simpleasynctask.MainActivity$ParsingAsync.doInBackground(MainActivity.java:1)
08-20 20:47:11.912: E/AndroidRuntime(519): at android.os.AsyncTask$2.call(AsyncTask.java:185)
08-20 20:47:11.912: E/AndroidRuntime(519): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
08-20 20:47:11.912: E/AndroidRuntime(519): ... 4 more
08-20 20:47:14.072: E/WindowManager(519): Activity com.example.simpleasynctask.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4051e498 that was originally added here
08-20 20:47:14.072: E/WindowManager(519): android.view.WindowLeaked: Activity com.example.simpleasynctask.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4051e498 that was originally added here
08-20 20:47:14.072: E/WindowManager(519): at android.view.ViewRoot.<init>(ViewRoot.java:258)
08-20 20:47:14.072: E/WindowManager(519): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
08-20 20:47:14.072: E/WindowManager(519): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
08-20 20:47:14.072: E/WindowManager(519): at android.view.Window$LocalWindowManager.addView(Window.java:424)
08-20 20:47:14.072: E/WindowManager(519): at android.app.Dialog.show(Dialog.java:241)
08-20 20:47:14.072: E/WindowManager(519): at android.app.ProgressDialog.show(ProgressDialog.java:107)
08-20 20:47:14.072: E/WindowManager(519): at android.app.ProgressDialog.show(ProgressDialog.java:95)
08-20 20:47:14.072: E/WindowManager(519): at com.example.simpleasynctask.MainActivity$ParsingAsync.onPreExecute(MainActivity.java:43)
08-20 20:47:14.072: E/WindowManager(519): at android.os.AsyncTask.execute(AsyncTask.java:391)
08-20 20:47:14.072: E/WindowManager(519): at com.example.simpleasynctask.MainActivity.onCreate(MainActivity.java:34)
08-20 20:47:14.072: E/WindowManager(519): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-20 20:47:14.072: E/WindowManager(519): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-20 20:47:14.072: E/WindowManager(519): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-20 20:47:14.072: E/WindowManager(519): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-20 20:47:14.072: E/WindowManager(519): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-20 20:47:14.072: E/WindowManager(519): at android.os.Handler.dispatchMessage(Handler.java:99)
08-20 20:47:14.072: E/WindowManager(519): at android.os.Looper.loop(Looper.java:123)
08-20 20:47:14.072: E/WindowManager(519): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-20 20:47:14.072: E/WindowManager(519): at java.lang.reflect.Method.invokeNative(Native Method)
08-20 20:47:14.072: E/WindowManager(519): at java.lang.reflect.Method.invoke(Method.java:507)
08-20 20:47:14.072: E/WindowManager(519): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-20 20:47:14.072: E/WindowManager(519): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-20 20:47:14.072: E/WindowManager(519): at dalvik.system.NativeStart.main(Native Method)
08-20 20:49:38.402: W/System.err(555): java.net.SocketException: Permission denied
08-20 20:49:38.434: W/System.err(555): at org.apache.harmony.luni.platform.OSNetworkSystem.socket(Native Method)
08-20 20:49:38.452: W/System.err(555): at dalvik.system.BlockGuard$WrappedNetworkSystem.socket(BlockGuard.java:335)
08-20 20:49:38.452: W/System.err(555): at org.apache.harmony.luni.net.PlainSocketImpl.create(PlainSocketImpl.java:216)
08-20 20:49:38.452: W/System.err(555): at java.net.Socket.checkOpenAndCreate(Socket.java:802)
08-20 20:49:38.452: W/System.err(555): at java.net.Socket.connect(Socket.java:948)
08-20 20:49:38.452: W/System.err(555): at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
08-20 20:49:38.452: W/System.err(555): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:143)
08-20 20:49:38.477: W/System.err(555): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
08-20 20:49:38.482: W/System.err(555): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
08-20 20:49:38.482: W/System.err(555): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:359)
08-20 20:49:38.482: W/System.err(555): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
08-20 20:49:38.482: W/System.err(555): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
08-20 20:49:38.492: W/System.err(555): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
08-20 20:49:38.492: W/System.err(555): at com.example.simpleasynctask.JSONObjParser.getJSONFromUrl(JSONObjParser.java:40)
08-20 20:49:38.502: W/System.err(555): at com.example.simpleasynctask.MainActivity$ParsingAsync.doInBackground(MainActivity.java:50)
08-20 20:49:38.522: W/System.err(555): at com.example.simpleasynctask.MainActivity$ParsingAsync.doInBackground(MainActivity.java:1)
08-20 20:49:38.522: W/System.err(555): at android.os.AsyncTask$2.call(AsyncTask.java:185)
08-20 20:49:38.532: W/System.err(555): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
08-20 20:49:38.542: W/System.err(555): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
08-20 20:49:38.542: W/System.err(555): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
08-20 20:49:38.552: W/System.err(555): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
08-20 20:49:38.552: W/System.err(555): at java.lang.Thread.run(Thread.java:1019)
08-20 20:49:38.563: E/Buffer Error(555): Error converting result java.lang.NullPointerException
08-20 20:49:38.582: E/JSON Parser(555): Error parsing data org.json.JSONException: End of input at character 0 of
08-20 20:49:38.632: W/dalvikvm(555): threadid=9: thread exiting with uncaught exception (group=0x40015560)
08-20 20:49:38.642: E/AndroidRuntime(555): FATAL EXCEPTION: AsyncTask #1
08-20 20:49:38.642: E/AndroidRuntime(555): java.lang.RuntimeException: An error occured while executing doInBackground()
08-20 20:49:38.642: E/AndroidRuntime(555): at android.os.AsyncTask$3.done(AsyncTask.java:200)
08-20 20:49:38.642: E/AndroidRuntime(555): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
08-20 20:49:38.642: E/AndroidRuntime(555): at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
08-20 20:49:38.642: E/AndroidRuntime(555): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
08-20 20:49:38.642: E/AndroidRuntime(555): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
08-20 20:49:38.642: E/AndroidRuntime(555): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
08-20 20:49:38.642: E/AndroidRuntime(555): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
08-20 20:49:38.642: E/AndroidRuntime(555): at java.lang.Thread.run(Thread.java:1019)
08-20 20:49:38.642: E/AndroidRuntime(555): Caused by: java.lang.NullPointerException
08-20 20:49:38.642: E/AndroidRuntime(555): at com.example.simpleasynctask.MainActivity$ParsingAsync.doInBackground(MainActivity.java:53)
08-20 20:49:38.642: E/AndroidRuntime(555): at com.example.simpleasynctask.MainActivity$ParsingAsync.doInBackground(MainActivity.java:1)
08-20 20:49:38.642: E/AndroidRuntime(555): at android.os.AsyncTask$2.call(AsyncTask.java:185)
08-20 20:49:38.642: E/AndroidRuntime(555): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
08-20 20:49:38.642: E/AndroidRuntime(555): ... 4 more
08-20 20:49:40.662: E/WindowManager(555): Activity com.example.simpleasynctask.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4051e7f0 that was originally added here
08-20 20:49:40.662: E/WindowManager(555): android.view.WindowLeaked: Activity com.example.simpleasynctask.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4051e7f0 that was originally added here
08-20 20:49:40.662: E/WindowManager(555): at android.view.ViewRoot.<init>(ViewRoot.java:258)
08-20 20:49:40.662: E/WindowManager(555): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
08-20 20:49:40.662: E/WindowManager(555): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
08-20 20:49:40.662: E/WindowManager(555): at android.view.Window$LocalWindowManager.addView(Window.java:424)
08-20 20:49:40.662: E/WindowManager(555): at android.app.Dialog.show(Dialog.java:241)
08-20 20:49:40.662: E/WindowManager(555): at android.app.ProgressDialog.show(ProgressDialog.java:107)
08-20 20:49:40.662: E/WindowManager(555): at android.app.ProgressDialog.show(ProgressDialog.java:95)
08-20 20:49:40.662: E/WindowManager(555): at com.example.simpleasynctask.MainActivity$ParsingAsync.onPreExecute(MainActivity.java:43)
08-20 20:49:40.662: E/WindowManager(555): at android.os.AsyncTask.execute(AsyncTask.java:391)
08-20 20:49:40.662: E/WindowManager(555): at com.example.simpleasynctask.MainActivity.onCreate(MainActivity.java:34)
08-20 20:49:40.662: E/WindowManager(555): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-20 20:49:40.662: E/WindowManager(555): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-20 20:49:40.662: E/WindowManager(555): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-20 20:49:40.662: E/WindowManager(555): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-20 20:49:40.662: E/WindowManager(555): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-20 20:49:40.662: E/WindowManager(555): at android.os.Handler.dispatchMessage(Handler.java:99)
08-20 20:49:40.662: E/WindowManager(555): at android.os.Looper.loop(Looper.java:123)
08-20 20:49:40.662: E/WindowManager(555): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-20 20:49:40.662: E/WindowManager(555): at java.lang.reflect.Method.invokeNative(Native Method)
08-20 20:49:40.662: E/WindowManager(555): at java.lang.reflect.Method.invoke(Method.java:507)
08-20 20:49:40.662: E/WindowManager(555): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-20 20:49:40.662: E/WindowManager(555): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-20 20:49:40.662: E/WindowManager(555): at dalvik.system.NativeStart.main(Native Method)
更新 添加互联网权限后
错误日志中没有错误
但是我无法填充剩余的两个文本视图
activity_main.xml中
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/restaurantTimings1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="TextView" />
<TextView
android:id="@+id/restaurantTimings2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView2"
android:layout_centerHorizontal="true"
android:layout_marginTop="133dp"
android:text="TextView" />
<TextView
android:id="@+id/restaurantTimings3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/restaurantTimings2"
android:layout_alignLeft="@+id/restaurantTimings2"
android:layout_marginBottom="68dp"
android:text="TextView" />
</RelativeLayout>
答案 0 :(得分:0)
首先,
从您的日志: - java.net.SocketException: Permission denied
它
清除你没有添加互联网权限,所以你必须添加
<uses-permission android:name="android.permission.INTERNET"/>
in
您的清单文件
其次
你没有将textTxt设置为你的其他TextView
..请参阅下面的代码,..
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
progressDialog.dismiss();
TextView TV1=(TextView) findViewById(R.id.restaurantTimings1);
TV1.setText(contentsMap.get(1));
TextView TV2=(TextView) findViewById(R.id.restaurantTimings2);
TV2.setText(contentsMap.get(2));//Here........
TextView TV3=(TextView) findViewById(R.id.restaurantTimings3);
TV3.setText(contentsMap.get(3));//Here.........
}