Lamentablemente el nombre de la aplicación se detuvo

Estoy trabajando en Android Twitter Client y cuando el código se ejecuta en mi dispositivo Android, muestra "Desafortunadamente, appname ha dejado de funcionar". Anteriormente tiene un logcat diferente, pero se ha resuelto. Ahora cuando lo compilo, tiene otro error que causó la detención de la aplicación.

Aquí está el logcat:

12-17 02:05:14.045: E/AndroidRuntime(24423): FATAL EXCEPTION: AsyncTask #1
12-17 02:05:14.045: E/AndroidRuntime(24423): java.lang.RuntimeException: An error occured while executing doInBackground()
12-17 02:05:14.045: E/AndroidRuntime(24423):    at android.os.AsyncTask$3.done(AsyncTask.java:299)
12-17 02:05:14.045: E/AndroidRuntime(24423):    at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
12-17 02:05:14.045: E/AndroidRuntime(24423):    at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
12-17 02:05:14.045: E/AndroidRuntime(24423):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
12-17 02:05:14.045: E/AndroidRuntime(24423):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
12-17 02:05:14.045: E/AndroidRuntime(24423):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
12-17 02:05:14.045: E/AndroidRuntime(24423):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
12-17 02:05:14.045: E/AndroidRuntime(24423):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
12-17 02:05:14.045: E/AndroidRuntime(24423):    at java.lang.Thread.run(Thread.java:856)
12-17 02:05:14.045: E/AndroidRuntime(24423): Caused by: java.lang.SecurityException: Permission denied (missing INTERNET permission?)
12-17 02:05:14.045: E/AndroidRuntime(24423):    at java.net.InetAddress.lookupHostByName(InetAddress.java:418)
12-17 02:05:14.045: E/AndroidRuntime(24423):    at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
12-17 02:05:14.045: E/AndroidRuntime(24423):    at java.net.InetAddress.getAllByName(InetAddress.java:214)
12-17 02:05:14.045: E/AndroidRuntime(24423):    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
12-17 02:05:14.045: E/AndroidRuntime(24423):    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
12-17 02:05:14.045: E/AndroidRuntime(24423):    at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
12-17 02:05:14.045: E/AndroidRuntime(24423):    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
12-17 02:05:14.045: E/AndroidRuntime(24423):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:670)
12-17 02:05:14.045: E/AndroidRuntime(24423):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:509)
12-17 02:05:14.045: E/AndroidRuntime(24423):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
12-17 02:05:14.045: E/AndroidRuntime(24423):    at com.example.androidtwitterclient.MainActivity$DownloadTwitterTask.getResponseBody(MainActivity.java:120)
12-17 02:05:14.045: E/AndroidRuntime(24423):    at com.example.androidtwitterclient.MainActivity$DownloadTwitterTask.getTwitterStream(MainActivity.java:165)
12-17 02:05:14.045: E/AndroidRuntime(24423):    at com.example.androidtwitterclient.MainActivity$DownloadTwitterTask.doInBackground(MainActivity.java:67)
12-17 02:05:14.045: E/AndroidRuntime(24423):    at com.example.androidtwitterclient.MainActivity$DownloadTwitterTask.doInBackground(MainActivity.java:1)
12-17 02:05:14.045: E/AndroidRuntime(24423):    at android.os.AsyncTask$2.call(AsyncTask.java:287)
12-17 02:05:14.045: E/AndroidRuntime(24423):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
12-17 02:05:14.045: E/AndroidRuntime(24423):    ... 5 more
12-17 02:05:14.045: E/AndroidRuntime(24423): Caused by: libcore.io.GaiException: getaddrinfo failed: EAI_NODATA (No address associated with hostname)
12-17 02:05:14.045: E/AndroidRuntime(24423):    at libcore.io.Posix.getaddrinfo(Native Method)
12-17 02:05:14.045: E/AndroidRuntime(24423):    at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:55)
12-17 02:05:14.045: E/AndroidRuntime(24423):    at java.net.InetAddress.lookupHostByName(InetAddress.java:405)
12-17 02:05:14.045: E/AndroidRuntime(24423):    ... 20 more
12-17 02:05:14.045: E/AndroidRuntime(24423): Caused by: libcore.io.ErrnoException: getaddrinfo failed: EACCES (Permission denied)
12-17 02:05:14.045: E/AndroidRuntime(24423):    ... 23 more

Y aquí está mi AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>


    

    
        
            
                

                
            
        
    


Y aquí está mi archivo mainactivity.xml:

package com.example.androidtwitterclient;

import android.app.ListActivity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Base64;
import android.util.Log;
import android.widget.ArrayAdapter;
import com.google.gson.Gson;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;

import java.io.*;
import java.net.URLEncoder;

/**
 * Demonstrates how to use a twitter application keys to access a user's timeline
 */
public class MainActivity extends ListActivity {

    private ListActivity activity;
    final static String ScreenName = "elvirachrisanty";
    final static String LOG_TAG = "rnc";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        activity = this;

        downloadTweets();
    }

   //download twitter timeline after first checking to see if there is a network connection
    public void downloadTweets() {
        ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();

        if (networkInfo != null && networkInfo.isConnected()) {
            new DownloadTwitterTask().execute(ScreenName);
        } else {
            Log.v(LOG_TAG, "No network connection available.");
        }
    }

   //Uses an AsyncTask to download a Twitter user's timeline
    private class DownloadTwitterTask extends AsyncTask {
        final static String CONSUMER_KEY = "WWAtGnhZ11uSCPLjmN9Fw";
        final static String CONSUMER_SECRET = "ZnorUE440cG7vhEp25NS977fahiUFK1inqxnbDyedd0";
        final static String TwitterTokenURL = "https://api.twitter.com/oauth2/token";
        final static String TwitterStreamURL = "https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=";

        @Override
        protected String doInBackground(String... screenNames) {
            String result = null;

            if (screenNames.length > 0) {
                result = getTwitterStream(screenNames[0]);
            }
            return result;
        }

       //onPostExecute convert the JSON results into a Twitter object (which is an Array list of tweets
        @Override
        protected void onPostExecute(String result) {
            Twitter twits = jsonToTwitter(result);

           //lets write the results to the console as well
            for (Tweet tweet : twits) {
                Log.i(LOG_TAG, tweet.getText());
            }

           //send the tweets to the adapter for rendering
            ArrayAdapter adapter = new ArrayAdapter(activity, android.R.layout.simple_list_item_1, twits);
            setListAdapter(adapter);
        }

       //converts a string of JSON data into a Twitter object
        private Twitter jsonToTwitter(String result) {
            Twitter twits = null;
            if (result != null && result.length() > 0) {
                try {
                    Gson gson = new Gson();
                    twits = gson.fromJson(result, Twitter.class);
                } catch (IllegalStateException ex) {
                   //just eat the exception
                }
            }
            return twits;
        }

       //convert a JSON authentication object into an Authenticated object
        private Authenticated jsonToAuthenticated(String rawAuthorization) {
            Authenticated auth = null;
            if (rawAuthorization != null && rawAuthorization.length() > 0) {
                try {
                    Gson gson = new Gson();
                    auth = gson.fromJson(rawAuthorization, Authenticated.class);
                } catch (IllegalStateException ex) {
                   //just eat the exception
                }
            }
            return auth;
        }

        private String getResponseBody(HttpRequestBase request) {
            StringBuilder sb = new StringBuilder();
            try {

                DefaultHttpClient httpClient = new DefaultHttpClient(new BasicHttpParams());
                HttpResponse response = httpClient.execute(request);
                int statusCode = response.getStatusLine().getStatusCode();
                String reason = response.getStatusLine().getReasonPhrase();

                if (statusCode == 200) {

                    HttpEntity entity = response.getEntity();
                    InputStream inputStream = entity.getContent();

                    BufferedReader bReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
                    String line = null;
                    while ((line = bReader.readLine()) != null) {
                        sb.append(line);
                    }
                } else {
                    sb.append(reason);
                }
            } catch (UnsupportedEncodingException ex) {
            } catch (ClientProtocolException ex1) {
            } catch (IOException ex2) {
            }
            return sb.toString();
        }

        private String getTwitterStream(String screenName) {
            String results = null;

           //Step 1: Encode consumer key and secret
            try {
               //URL encode the consumer key and secret
                String urlApiKey = URLEncoder.encode(CONSUMER_KEY, "UTF-8");
                String urlApiSecret = URLEncoder.encode(CONSUMER_SECRET, "UTF-8");

               //Concatenate the encoded consumer key, a colon character, and the
               //encoded consumer secret
                String combined = urlApiKey + ":" + urlApiSecret;

               //Base64 encode the string
                String base64Encoded = Base64.encodeToString(combined.getBytes(), Base64.NO_WRAP);

               //Step 2: Obtain a bearer token
                HttpPost httpPost = new HttpPost(TwitterTokenURL);
                httpPost
0
Causado por: java.lang.SecurityException: ¿Permiso denegado (falta el permiso de INTERNET?) ¿Agregaste este permiso a tu manifiesto? No lo creo
agregado el autor Alexis C., fuente

2 Respuestas

Causado por: java.lang.SecurityException: ¿Permiso denegado (falta el permiso de INTERNET?)

Tienes que agregar este permiso en tu Manifiesto.


0
agregado

Debes declarar el permiso de Internet. Solo agrega




estas líneas a su archivo AndroidManifest.xml

0
agregado