0

Bom pessoa, eu estava tentando fazer um aplicativo que insere produtos e te permite visualizar ele no celular por meio de banco de dados, mas quando tento criar o produto o aplicativo fecha e aparece isso na minha 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

OBS: Estou usando WampServer (localhost)


@Edit

Classe que manipula a Conexao:

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;

    }
}
4
  • Existe alguma classe, ou objeto que manipule a conexão com o banco? Se tiver, coloque aqui por favor. 18/02/2015 às 16:11
  • @GustavoCinque existe sim, JSONParser, vou editar o topico..
    – Jeiferson
    18/02/2015 às 21:41
  • Jeiferson, o servidor MySQL está no dispositivo Android (localhost)? Ou em uma máquina na mesma rede? Lembrando que deve usar o endereço de rede privada para se conectar com o servidor em vez de localhost...
    – Wakim
    18/02/2015 às 21:55
  • @Wakim fiz umas alterações agora o erro é diferente, vou editar o topico...
    – Jeiferson
    18/02/2015 às 22:05

2 Respostas 2

1

O servidor não está conseguindo acessar o banco de dados no endereço "localhost"

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

Tente alterar nas configurações do servidor para o ip local "127.0.0.1" ao invés de "localhost"

Tente também acessar sua aplicação via seu TCP/IP

Você também precisa liberar acesso a internet no servidor:

No arquivo AndroidManifest.xml, adicione a seguinte linha:

<manifest> 
...
    <uses-permission android:name="android.permission.INTERNET"/>
</manifest>
7
  • Como eu alterou isso?
    – Jeiferson
    18/02/2015 às 17:22
  • Melhorei a resposta com uma verificação de permissão.
    – LeoCBS
    18/02/2015 às 18:12
  • Ja liberei essa permissao...
    – Jeiferson
    18/02/2015 às 19:32
  • Quero saber como alterar as configurações de ip...
    – Jeiferson
    18/02/2015 às 19:41
  • Jeiferson, tenta posta a solução no erro e criar uma nova pergunta para esse erro do JSON. Assim o erro de banco fica documentado para futuras consultas. Abraço
    – LeoCBS
    19/02/2015 às 10:40
0

Basicamente esta ocorrendo un Nullpointer exception por causa de que esta tratando de facer una coneçao a localhost, o cual para o android e o propio device, para faver refencia a maquina onde esta o servidor web use a ip da rede local ou 10.0.2.2 Para mais referencias https://stackoverflow.com/questions/5806220/how-to-connect-to-my-http-localhost-web-server-from-android-emulator-in-eclips

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .