• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps App Crash onClick

I'm creating an app that goes through JSON data on a website and then presents it to the user. It asks the user to enter a game name and searches through the JSON database to get the results. I'm having some problems with getting the results though. It seems like certain results crash the app when I click on them, but I don't get any errors.

Java:
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    private Button button = null;
    private EditText text = null;
    private ProgressBar progressBar = null;
    private TextView responseView = null;
    private ListView gameListRows = null;
    ImageView imageView = null;

    private String query_text = "";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        button = (Button) findViewById(R.id.s_button);
        text = (EditText) findViewById(R.id.s_text);
        progressBar = (ProgressBar) findViewById(R.id.progressBar);
        responseView = (TextView) findViewById(R.id.responseView);
        gameListRows = (ListView) findViewById(R.id.listView);
        imageView = (ImageView) findViewById(R.id.icon);

        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

                query_text = text.getText().toString();
                new JSONParser().execute();
            }
        });
    }

    public class JSONParser extends AsyncTask<Void,Void,String> {

        private Exception exception;
        private GetJSONValues jsonValues = new GetJSONValues();
        private ArrayList<Game> gameData = jsonValues.gameData;

        protected void onPreExecute()
        {
            progressBar.setVisibility(View.VISIBLE);
            responseView.setText("");
        }

        protected String doInBackground(Void... urls)
        {
            try {

                URL url = new URL("http://www.giantbomb.com/api/search/?query=" + URLEncoder.encode(query_text, "UTF-8")
                        + "&field_list=name,id,deck,description,image&resources=game,concept&api_key=API_KEY&format=json&offset=0");
                HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();

                try
                {
                    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));

                    StringBuilder stringBuilder = new StringBuilder();
                    String line;

                    while ((line = bufferedReader.readLine()) != null)
                    {
                        stringBuilder.append(line).append("\n");
                    }
                    bufferedReader.close();

                    String result = stringBuilder.toString();

                    try {
                        JSONObject jsonObject = new JSONObject(result);
                        JSONArray jsonArray = jsonObject.getJSONArray("results");
                        jsonValues.getGameList(jsonArray);
                        jsonValues.getValues();
                    }
                    catch (JSONException e)
                    {
                        e.printStackTrace();
                    }
                    return  result;
                }
                finally {
                    urlConnection.disconnect();
                }
            }
            catch (IOException e)
            {
                e.printStackTrace();
                return null;
            }

        }

        protected void onPostExecute(String response)
        {
            if(response == null)
            {
                response = "THERE WAS AN ERROR";
            }
            progressBar.setVisibility(View.GONE);
            //Log.i("INFO", response);
            RowAdapter adapter = new RowAdapter(MainActivity.this, gameData);
            gameListRows.setAdapter(adapter);

            gameListRows.setOnItemClickListener(
                    new AdapterView.OnItemClickListener()
                    {
                        @Override
                        public void onItemClick(AdapterView<?> parent, View view, int position, long id)
                        {
                            try {
                                Game gameInfo = gameData.get(position);
                                Bitmap temp = gameInfo.imageUrl;
                                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                                gameInfo.imageUrl.compress(Bitmap.CompressFormat.PNG, 100, stream);
                                byte[] bytes = stream.toByteArray();

                                gameInfo.imageUrl = null;
                                Intent myIntent = new Intent(view.getContext(), game_info.class);
                                myIntent.putExtra("tempGame", gameInfo);
                                myIntent.putExtra("gameImage", bytes);
                                startActivity(myIntent);
                                gameInfo.imageUrl = temp;
                            }catch (Exception e)
                            {
                                System.out.println(e);
                            }
                        }
                    }

            );
        }
    }
}
 
If the app crashed you will have a stack trace in the Logcat output. Next time it crashes, please post this stack trace.
 
If the app crashed you will have a stack trace in the Logcat output. Next time it crashes, please post this stack trace.

Here you go. Any ideas.

Code:
04-14 11:06:58.459 14949-14949/? I/art: Not late-enabling -Xcheck:jni (already on)
04-14 11:06:58.495 14949-14949/com.temp.temp.gamelibary W/ActivityThread: Application com.temp.temp.gamelibary is waiting for the debugger on port 8100...
04-14 11:06:58.538 14949-14955/com.temp.temp.gamelibary I/art: Debugger is active
04-14 11:06:58.553 14949-14949/com.temp.temp.gamelibary W/System: ClassLoader referenced unknown path: /data/app/com.temp.temp.gamelibary-2/lib/x86
04-14 11:06:58.737 14949-14972/com.temp.temp.gamelibary D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
04-14 11:06:58.827 14949-14972/com.temp.temp.gamelibary I/OpenGLRenderer: Initialized EGL, version 1.4
04-14 11:06:58.877 14949-14972/com.temp.temp.gamelibary W/EGL_emulation: eglSurfaceAttrib not implemented
04-14 11:06:58.877 14949-14972/com.temp.temp.gamelibary W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xb4034380, error=EGL_SUCCESS
04-14 11:06:59.535 14949-14949/com.temp.temp.gamelibary I/Choreographer: Skipped 44 frames!  The application may be doing too much work on its main thread.
 
Sorry for the delay. I've had some hardware problems.

Heres the LogCat output. I can't see much from it.

05-04 18:53:17.473 2160-2160/com.temp.temp.gamelibary I/art: Not late-enabling -Xcheck:jni (already on)
05-04 18:53:17.496 2160-2160/com.temp.temp.gamelibary W/ActivityThread: Application com.temp.temp.gamelibary is waiting for the debugger on port 8100...
05-04 18:53:17.536 2160-2160/com.temp.temp.gamelibary I/System.out: Sending WAIT chunk
05-04 18:53:17.660 2160-2166/com.temp.temp.gamelibary I/art: Debugger is active
05-04 18:53:17.751 2160-2160/com.temp.temp.gamelibary I/System.out: Debugger has connected
05-04 18:53:17.751 2160-2160/com.temp.temp.gamelibary I/System.out: waiting for debugger to settle...
05-04 18:53:17.962 2160-2160/com.temp.temp.gamelibary I/System.out: waiting for debugger to settle...
05-04 18:53:18.172 2160-2160/com.temp.temp.gamelibary I/System.out: waiting for debugger to settle...
05-04 18:53:18.382 2160-2160/com.temp.temp.gamelibary I/System.out: waiting for debugger to settle...
05-04 18:53:18.592 2160-2160/com.temp.temp.gamelibary I/System.out: waiting for debugger to settle...
05-04 18:53:18.802 2160-2160/com.temp.temp.gamelibary I/System.out: waiting for debugger to settle...
05-04 18:53:19.011 2160-2160/com.temp.temp.gamelibary I/System.out: waiting for debugger to settle...
05-04 18:53:19.221 2160-2160/com.temp.temp.gamelibary I/System.out: waiting for debugger to settle...
05-04 18:53:19.431 2160-2160/com.temp.temp.gamelibary I/System.out: waiting for debugger to settle...
05-04 18:53:19.641 2160-2160/com.temp.temp.gamelibary I/System.out: debugger has settled (1353)
05-04 18:53:19.644 2160-2160/com.temp.temp.gamelibary W/System: ClassLoader referenced unknown path: /data/app/com.temp.temp.gamelibary-1/lib/x86
05-04 18:53:19.772 2160-2259/com.temp.temp.gamelibary D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
05-04 18:53:19.813 2160-2259/com.temp.temp.gamelibary I/OpenGLRenderer: Initialized EGL, version 1.4
05-04 18:53:19.862 2160-2259/com.temp.temp.gamelibary W/EGL_emulation: eglSurfaceAttrib not implemented
05-04 18:53:19.862 2160-2259/com.temp.temp.gamelibary W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xabf6c360, error=EGL_SUCCESS
05-04 18:54:13.231 2160-2170/com.temp.temp.gamelibary W/art: Suspending all threads took: 8.054ms
05-04 18:54:13.786 2160-2170/com.temp.temp.gamelibary I/art: Background partial concurrent mark sweep GC freed 133(10KB) AllocSpace objects, 0(0B) LOS objects, 39% free, 3MB/5MB, paused 10.891ms total 20.441ms
05-04 18:54:14.163 2160-2166/com.temp.temp.gamelibary W/art: Suspending all threads took: 5.693ms
 
There's still no stack trace.

What actually happens with your app? Does it crash?
 
Back
Top Bottom