Error trying to insert values in MySQL

0

Well, I was trying to make an application that inserts products and allows you to view it on the phone through the database, but when I try to create the product the application closes and it appears in my LogCat:

2-18 15:55:27.667: I/Choreographer(1067): Skipped 48 frames!  The application may be doing too much work on its main thread.
02-18 15:55:27.782: D/gralloc_goldfish(1067): Emulator without GPU emulation detected.
02-18 15:55:28.234: I/Choreographer(1067): Skipped 55 frames!  The application may be doing too much work on its main thread.
02-18 15:55:57.904: I/Choreographer(1067): Skipped 167 frames!  The application may be doing too much work on its main thread.
02-18 15:55:59.174: I/Choreographer(1067): Skipped 136 frames!  The application may be doing too much work on its main thread.
02-18 15:56:01.128: I/Choreographer(1067): Skipped 211 frames!  The application may be doing too much work on its main thread.
02-18 15:56:25.616: I/Choreographer(1067): Skipped 71 frames!  The application may be doing too much work on its main thread.
02-18 15:56:26.819: I/Choreographer(1067): Skipped 96 frames!  The application may be doing too much work on its main thread.
02-18 15:56:27.948: I/Choreographer(1067): Skipped 119 frames!  The application may be doing too much work on its main thread.
02-18 15:56:31.006: I/Choreographer(1067): Skipped 331 frames!  The application may be doing too much work on its main thread.
02-18 15:56:54.902: I/Choreographer(1067): Skipped 66 frames!  The application may be doing too much work on its main thread.
02-18 15:56:55.582: I/Choreographer(1067): Skipped 71 frames!  The application may be doing too much work on its main thread.
02-18 15:56:56.022: I/Choreographer(1067): Skipped 46 frames!  The application may be doing too much work on its main thread.
02-18 15:56:56.454: I/Choreographer(1067): Skipped 45 frames!  The application may be doing too much work on its main thread.
02-18 15:56:56.980: I/Choreographer(1067): Skipped 54 frames!  The application may be doing too much work on its main thread.
02-18 15:56:57.747: I/Choreographer(1067): Skipped 36 frames!  The application may be doing too much work on its main thread.
02-18 15:56:58.216: I/Choreographer(1067): Skipped 31 frames!  The application may be doing too much work on its main thread.
02-18 15:56:59.674: I/Choreographer(1067): Skipped 30 frames!  The application may be doing too much work on its main thread.
02-18 15:56:59.888: W/System.err(1067): org.apache.http.conn.HttpHostConnectException: Connection to http://localhost refused
02-18 15:56:59.890: W/System.err(1067):     at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:183)
02-18 15:56:59.890: W/System.err(1067):     at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
02-18 15:56:59.890: W/System.err(1067):     at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
02-18 15:56:59.890: W/System.err(1067):     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
02-18 15:57:00.512: W/System.err(1067):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
02-18 15:57:00.512: W/System.err(1067):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
02-18 15:57:00.513: W/System.err(1067):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
02-18 15:57:00.513: W/System.err(1067):     at br.com.products.JSONParser.makeHttpRequest(JSONParser.java:51)
02-18 15:57:00.513: W/System.err(1067):     at br.com.products.NewProductActivity$CreateNewProduct.doInBackground(NewProductActivity.java:95)
02-18 15:57:00.513: W/System.err(1067):     at br.com.products.NewProductActivity$CreateNewProduct.doInBackground(NewProductActivity.java:1)
02-18 15:57:00.514: W/System.err(1067):     at android.os.AsyncTask$2.call(AsyncTask.java:288)
02-18 15:57:00.514: W/System.err(1067):     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
02-18 15:57:00.514: W/System.err(1067):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
02-18 15:57:00.514: W/System.err(1067):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
02-18 15:57:00.514: W/System.err(1067):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
02-18 15:57:00.515: W/System.err(1067):     at java.lang.Thread.run(Thread.java:818)
02-18 15:57:00.515: W/System.err(1067): Caused by: java.net.ConnectException: failed to connect to /127.0.0.1 (port 80): connect failed: ECONNREFUSED (Connection refused)
02-18 15:57:00.816: I/Choreographer(1067): Skipped 43 frames!  The application may be doing too much work on its main thread.
02-18 15:57:00.997: W/System.err(1067):     at libcore.io.IoBridge.connect(IoBridge.java:124)
02-18 15:57:00.998: W/System.err(1067):     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183)
02-18 15:57:00.998: W/System.err(1067):     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:456)
02-18 15:57:00.998: W/System.err(1067):     at java.net.Socket.connect(Socket.java:882)
02-18 15:57:00.998: W/System.err(1067):     at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
02-18 15:57:00.998: W/System.err(1067):     at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)
02-18 15:57:00.999: W/System.err(1067):     ... 15 more
02-18 15:57:00.999: W/System.err(1067): Caused by: android.system.ErrnoException: connect failed: ECONNREFUSED (Connection refused)
02-18 15:57:01.213: W/System.err(1067):     at libcore.io.Posix.connect(Native Method)
02-18 15:57:01.214: W/System.err(1067):     at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:111)
02-18 15:57:01.214: W/System.err(1067):     at libcore.io.IoBridge.connectErrno(IoBridge.java:137)
02-18 15:57:01.214: W/System.err(1067):     at libcore.io.IoBridge.connect(IoBridge.java:122)
02-18 15:57:01.214: W/System.err(1067):     ... 20 more
02-18 15:57:01.216: E/Buffer Error(1067): Error converting result java.lang.NullPointerException: lock == null
02-18 15:57:01.218: E/JSON Parser(1067): Error parsing data org.json.JSONException: End of input at character 0 of 
02-18 15:57:01.444: I/Choreographer(1067): Skipped 35 frames!  The application may be doing too much work on its main thread.
02-18 15:57:01.444: I/Choreographer(1067): --------- beginning of crash
02-18 15:57:01.795: E/AndroidRuntime(1067): FATAL EXCEPTION: AsyncTask #2
02-18 15:57:01.795: E/AndroidRuntime(1067): Process: br.com.products, PID: 1067
02-18 15:57:01.795: E/AndroidRuntime(1067): java.lang.RuntimeException: An error occured while executing doInBackground()
02-18 15:57:01.795: E/AndroidRuntime(1067):     at android.os.AsyncTask$3.done(AsyncTask.java:300)
02-18 15:57:01.795: E/AndroidRuntime(1067):     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
02-18 15:57:01.795: E/AndroidRuntime(1067):     at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
02-18 15:57:01.795: E/AndroidRuntime(1067):     at java.util.concurrent.FutureTask.run(FutureTask.java:242)
02-18 15:57:01.795: E/AndroidRuntime(1067):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
02-18 15:57:01.795: E/AndroidRuntime(1067):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
02-18 15:57:01.795: E/AndroidRuntime(1067):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
02-18 15:57:01.795: E/AndroidRuntime(1067):     at java.lang.Thread.run(Thread.java:818)
02-18 15:57:01.795: E/AndroidRuntime(1067): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String org.json.JSONObject.toString()' on a null object reference
02-18 15:57:01.795: E/AndroidRuntime(1067):     at br.com.products.NewProductActivity$CreateNewProduct.doInBackground(NewProductActivity.java:99)
02-18 15:57:01.795: E/AndroidRuntime(1067):     at br.com.products.NewProductActivity$CreateNewProduct.doInBackground(NewProductActivity.java:1)
02-18 15:57:01.795: E/AndroidRuntime(1067):     at android.os.AsyncTask$2.call(AsyncTask.java:288)
02-18 15:57:01.795: E/AndroidRuntime(1067):     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
02-18 15:57:01.795: E/AndroidRuntime(1067):     ... 4 more
02-18 15:57:02.283: I/Choreographer(1067): Skipped 54 frames!  The application may be doing too much work on its main thread.
02-18 15:57:02.996: I/Choreographer(1067): Skipped 76 frames!  The application may be doing too much work on its main thread.
02-18 15:57:04.112: I/Choreographer(1067): Skipped 98 frames!  The application may be doing too much work on its main thread.
02-18 15:57:05.401: I/Choreographer(1067): Skipped 138 frames!  The application may be doing too much work on its main thread.
02-18 15:57:06.121: I/Choreographer(1067): Skipped 37 frames!  The application may be doing too much work on its main thread.
02-18 15:57:07.214: I/Choreographer(1067): Skipped 127 frames!  The application may be doing too much work on its main thread.
02-18 15:57:07.689: E/WindowManager(1067): android.view.WindowLeaked: Activity br.com.products.NewProductActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{34f05b4 V.E..... R.....ID 0,0-684,232} that was originally added here
02-18 15:57:07.689: E/WindowManager(1067):  at android.view.ViewRootImpl.<init>(ViewRootImpl.java:363)
02-18 15:57:07.689: E/WindowManager(1067):  at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:261)
02-18 15:57:07.689: E/WindowManager(1067):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
02-18 15:57:07.689: E/WindowManager(1067):  at android.app.Dialog.show(Dialog.java:298)
02-18 15:57:07.689: E/WindowManager(1067):  at br.com.products.NewProductActivity$CreateNewProduct.onPreExecute(NewProductActivity.java:76)
02-18 15:57:07.689: E/WindowManager(1067):  at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:587)
02-18 15:57:07.689: E/WindowManager(1067):  at android.os.AsyncTask.execute(AsyncTask.java:535)
02-18 15:57:07.689: E/WindowManager(1067):  at br.com.products.NewProductActivity$1.onClick(NewProductActivity.java:56)
02-18 15:57:07.689: E/WindowManager(1067):  at android.view.View.performClick(View.java:4756)
02-18 15:57:07.689: E/WindowManager(1067):  at android.view.View$PerformClick.run(View.java:19749)
02-18 15:57:07.689: E/WindowManager(1067):  at android.os.Handler.handleCallback(Handler.java:739)
02-18 15:57:07.689: E/WindowManager(1067):  at android.os.Handler.dispatchMessage(Handler.java:95)
02-18 15:57:07.689: E/WindowManager(1067):  at android.os.Looper.loop(Looper.java:135)
02-18 15:57:07.689: E/WindowManager(1067):  at android.app.ActivityThread.main(ActivityThread.java:5221)
02-18 15:57:07.689: E/WindowManager(1067):  at java.lang.reflect.Method.invoke(Native Method)
02-18 15:57:07.689: E/WindowManager(1067):  at java.lang.reflect.Method.invoke(Method.java:372)
02-18 15:57:07.689: E/WindowManager(1067):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
02-18 15:57:07.689: E/WindowManager(1067):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
02-18 15:57:08.207: I/Choreographer(1067): Skipped 50 frames!  The application may be doing too much work on its main thread.
02-18 15:57:11.746: I/Process(1067): Sending signal. PID: 1067 SIG: 9

NOTE: I'm using WampServer (localhost)

@Edit

Class that Handles Connection:

JSONParser.java

package br.com.products;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

public class JSONParser {

    static InputStream is = null;
    static JSONObject jObj = null;
    static String json = "";

    // constructor
    public JSONParser() {

    }

    // function get json from url
    // by making HTTP POST or GET mehtod
    public JSONObject makeHttpRequest(String url, String method,
            List<NameValuePair> params) {

        // Making HTTP request
        try {

            // check for request method
            if(method == "POST"){
                // request method is POST
                // defaultHttpClient
                DefaultHttpClient httpClient = new DefaultHttpClient();
                HttpPost httpPost = new HttpPost(url);
                httpPost.setEntity(new UrlEncodedFormEntity(params));

                HttpResponse httpResponse = httpClient.execute(httpPost);
                HttpEntity httpEntity = httpResponse.getEntity();
                is = httpEntity.getContent();

            }else if(method == "GET"){
                // request method is GET
                DefaultHttpClient httpClient = new DefaultHttpClient();
                String paramString = URLEncodedUtils.format(params, "utf-8");
                url += "?" + paramString;
                HttpGet httpGet = new HttpGet(url);

                HttpResponse httpResponse = httpClient.execute(httpGet);
                HttpEntity httpEntity = httpResponse.getEntity();
                is = httpEntity.getContent();
            }           

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    is, "iso-8859-1"), 8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            is.close();
            json = sb.toString();
        } catch (Exception e) {
            Log.e("Buffer Error", "Error converting result " + e.toString());
        }

        // try parse the string to a JSON object
        try {
            jObj = new JSONObject(json);
        } catch (JSONException e) {
            Log.e("JSON Parser", "Error parsing data " + e.toString());
        }

        // return JSON String
        return jObj;

    }
}
    
asked by anonymous 18.02.2015 / 17:01

2 answers

1

The server is not able to access the database at "localhost"

Connection to http://localhost refused 02-18 15:56:59.890: W/System.err(1067): at 

Try changing the server settings to local ip "127.0.0.1" instead of "localhost"

Also try to access your application via your TCP / IP

You also need to free internet access on the server:

In the AndroidManifest.xml file, add the following line:

<manifest> 
...
    <uses-permission android:name="android.permission.INTERNET"/>
</manifest>
    
18.02.2015 / 17:11
0

Basically this is a Nullpointer exception because it is trying to make a connection to localhost, or which to the android and the device itself, to reffer to the machine where the web server is using ip from the local network or 10.0 .2.2 For more references link

    
23.07.2015 / 20:33