在Android App上运行PHP

时间:2014-07-02 15:15:51

标签: php android

我试图制作一个简单的Android应用程序,它在屏幕上显示一个简单的字符串,来自实际网址上的php脚本。不幸的是,我一直得到这个经典的信息"不幸的是,你好已经停止"在尝试了很多方法之后。

这是myActivity.java:

package com.example.scoelli.hello;

import ...


public class MyActivity extends Activity {

    TextView txtHelloWorld;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);


        txtHelloWorld = (TextView) findViewById(R.id.txthelloworld);
        new ConnectTask().execute();
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.my, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    private class ConnectTask extends AsyncTask<Void, Void, HttpResponse> {
        protected HttpResponse doInBackground(Void... params) {
            String url = "http://www.scoelli.ewwoconsulting.com/hello/";
            HttpClient httpclient = new DefaultHttpClient();
            try {
                HttpGet request = new HttpGet(new URI(url));
                request.addHeader("User-Agent", "Android");
                HttpResponse response = httpclient.execute(request);
                return response;
            }catch (URISyntaxException e1) {
                e1.printStackTrace();
            } catch (IOException ioe){
                ioe.printStackTrace();
            }
            return null;
        }

        protected void onPostExecute(HttpResponse result) {
            String resultado = "NOO";
            StatusLine statusLine = result.getStatusLine();
            try {
                if (statusLine.getStatusCode() == HttpStatus.SC_OK) {
                    ByteArrayOutputStream out = new ByteArrayOutputStream();
                    result.getEntity().writeTo(out);
                    out.close();
                    resultado = out.toString();
                }
            } catch (IOException ioe){
                ioe.printStackTrace();
            }
            txtHelloWorld.setText(resultado);
        }
    }
}

这是我的PHP脚本:

<?php
namespace Controller;

Class Hello
{
    static function World()
    {
        echo "Hola Mundo!";
    }
}
?>

我有一个调用静态函数World的控制器;我知道php有效。

除非我使用Android Studio,否则我不知道是否有任何更改。

这是Logcat:

...
07-02 15:54:28.532      381-629/? I/PackageManager﹕ Action: "android.intent.action.SENDTO"
07-02 15:54:28.532      381-629/? I/PackageManager﹕ Category: "android.intent.category.DEFAULT"
07-02 15:54:28.532      381-629/? I/PackageManager﹕ Adding preferred activity ComponentInfo{com.android.mms/com.android.mms.ui.ComposeMessageActivity} for user 0 :
07-02 15:54:28.542      381-629/? I/PackageManager﹕ Scheme: "sms"
07-02 15:54:28.592      381-385/? D/dalvikvm﹕ GC_CONCURRENT freed 1072K, 16% free 6185K/7344K, paused 49ms+9ms, total 216ms
07-02 15:54:28.592      381-629/? D/dalvikvm﹕ WAIT_FOR_CONCURRENT_GC blocked 49ms
07-02 15:54:28.672      381-392/? I/ActivityManager﹕ Delay finish: com.android.keychain/.KeyChainBroadcastReceiver
07-02 15:54:28.712      381-614/? I/PackageManager﹕ Action: "android.intent.action.SENDTO"
07-02 15:54:28.712      381-614/? I/PackageManager﹕ Category: "android.intent.category.DEFAULT"
07-02 15:54:28.712      381-614/? I/PackageManager﹕ Adding preferred activity ComponentInfo{com.android.mms/com.android.mms.ui.ComposeMessageActivity} for user 0 :
07-02 15:54:28.722      381-614/? I/PackageManager﹕ Scheme: "smsto"
07-02 15:54:28.772      381-613/? I/PackageManager﹕ Action: "android.intent.action.SENDTO"
07-02 15:54:28.772      381-613/? I/PackageManager﹕ Category: "android.intent.category.DEFAULT"
07-02 15:54:28.772      381-613/? I/PackageManager﹕ Scheme: "mms"
07-02 15:54:28.772      381-613/? I/PackageManager﹕ Adding preferred activity ComponentInfo{com.android.mms/com.android.mms.ui.ComposeMessageActivity} for user 0 :
07-02 15:54:28.822      381-560/? I/PackageManager﹕ Action: "android.intent.action.SENDTO"
07-02 15:54:28.822      381-560/? I/PackageManager﹕ Category: "android.intent.category.DEFAULT"
07-02 15:54:28.822      381-560/? I/PackageManager﹕ Adding preferred activity ComponentInfo{com.android.mms/com.android.mms.ui.ComposeMessageActivity} for user 0 :
07-02 15:54:28.832      381-560/? I/PackageManager﹕ Scheme: "mmsto"
07-02 15:54:28.912      517-526/? D/dalvikvm﹕ GC_CONCURRENT freed 394K, 15% free 3338K/3924K, paused 25ms+4ms, total 102ms
07-02 15:54:28.932      517-517/? D/dalvikvm﹕ WAIT_FOR_CONCURRENT_GC blocked 22ms
07-02 15:54:29.122      381-628/? I/PackageManager﹕ Adding preferred activity ComponentInfo{com.android.mms/com.android.mms.ui.ComposeMessageActivity} for user 0 :
07-02 15:54:29.132      381-628/? I/PackageManager﹕ Action: "android.intent.action.SENDTO"
07-02 15:54:29.142      381-628/? I/PackageManager﹕ Category: "android.intent.category.DEFAULT"
07-02 15:54:29.142      381-628/? I/PackageManager﹕ Scheme: "sms"
07-02 15:54:29.192      381-410/? I/InputReader﹕ Reconfiguring input devices.  changes=0x00000010
07-02 15:54:29.222      381-561/? I/PackageManager﹕ Adding preferred activity ComponentInfo{com.android.mms/com.android.mms.ui.ComposeMessageActivity} for user 0 :
07-02 15:54:29.232      381-561/? I/PackageManager﹕ Action: "android.intent.action.SENDTO"
07-02 15:54:29.232      381-561/? I/PackageManager﹕ Category: "android.intent.category.DEFAULT"
07-02 15:54:29.232      381-561/? I/PackageManager﹕ Scheme: "smsto"
07-02 15:54:29.242      381-381/? D/BackupManagerService﹕ Received broadcast Intent { act=android.intent.action.PACKAGE_ADDED dat=package:com.example.scoelli.hello flg=0x4000010 (has extras) }
07-02 15:54:29.252      381-381/? V/BackupManagerService﹕ removePackageParticipantsLocked: uid=10052 #1
07-02 15:54:29.292      381-381/? V/BackupManagerService﹕ addPackageParticipantsLocked: #1
07-02 15:54:29.342      381-629/? I/PackageManager﹕ Action: "android.intent.action.SENDTO"
07-02 15:54:29.342      381-629/? I/PackageManager﹕ Category: "android.intent.category.DEFAULT"
07-02 15:54:29.342      381-629/? I/PackageManager﹕ Scheme: "mms"
07-02 15:54:29.342      381-629/? I/PackageManager﹕ Adding preferred activity ComponentInfo{com.android.mms/com.android.mms.ui.ComposeMessageActivity} for user 0 :
07-02 15:54:29.452      381-626/? I/PackageManager﹕ Action: "android.intent.action.SENDTO"
07-02 15:54:29.452      381-626/? I/PackageManager﹕ Category: "android.intent.category.DEFAULT"
07-02 15:54:29.452      381-626/? I/PackageManager﹕ Scheme: "mmsto"
07-02 15:54:29.452      381-626/? I/PackageManager﹕ Adding preferred activity ComponentInfo{com.android.mms/com.android.mms.ui.ComposeMessageActivity} for user 0 :
07-02 15:54:29.552      381-613/? I/PackageManager﹕ Action: "android.intent.action.SENDTO"
07-02 15:54:29.552      381-613/? I/PackageManager﹕ Category: "android.intent.category.DEFAULT"
07-02 15:54:29.552      381-613/? I/PackageManager﹕ Adding preferred activity ComponentInfo{com.android.mms/com.android.mms.ui.ComposeMessageActivity} for user 0 :
07-02 15:54:29.562      381-613/? I/PackageManager﹕ Scheme: "sms"
07-02 15:54:29.722      381-385/? D/dalvikvm﹕ GC_CONCURRENT freed 887K, 16% free 6173K/7344K, paused 27ms+8ms, total 253ms
07-02 15:54:29.722      381-613/? D/dalvikvm﹕ WAIT_FOR_CONCURRENT_GC blocked 162ms
07-02 15:54:29.872      517-517/? D/dalvikvm﹕ GC_FOR_ALLOC freed 396K, 15% free 3336K/3924K, paused 90ms, total 91ms
07-02 15:54:29.922      381-614/? I/PackageManager﹕ Action: "android.intent.action.SENDTO"
07-02 15:54:29.922      381-614/? I/PackageManager﹕ Category: "android.intent.category.DEFAULT"
07-02 15:54:29.922      381-614/? I/PackageManager﹕ Adding preferred activity ComponentInfo{com.android.mms/com.android.mms.ui.ComposeMessageActivity} for user 0 :
07-02 15:54:29.932      381-614/? I/PackageManager﹕ Scheme: "smsto"
07-02 15:54:30.002      381-625/? I/PackageManager﹕ Action: "android.intent.action.SENDTO"
07-02 15:54:30.002      381-625/? I/PackageManager﹕ Category: "android.intent.category.DEFAULT"
07-02 15:54:30.002      381-625/? I/PackageManager﹕ Scheme: "mms"
07-02 15:54:30.002      381-625/? I/PackageManager﹕ Adding preferred activity ComponentInfo{com.android.mms/com.android.mms.ui.ComposeMessageActivity} for user 0 :
07-02 15:54:30.042      517-526/? D/dalvikvm﹕ GC_CONCURRENT freed 91K, 15% free 3343K/3924K, paused 21ms+13ms, total 167ms
07-02 15:54:30.112      381-393/? I/PackageManager﹕ Action: "android.intent.action.SENDTO"
07-02 15:54:30.112      381-393/? I/PackageManager﹕ Category: "android.intent.category.DEFAULT"
07-02 15:54:30.112      381-393/? I/PackageManager﹕ Scheme: "mmsto"
07-02 15:54:30.112      381-393/? I/PackageManager﹕ Adding preferred activity ComponentInfo{com.android.mms/com.android.mms.ui.ComposeMessageActivity} for user 0 :
07-02 15:54:30.222      381-632/? I/PackageManager﹕ Adding preferred activity ComponentInfo{com.android.mms/com.android.mms.ui.ComposeMessageActivity} for user 0 :
07-02 15:54:30.232      381-632/? I/PackageManager﹕ Action: "android.intent.action.SENDTO"
07-02 15:54:30.232      381-632/? I/PackageManager﹕ Category: "android.intent.category.DEFAULT"
07-02 15:54:30.232      381-632/? I/PackageManager﹕ Scheme: "sms"
07-02 15:54:30.292      381-613/? I/PackageManager﹕ Action: "android.intent.action.SENDTO"
07-02 15:54:30.292      381-613/? I/PackageManager﹕ Category: "android.intent.category.DEFAULT"
07-02 15:54:30.292      381-613/? I/PackageManager﹕ Scheme: "smsto"
07-02 15:54:30.292      381-613/? I/PackageManager﹕ Adding preferred activity ComponentInfo{com.android.mms/com.android.mms.ui.ComposeMessageActivity} for user 0 :
07-02 15:54:30.352      381-551/? I/PackageManager﹕ Action: "android.intent.action.SENDTO"
07-02 15:54:30.352      381-551/? I/PackageManager﹕ Category: "android.intent.category.DEFAULT"
07-02 15:54:30.352      381-551/? I/PackageManager﹕ Scheme: "mms"
07-02 15:54:30.352      381-551/? I/PackageManager﹕ Adding preferred activity ComponentInfo{com.android.mms/com.android.mms.ui.ComposeMessageActivity} for user 0 :
07-02 15:54:30.362      381-673/? D/LightsService﹕ Excessive delay setting light: 695ms
07-02 15:54:30.442      381-393/? I/PackageManager﹕ Action: "android.intent.action.SENDTO"
07-02 15:54:30.442      381-393/? I/PackageManager﹕ Category: "android.intent.category.DEFAULT"
07-02 15:54:30.442      381-393/? I/PackageManager﹕ Adding preferred activity ComponentInfo{com.android.mms/com.android.mms.ui.ComposeMessageActivity} for user 0 :
07-02 15:54:30.452      381-393/? I/PackageManager﹕ Scheme: "mmsto"
07-02 15:54:30.572      517-517/? D/dalvikvm﹕ GC_FOR_ALLOC freed 412K, 16% free 3331K/3924K, paused 79ms, total 80ms
07-02 15:54:30.612      381-613/? I/PackageManager﹕ Adding preferred activity ComponentInfo{com.android.mms/com.android.mms.ui.ComposeMessageActivity} for user 0 :
07-02 15:54:30.622      381-613/? I/PackageManager﹕ Action: "android.intent.action.SENDTO"
07-02 15:54:30.622      381-613/? I/PackageManager﹕ Category: "android.intent.category.DEFAULT"
07-02 15:54:30.622      381-613/? I/PackageManager﹕ Scheme: "sms"
07-02 15:54:30.712      517-526/? D/dalvikvm﹕ GC_CONCURRENT freed 49K, 14% free 3413K/3924K, paused 23ms+32ms, total 138ms
07-02 15:54:30.722      381-554/? I/PackageManager﹕ Action: "android.intent.action.SENDTO"
07-02 15:54:30.722      381-554/? I/PackageManager﹕ Category: "android.intent.category.DEFAULT"
07-02 15:54:30.722      381-554/? I/PackageManager﹕ Adding preferred activity ComponentInfo{com.android.mms/com.android.mms.ui.ComposeMessageActivity} for user 0 :
07-02 15:54:30.732      381-554/? I/PackageManager﹕ Scheme: "smsto"
07-02 15:54:30.792      381-673/? D/LightsService﹕ Excessive delay setting light: 422ms
07-02 15:54:30.832      381-554/? D/dalvikvm﹕ GC_FOR_ALLOC freed 897K, 17% free 6148K/7344K, paused 96ms, total 97ms
07-02 15:54:30.922      381-467/? I/PackageManager﹕ Action: "android.intent.action.SENDTO"
07-02 15:54:30.922      381-467/? I/PackageManager﹕ Category: "android.intent.category.DEFAULT"
07-02 15:54:30.922      381-467/? I/PackageManager﹕ Scheme: "mms"
07-02 15:54:30.922      381-467/? I/PackageManager﹕ Adding preferred activity ComponentInfo{com.android.mms/com.android.mms.ui.ComposeMessageActivity} for user 0 :
07-02 15:54:31.032      381-628/? I/PackageManager﹕ Action: "android.intent.action.SENDTO"
07-02 15:54:31.032      381-628/? I/PackageManager﹕ Category: "android.intent.category.DEFAULT"
07-02 15:54:31.032      381-628/? I/PackageManager﹕ Scheme: "mmsto"
07-02 15:54:31.032      381-628/? I/PackageManager﹕ Adding preferred activity ComponentInfo{com.android.mms/com.android.mms.ui.ComposeMessageActivity} for user 0 :
07-02 15:54:31.072      381-385/? D/dalvikvm﹕ GC_CONCURRENT freed 216K, 16% free 6188K/7344K, paused 20ms+20ms, total 238ms
07-02 15:54:31.072      381-397/? D/dalvikvm﹕ WAIT_FOR_CONCURRENT_GC blocked 1413ms
07-02 15:54:31.162      536-536/? I/Choreographer﹕ Skipped 117 frames!  The application may be doing too much work on its main thread.
07-02 15:54:31.372      381-541/? I/ActivityManager﹕ Resuming delayed broadcast
07-02 15:54:31.422      381-410/? I/InputReader﹕ Reconfiguring input devices.  changes=0x00000010
07-02 15:54:31.772      536-542/? D/dalvikvm﹕ GC_CONCURRENT freed 423K, 42% free 4894K/8328K, paused 13ms+10ms, total 83ms
07-02 15:54:32.132      381-404/? D/dalvikvm﹕ GC_EXPLICIT freed 168K, 16% free 6169K/7344K, paused 63ms+20ms, total 713ms
07-02 15:54:32.172    1671-1671/? D/AndroidRuntime﹕ Shutting down VM
07-02 15:54:32.212    1671-1675/? D/dalvikvm﹕ GC_CONCURRENT freed 95K, 16% free 560K/660K, paused 1ms+2ms, total 25ms
07-02 15:54:32.312      381-397/? W/RecognitionManagerService﹕ no available voice recognition services found for user 0
07-02 15:54:33.082    1686-1686/? D/AndroidRuntime﹕ >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
07-02 15:54:33.092    1686-1686/? D/AndroidRuntime﹕ CheckJNI is ON
07-02 15:54:33.182    1686-1686/? D/dalvikvm﹕ Trying to load lib libjavacore.so 0x0
07-02 15:54:33.202    1686-1686/? D/dalvikvm﹕ Added shared lib libjavacore.so 0x0
07-02 15:54:33.222    1686-1686/? D/dalvikvm﹕ Trying to load lib libnativehelper.so 0x0
07-02 15:54:33.222    1686-1686/? D/dalvikvm﹕ Added shared lib libnativehelper.so 0x0
07-02 15:54:33.222    1686-1686/? D/dalvikvm﹕ No JNI_OnLoad found in libnativehelper.so 0x0, skipping init
07-02 15:54:33.472    1686-1686/? D/dalvikvm﹕ Note: class Landroid/app/ActivityManagerNative; has 179 unimplemented (abstract) methods
07-02 15:54:34.222    1686-1686/? E/memtrack﹕ Couldn't load memtrack module (No such file or directory)
07-02 15:54:34.222    1686-1686/? E/android.os.Debug﹕ failed to load memtrack module: -2
07-02 15:54:34.592    1686-1686/? D/AndroidRuntime﹕ Calling main entry com.android.commands.am.Am
07-02 15:54:34.682      381-393/? I/ActivityManager﹕ START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.scoelli.hello/.MyActivity} from pid 1686
07-02 15:54:34.762        49-78/? E/gralloc_goldfish﹕ gralloc_alloc: Mismatched usage flags: 343 x 201, usage 333
07-02 15:54:34.762        49-78/? W/GraphicBufferAllocator﹕ alloc(343, 201, 1, 00000333, ...) failed -22 (Invalid argument)
07-02 15:54:34.762        49-78/? E/﹕ GraphicBufferAlloc::createGraphicBuffer(w=343, h=201) failed (Invalid argument), handle=0x0
07-02 15:54:34.772      381-393/? E/BufferQueue﹕ [ScreenshotClient] dequeueBuffer: SurfaceComposer::createGraphicBuffer failed
07-02 15:54:34.772      381-393/? W/WindowManager﹕ Screenshot failure taking screenshot for (343x201) to layer 21005
07-02 15:54:34.802    1686-1686/? D/AndroidRuntime﹕ Shutting down VM
07-02 15:54:34.862    1686-1690/? D/dalvikvm﹕ GC_CONCURRENT freed 96K, 15% free 586K/684K, paused 1ms+2ms, total 23ms
07-02 15:54:34.922      381-560/? I/ActivityManager﹕ Start proc com.example.scoelli.hello for activity com.example.scoelli.hello/.MyActivity: pid=1696 uid=10052 gids={50052, 3003}
07-02 15:54:34.982    1696-1696/? D/dalvikvm﹕ Not late-enabling CheckJNI (already on)
07-02 15:54:36.342    1696-1696/? D/﹕ HostConnection::get() New Host Connection established 0xb8ef1e38, tid 1696
07-02 15:54:36.472    1696-1696/? W/EGL_emulation﹕ eglSurfaceAttrib not implemented
07-02 15:54:36.472    1696-1696/? D/OpenGLRenderer﹕ Enabling debug mode 0
07-02 15:54:36.722      536-536/? I/Choreographer﹕ Skipped 31 frames!  The application may be doing too much work on its main thread.
07-02 15:54:36.772      381-395/? I/ActivityManager﹕ Displayed com.example.scoelli.hello/.MyActivity: +1s972ms
07-02 15:54:37.352    1696-1709/? W/System.err﹕ java.net.UnknownHostException: Unable to resolve host "www.scoelli.ewwoconsulting.com": No address associated with hostname
07-02 15:54:37.372    1696-1709/? W/System.err﹕ at java.net.InetAddress.lookupHostByName(InetAddress.java:424)
07-02 15:54:37.372    1696-1709/? W/System.err﹕ at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
07-02 15:54:37.372    1696-1709/? W/System.err﹕ at java.net.InetAddress.getAllByName(InetAddress.java:214)
07-02 15:54:37.372    1696-1709/? W/System.err﹕ at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
07-02 15:54:37.402    1696-1700/? D/dalvikvm﹕ GC_CONCURRENT freed 183K, 9% free 2915K/3172K, paused 5ms+3ms, total 79ms
07-02 15:54:37.412    1696-1709/? W/System.err﹕ at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
07-02 15:54:37.412    1696-1709/? W/System.err﹕ at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
07-02 15:54:37.412    1696-1709/? W/System.err﹕ at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
07-02 15:54:37.412    1696-1709/? W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
07-02 15:54:37.412    1696-1709/? W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
07-02 15:54:37.412    1696-1709/? W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
07-02 15:54:37.412    1696-1709/? W/System.err﹕ at com.example.scoelli.hello.MyActivity$ConnectTask.doInBackground(MyActivity.java:132)
07-02 15:54:37.412    1696-1709/? W/System.err﹕ at com.example.scoelli.hello.MyActivity$ConnectTask.doInBackground(MyActivity.java:125)
07-02 15:54:37.412    1696-1709/? W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:288)
07-02 15:54:37.412    1696-1709/? W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:237)
07-02 15:54:37.412    1696-1709/? W/System.err﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
07-02 15:54:37.412    1696-1709/? W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
07-02 15:54:37.432    1696-1709/? W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
07-02 15:54:37.432    1696-1709/? W/System.err﹕ at java.lang.Thread.run(Thread.java:841)
07-02 15:54:37.442    1696-1709/? W/System.err﹕ Caused by: libcore.io.GaiException: getaddrinfo failed: EAI_NODATA (No address associated with hostname)
07-02 15:54:37.442    1696-1709/? W/System.err﹕ at libcore.io.Posix.getaddrinfo(Native Method)
07-02 15:54:37.442    1696-1709/? W/System.err﹕ at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:61)
07-02 15:54:37.452    1696-1709/? W/System.err﹕ at java.net.InetAddress.lookupHostByName(InetAddress.java:405)
07-02 15:54:37.452    1696-1709/? W/System.err﹕ ... 17 more
07-02 15:54:37.452    1696-1696/? D/AndroidRuntime﹕ Shutting down VM
07-02 15:54:37.452    1696-1696/? W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb2a71ba8)
07-02 15:54:37.472    1696-1696/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.scoelli.hello, PID: 1696
java.lang.NullPointerException
        at com.example.scoelli.hello.MyActivity$ConnectTask.onPostExecute(MyActivity.java:144)
        at com.example.scoelli.hello.MyActivity$ConnectTask.onPostExecute(MyActivity.java:125)
        at android.os.AsyncTask.finish(AsyncTask.java:632)
        at android.os.AsyncTask.access$600(AsyncTask.java:177)
        at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5017)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
        at dalvik.system.NativeStart.main(Native Method)
07-02 15:54:37.502      381-551/? W/ActivityManager﹕ Force finishing activity com.example.scoelli.hello/.MyActivity
07-02 15:54:37.532       49-122/? E/gralloc_goldfish﹕ gralloc_alloc: Mismatched usage flags: 343 x 201, usage 333
07-02 15:54:37.532       49-122/? W/GraphicBufferAllocator﹕ alloc(343, 201, 1, 00000333, ...) failed -22 (Invalid argument)
07-02 15:54:37.532       49-122/? E/﹕ GraphicBufferAlloc::createGraphicBuffer(w=343, h=201) failed (Invalid argument), handle=0x0
07-02 15:54:37.542      381-551/? E/BufferQueue﹕ [ScreenshotClient] dequeueBuffer: SurfaceComposer::createGraphicBuffer failed
07-02 15:54:37.542      381-551/? W/WindowManager﹕ Screenshot failure taking screenshot for (343x201) to layer 21010
07-02 15:54:38.052      381-396/? W/ActivityManager﹕ Activity pause timeout for ActivityRecord{b2f080d8 u0 com.example.scoelli.hello/.MyActivity t14 f}
07-02 15:54:38.472      536-536/? W/EGL_emulation﹕ eglSurfaceAttrib not implemented
07-02 15:54:40.402    1696-1696/? I/Process﹕ Sending signal. PID: 1696 SIG: 9
07-02 15:54:40.452      381-426/? E/SoundPool﹕ error loading /system/media/audio/ui/Effect_Tick.ogg
07-02 15:54:40.452      381-426/? W/AudioService﹕ Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
07-02 15:54:40.452      381-426/? E/SoundPool﹕ error loading /system/media/audio/ui/Effect_Tick.ogg
07-02 15:54:40.462      381-426/? W/AudioService﹕ Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
07-02 15:54:40.462      381-426/? E/SoundPool﹕ error loading /system/media/audio/ui/Effect_Tick.ogg
07-02 15:54:40.462      381-426/? W/AudioService﹕ Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
07-02 15:54:40.472      381-426/? E/SoundPool﹕ error loading /system/media/audio/ui/Effect_Tick.ogg
07-02 15:54:40.472      381-426/? W/AudioService﹕ Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
07-02 15:54:40.472      381-426/? E/SoundPool﹕ error loading /system/media/audio/ui/Effect_Tick.ogg
07-02 15:54:40.472      381-426/? W/AudioService﹕ Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
07-02 15:54:40.472      381-426/? E/SoundPool﹕ error loading /system/media/audio/ui/KeypressStandard.ogg
07-02 15:54:40.472      381-426/? W/AudioService﹕ Soundpool could not load file: /system/media/audio/ui/KeypressStandard.ogg
07-02 15:54:40.472      381-426/? E/SoundPool﹕ error loading /system/media/audio/ui/KeypressSpacebar.ogg
07-02 15:54:40.472      381-426/? W/AudioService﹕ Soundpool could not load file: /system/media/audio/ui/KeypressSpacebar.ogg
07-02 15:54:40.482      381-426/? E/SoundPool﹕ error loading /system/media/audio/ui/KeypressDelete.ogg
07-02 15:54:40.482      381-426/? W/AudioService﹕ Soundpool could not load file: /system/media/audio/ui/KeypressDelete.ogg
07-02 15:54:40.482      381-426/? E/SoundPool﹕ error loading /system/media/audio/ui/KeypressReturn.ogg
07-02 15:54:40.492      381-426/? W/AudioService﹕ Soundpool could not load file: /system/media/audio/ui/KeypressReturn.ogg
07-02 15:54:40.492      381-426/? E/SoundPool﹕ error loading /system/media/audio/ui/KeypressInvalid.ogg
07-02 15:54:40.492      381-426/? W/AudioService﹕ Soundpool could not load file: /system/media/audio/ui/KeypressInvalid.ogg
07-02 15:54:40.492      381-426/? W/AudioService﹕ onLoadSoundEffects(), Error -1 while loading samples
07-02 15:54:40.662      536-536/? I/Choreographer﹕ Skipped 114 frames!  The application may be doing too much work on its main thread.
07-02 15:54:41.182      381-632/? I/ActivityManager﹕ Process com.example.scoelli.hello (pid 1696) has died.
07-02 15:54:41.182      381-628/? I/WindowState﹕ WIN DEATH: Window{b3053f60 u0 com.example.scoelli.hello/com.example.scoelli.hello.MyActivity}
07-02 15:54:41.392      381-442/? D/LightsService﹕ Excessive delay setting light: 1438ms

谢谢!

2 个答案:

答案 0 :(得分:0)

当您在主线程中进行网络访问时,您的应用会因NetworkOnMainThreadExeption而崩溃。将您的http客户端代码放在AsyncTask或线程中,并在清单中请求Internet权限。例外将在您的logcat中。但你没有张贴......

答案 1 :(得分:-2)

您需要在PHP中创建一个API(REST),您可以从应用程序中调用它。

使用库来帮助处理异步回调对此非常有帮助。

这是我经常使用的那个:

LoopJ's Async HTTP Callback Library

这将处理GET和POST请求,具有许多很酷的功能,如自定义超时,JSON格式,onSuccess()和onFailure()方法等。这个库也有很多工作示例。我已经在我的所有应用程序中使用它并且还没有任何问题!

希望这有帮助。