0

I have been trying to run an application that stores and retrieves data from MySQL using PHP and Android. The whole project is on this link.

I am getting the following error

05-01 20:38:57.833: W/System.err(28816): org.apache.http.conn.HttpHostConnectException: Connection to http://192.168.1.34 refused
05-01 20:38:57.842: W/System.err(28816):    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:188)
05-01 20:38:57.842: W/System.err(28816):    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:169)
05-01 20:38:57.842: W/System.err(28816):    at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:124)
05-01 20:38:57.842: W/System.err(28816):    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:365)
05-01 20:38:57.842: W/System.err(28816):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:560)
05-01 20:38:57.842: W/System.err(28816):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:492)
05-01 20:38:57.842: W/System.err(28816):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:470)
05-01 20:38:57.842: W/System.err(28816):    at com.example.androidhive.JSONParser.makeHttpRequest(JSONParser.java:62)
05-01 20:38:57.842: W/System.err(28816):    at com.example.androidhive.AllProductsActivity$LoadAllProducts.doInBackground(AllProductsActivity.java:127)
05-01 20:38:57.842: W/System.err(28816):    at com.example.androidhive.AllProductsActivity$LoadAllProducts.doInBackground(AllProductsActivity.java:1)
05-01 20:38:57.842: W/System.err(28816):    at android.os.AsyncTask$2.call(AsyncTask.java:292)
05-01 20:38:57.842: W/System.err(28816):    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
05-01 20:38:57.842: W/System.err(28816):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
05-01 20:38:57.843: W/System.err(28816):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
05-01 20:38:57.843: W/System.err(28816):    at java.lang.Thread.run(Thread.java:818)
05-01 20:38:57.853: W/System.err(28816): Caused by: java.net.ConnectException: failed to connect to /192.168.1.34 (port 80): connect failed: ETIMEDOUT (Connection timed out)
05-01 20:38:57.872: W/System.err(28816):    at libcore.io.IoBridge.connect(IoBridge.java:124)
05-01 20:38:57.872: W/System.err(28816):    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183)
05-01 20:38:57.872: W/System.err(28816):    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:456)
05-01 20:38:57.872: W/System.err(28816):    at java.net.Socket.connect(Socket.java:882)
05-01 20:38:57.872: W/System.err(28816):    at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:124)
05-01 20:38:57.872: W/System.err(28816):    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:149)
05-01 20:38:57.872: W/System.err(28816):    ... 14 more
05-01 20:38:57.873: W/System.err(28816): Caused by: android.system.ErrnoException: connect failed: ETIMEDOUT (Connection timed out)
05-01 20:38:57.873: W/System.err(28816):    at libcore.io.Posix.connect(Native Method)
05-01 20:38:57.873: W/System.err(28816):    at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:111)
05-01 20:38:57.873: W/System.err(28816):    at libcore.io.IoBridge.connectErrno(IoBridge.java:137)
05-01 20:38:57.873: W/System.err(28816):    at libcore.io.IoBridge.connect(IoBridge.java:122)
05-01 20:38:57.873: W/System.err(28816):    ... 19 more
05-01 20:38:57.874: E/Buffer Error(28816): Error converting result java.lang.NullPointerException: lock == null
05-01 20:38:57.897: E/JSON Parser(28816): Error parsing data org.json.JSONException: End of input at character 0 of 
05-01 20:38:57.928: E/AndroidRuntime(28816): FATAL EXCEPTION: AsyncTask #1
05-01 20:38:57.928: E/AndroidRuntime(28816): Process: com.example.androidhive, PID: 28816
05-01 20:38:57.928: E/AndroidRuntime(28816): java.lang.RuntimeException: An error occured while executing doInBackground()
05-01 20:38:57.928: E/AndroidRuntime(28816):    at android.os.AsyncTask$3.done(AsyncTask.java:304)
05-01 20:38:57.928: E/AndroidRuntime(28816):    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
05-01 20:38:57.928: E/AndroidRuntime(28816):    at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
05-01 20:38:57.928: E/AndroidRuntime(28816):    at java.util.concurrent.FutureTask.run(FutureTask.java:242)
05-01 20:38:57.928: E/AndroidRuntime(28816):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
05-01 20:38:57.928: E/AndroidRuntime(28816):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
05-01 20:38:57.928: E/AndroidRuntime(28816):    at java.lang.Thread.run(Thread.java:818)
05-01 20:38:57.928: E/AndroidRuntime(28816): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String org.json.JSONObject.toString()' on a null object reference
05-01 20:38:57.928: E/AndroidRuntime(28816):    at com.example.androidhive.AllProductsActivity$LoadAllProducts.doInBackground(AllProductsActivity.java:130)
05-01 20:38:57.928: E/AndroidRuntime(28816):    at com.example.androidhive.AllProductsActivity$LoadAllProducts.doInBackground(AllProductsActivity.java:1)
05-01 20:38:57.928: E/AndroidRuntime(28816):    at android.os.AsyncTask$2.call(AsyncTask.java:292)
05-01 20:38:57.928: E/AndroidRuntime(28816):    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
05-01 20:38:57.928: E/AndroidRuntime(28816):    ... 3 more

I have connected both my phone and the server(laptop-localhost) to the wifi. I have checked the ping after checking the ipconfig to know the ip address of localhost.

Ip address is 192.168.1.34 (obtained from ipconfig)

,ping is working fine using this ip address

this IP address is working in browser (displaying the local host when i type this ip address)

I have searched a lot and got the same answer to include foll. in manifest file

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

But I had already included it and still facing the same problem. Here is my code of manifest file.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.androidhive"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />

    <application
        android:configChanges="keyboardHidden|orientation"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >


        <activity
            android:name=".MainScreenActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <!-- All Product Activity -->
        <activity
            android:name=".AllProductsActivity"
            android:label="All Products" >
        </activity>

        <!-- Add Product Activity -->
        <activity
            android:name=".NewProductActivity"
            android:label="Add New Product" >
        </activity>

        <!-- Edit Product Activity -->
        <activity
            android:name=".EditProductActivity"
            android:label="Edit Product" >
        </activity>
    </application>

    <!--  Internet Permissions -->
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

</manifest>

Please help and oblige Thank You

Mattia Maestrini
  • 32,270
  • 15
  • 87
  • 94
  • After adding 'http://localhost/android_connect/get_all_products.php' to browser, I am getting the following output," {"pid":"1","name":"Siddharth","price":"1876.00","description":"sdkvjsdij","created_at":"2015-05-01 19:51:57","updated_at":"0000-00-00 00:00:00"}],"success":1} " hence i think that the output is correct(so must be some problem with the N/W). – Siddharth Verma May 01 '15 at 16:10
  • show your AsyncTask class. Are you using a framework or just normal php? – James Njuguna May 01 '15 at 16:15
  • try using http://127.0.0.1/android_connect/get_all_products.php – James Njuguna May 01 '15 at 16:16
  • 1
    The issue resolved now, I had turned the firewall ON. I had to turn it off. Thank You James for helping (y) – Siddharth Verma May 01 '15 at 17:54
  • Hi James, Please help i have another problem, stuck in it for a long time now. http://stackoverflow.com/questions/30018667/rsa-in-android-producing-right-keys-but-wrong-decryption – Siddharth Verma May 03 '15 at 20:00

2 Answers2

0

use 192.168.1.34:80. Let me know if it works. It worked for me. If doesn't then follow this link

Community
  • 1
  • 1
Roon13
  • 387
  • 2
  • 23
0

Silly Me. I had turned the Firewall ON. Had to turn it off to make it work.

Thank You Every1 for help