响应无效 [英] Invalid response

查看:262
本文介绍了响应无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个例子链接<一个href=\"http://www.semurjengkol.com/populating-android-listview-with-json-based-data-fetched-from-mysql-server-using-php/,i\" rel=\"nofollow\">http://www.semurjengkol.com/populating-android-listview-with-json-based-data-fetched-from-mysql-server-using-php/,i尝试同样的事情,但我不能得到解决。

I am trying one example link http://www.semurjengkol.com/populating-android-listview-with-json-based-data-fetched-from-mysql-server-using-php/,i tried the same thing but i cant get the solution

activity_list_item.xml

activity_list_item.xml

<LinearLayout 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"
    tools:context=".MainActivity" >

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </ListView>

</LinearLayout>

Mainactivity.java

Mainactivity.java

public class MainActivity extends ListActivity implements FetchDataListener{
    private ProgressDialog dialog;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);       
            //setContentView(R.layout.activity_list_item);   
            initView();   
        }

        private void initView() {
            // show progress dialog
            dialog = ProgressDialog.show(this, "", "Loading...");

            String url = "http://10.0.2.2/test/apps.php";
            FetchDataTask task = new FetchDataTask(this);
            task.execute(url);
        }

        @Override
        public void onFetchComplete(List<Application> data) {
            // dismiss the progress dialog
            if(dialog != null)  dialog.dismiss();
            // create new adapter
            ApplicationAdapter adapter = new ApplicationAdapter(this, data);
            // set the adapter to list
            setListAdapter(adapter);        
        }

        @Override
        public void onFetchFailure(String msg) {
            // dismiss the progress dialog
            if(dialog != null)  dialog.dismiss();
            // show failure message
            Toast.makeText(this, msg, Toast.LENGTH_LONG).show();        
        }
    }

主要问题,我会在这里提到..

如果我注释掉setcontent视图不显示我还可以运行任何错误,但在其emulatore错误shwoing的无效响应

if i comment out the setcontent view not showing any error i can run also,but in emulatore its shwoing error of Invalid response

如果我没有注释掉临客logcat中这样表示误差

if i didnt comment out the linke logcat shows error like this

内容必须有一个ListView的id属性是'android.R.id.list

Content must have a ListView whose id attribute is 'android.R.id.list'

logcat的错误:

Logcat error:

5-17 11:30:30.649: E/AndroidRuntime(1177): FATAL EXCEPTION: main
05-17 11:30:30.649: E/AndroidRuntime(1177): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jsonandroid/com.example.jsonandroid.MainActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
05-17 11:30:30.649: E/AndroidRuntime(1177):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
05-17 11:30:30.649: E/AndroidRuntime(1177):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-17 11:30:30.649: E/AndroidRuntime(1177):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-17 11:30:30.649: E/AndroidRuntime(1177):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-17 11:30:30.649: E/AndroidRuntime(1177):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-17 11:30:30.649: E/AndroidRuntime(1177):     at android.os.Looper.loop(Looper.java:137)
05-17 11:30:30.649: E/AndroidRuntime(1177):     at android.app.ActivityThread.main(ActivityThread.java:5039)
05-17 11:30:30.649: E/AndroidRuntime(1177):     at java.lang.reflect.Method.invokeNative(Native Method)
05-17 11:30:30.649: E/AndroidRuntime(1177):     at java.lang.reflect.Method.invoke(Method.java:511)
05-17 11:30:30.649: E/AndroidRuntime(1177):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-17 11:30:30.649: E/AndroidRuntime(1177):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-17 11:30:30.649: E/AndroidRuntime(1177):     at dalvik.system.NativeStart.main(Native Method)
05-17 11:30:30.649: E/AndroidRuntime(1177): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
05-17 11:30:30.649: E/AndroidRuntime(1177):     at android.app.ListActivity.onContentChanged(ListActivity.java:243)
05-17 11:30:30.649: E/AndroidRuntime(1177):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:273)
05-17 11:30:30.649: E/AndroidRuntime(1177):     at android.app.Activity.setContentView(Activity.java:1881)
05-17 11:30:30.649: E/AndroidRuntime(1177):     at com.example.jsonandroid.MainActivity.onCreate(MainActivity.java:17)
05-17 11:30:30.649: E/AndroidRuntime(1177):     at android.app.Activity.performCreate(Activity.java:5104)
05-17 11:30:30.649: E/AndroidRuntime(1177):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-17 11:30:30.649: E/AndroidRuntime(1177):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
05-17 11:30:30.649: E/AndroidRuntime(1177):     ... 11 more

它可能是解决方案,这就是例子或URL问题

what it might be the solution,is this any problem in example or URL problem

推荐答案

该网址 http://10.0.2.2/test/apps.php 表示本地主机。你必须有你的PHP文件并运行PHP服务器成功执行客户端程序。

The URL http://10.0.2.2/test/apps.php indicates your localhost. you must have your php files and running php server to successfully execute the client program.

这篇关于响应无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆