0

I am creating an Android application that runs three fragments that contain one listview in each. currently, I am trying to populate one of the listviews with content from a table that I created on Parse.com. I followed this tutorial: http://www.androidbegin.com/tutorial/android-parse-com-listview-images-and-texts-tutorial/ and applied it to work in my fragment. The problem is though, everytime I run my application, it loads the data for about 3 seconds and then suddenly crashes and gives me this error:

ddmlib: Broken pipe
java.io.IOException: Broken pipe
    at sun.nio.ch.FileDispatcher.write0(Native Method)
    at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:29)
    at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:69)
    at sun.nio.ch.IOUtil.write(IOUtil.java:40)
    at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:336)
    at com.android.ddmlib.JdwpPacket.writeAndConsume(JdwpPacket.java:213)
    at com.android.ddmlib.Client.sendAndConsume(Client.java:642)
    at com.android.ddmlib.HandleHeap.sendREAQ(HandleHeap.java:348)
    at com.android.ddmlib.Client.requestAllocationStatus(Client.java:488)
    at com.android.ddmlib.DeviceMonitor.createClient(DeviceMonitor.java:835)
    at com.android.ddmlib.DeviceMonitor.openClient(DeviceMonitor.java:803)
    at com.android.ddmlib.DeviceMonitor.processIncomingJdwpData(DeviceMonitor.java:763)
    at com.android.ddmlib.DeviceMonitor.deviceClientMonitorLoop(DeviceMonitor.java:652)
    at com.android.ddmlib.DeviceMonitor.access$100(DeviceMonitor.java:44)
    at com.android.ddmlib.DeviceMonitor$3.run(DeviceMonitor.java:580)

I have absolutely no idea why I am receiving this error. Here is the code from the fragment in which I am trying to populate my listview from. I am aslo using a custom adapter for the listview but I am using the same one from another project of mine so I am sure that is working fine. To fetch the data, I am calling new RemoteDataTask().execute(); in onCreateView . This is where I believe it is going wrong. I am also sure all my table names are correct in my parse database.

public class fraternitiesFragment extends Fragment {

    private SwipeRefreshLayout swipeLayoutFraternities;
    private ListView fratList;
    List<ParseObject> objList;
    ProgressDialog mProgressDialog;
    fraternitiesAdapter fratAdapter;
    private List<Frat> fraternitiesList = null;
    public fraternitiesFragment()
    {

    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.frat_fragment, null);


        // Retrieve the SwipeRefreshLayout and ListView instances
        swipeLayoutFraternities = (SwipeRefreshLayout)view.findViewById(R.id.swipe_refresh_fraternities);
        swipeLayoutFraternities.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                new Handler().postDelayed(new Runnable() {
                    @Override public void run() {
                        swipeLayoutFraternities.setRefreshing(false);
                    }
                }, 3000);
            }
        });
        // Set the color scheme of the SwipeRefreshLayout by providing 4 color resource ids
        swipeLayoutFraternities.setColorScheme(
                R.color.tech_blue,
                R.color.tech_gold,
                R.color.tech_blue,
                R.color.tech_gold);

        new RemoteDataTask().execute();
        return view;

    }


    private class RemoteDataTask extends AsyncTask<Void, Void, Void> {
        @Override
        protected void onPreExecute() {
            super.onPreExecute();

            mProgressDialog = new ProgressDialog(getActivity());
            mProgressDialog.setTitle("Loading Fraternities");
            mProgressDialog.setMessage("Loading...");
            mProgressDialog.setIndeterminate(false);
            mProgressDialog.show();
        }

        @Override
        protected Void doInBackground(Void... params) {
            fraternitiesList = new ArrayList<Frat>();
            try{

                ParseQuery<ParseObject> fraternitiesQuery = new ParseQuery<ParseObject>("Fraternities");
                Log.i("Query", " Created");
                fraternitiesQuery.orderByAscending("fratName");
                objList = fraternitiesQuery.find();
                for(ParseObject Fraternity : objList)
                {
                    Frat fraternity = new Frat();
                    fraternity.setFratName((String) Fraternity.get("fratName"));
                    fraternity.setVoteCount((Integer) Fraternity.get("VoteCount"));
                    fraternitiesList.add(fraternity);
                }

            } catch (ParseException e)
            {
                Log.e("Error", e.getMessage());
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void result)
        {
            fratList = (ListView)getActivity().findViewById(R.id.frat_list);
            fratAdapter = new fraternitiesAdapter(getActivity(), fraternitiesList);
            Log.d("Adapter Created", "Created");
            mProgressDialog.dismiss();
            fratList.setAdapter(fratAdapter);

        }
    }

}

I really need help figuring out what is going wrong here that is leading to this Broken Pipe error. Any help or feedback is greatly appreciated!

Rbro112
  • 247
  • 1
  • 2
  • 9

1 Answers1

0

Parse has already async methods, Try this

 ParseQuery<ParseObject> query = ParseQuery.getQuery("Fraternities");
        query.findInBackground(new FindCallback<ParseObject>() {
            public void done(List<ParseObject> fraternityList, ParseException e) {
                // Do your work here
            }
        });
Viswanath Lekshmanan
  • 9,945
  • 1
  • 40
  • 64
  • So should I replace my whole RemoteDataTask class with this code or put this inside of the class? And does this method fetch all the data from the table and place it into the List fraternityList? – Rbro112 Jun 09 '14 at 04:50
  • You can try removing your query part and replace with this. If it is working try to replace whole – Viswanath Lekshmanan Jun 09 '14 at 05:01
  • I actually got it to work with my code above simply by fixing an error in variable types in my Listview adapter, but unfortunately now I am only returning the first row of the table. Does the method above fetch all the rows? – Rbro112 Jun 09 '14 at 05:25
  • Yes absolutely, it will fetch all – Viswanath Lekshmanan Jun 09 '14 at 05:29