0

I get this error while I am creating a read request object DataReadRequest class. I tried to look for the documentation but it is unclear. Here is my code:

 DataReadRequest readRequest = new DataReadRequest.Builder()
            .read(DataType.TYPE_LOCATION_SAMPLE)
            .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
            .bucketByTime(1, TimeUnit.HOURS)
            .build();

The error is in bucketByTime method and I don't know how to proceed.

lorond
  • 3,856
  • 2
  • 37
  • 52
  • Your [error](https://developer.android.com/reference/java/lang/IllegalStateException.html) states that you are attempting to write output stream after response has been committed. *"Signals that a method has been invoked at an illegal or inappropriate time. In other words, the Java environment or Java application is not in an appropriate state for the requested operation."* To solve this problem, try including return statement immediately after send redirect or forward statement. Check this [tutorial](http://quabr.com/37820404/google-fit-api-getting-calories-burned-per-activity). – abielita Jul 27 '16 at 14:54

1 Answers1

5

I had this error before. The short answer is to remove the line

    .bucketByTime(1, TimeUnit.HOURS)

The reason why this does not work with your request is that the bucketByTime method aggregates data according to the period of time you're asking for, but the data you're requesting can't be aggregated (what does it mean to add together location samples??). In fact all the bucketing methods expect an aggregate data type because bucketing implies that you're trying to represent a number of data points as one data point.

Matthew Woo
  • 1,288
  • 15
  • 28