[Java for Android App Development] juan_guardado:
hello i have a problems with app

result

W/System.err﹕ com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected an int but was BOOLEAN at line 1 column 856

code:

private Boolean getCourseInfo() {

CourseSyncTask cs = new CourseSyncTask(mUrl, token, siteInfo.getId());

publishProgress(context.getString(R.string.login_p rog_sync_course));

Boolean usrCourseSyncStatus = cs.syncUserCourses();

if (!usrCourseSyncStatus) {

publishProgress(cs.getError());

publishProgress("\n"

+ context.getString(R.string.login_prog_sync_failed) );

}

return usrCourseSyncStatus;

}

////////////////////////////////////////////////////////////

public class CourseSyncTask {

String mUrl;

String token;

long siteid;

String error;

/**

*

* [MENTION=955119]param[/MENTION] mUrl

* [MENTION=955119]param[/MENTION] token

* [MENTION=955119]param[/MENTION] siteid

*

*/

public CourseSyncTask(String mUrl, String token, long siteid) {

this.mUrl = mUrl;

this.token = token;

this.siteid = siteid;

}

/**

* Sync all the courses in the current site.

*

* [MENTION=2056652]return[/MENTION] syncStatus

*

*/

public Boolean syncAllCourses() {

MoodleRestCourse mrc = new MoodleRestCourse(mUrl, token);

ArrayList<MoodleCourse> mCourses = mrc.getAllCourses();

/** Error checking **/

// Some network or encoding issue.

if (mCourses.size() == 0) {

error = "Network issue!";

return false;

}

// Moodle exception

if (mCourses.size() == 1 && mCourses.get(0).getCourseid() == 0) {

error = "Moodle Exception: User don't have permissions!";

return false;

}

// Add siteid to all courses and update

MoodleCourse course = new MoodleCourse();

List<MoodleCourse> dbCourses;

for (int i = 0; i < mCourses.size(); i++) {

course = mCourses.get(i);

course.setSiteid(siteid);

// Update or save in database

dbCourses = MoodleCourse.find(MoodleCourse.class,

"courseid = ? and siteid = ?", course.getCourseid() + "",

course.getSiteid() + "");

if (dbCourses != null && dbCourses.size() > 0) {

// Set app specific fields explicitly

course.setId(dbCourses.get(0).getId());

course.setIsUserCourse(dbCourses.get(0).getIsUserC ourse());

course.setIsFavCourse(dbCourses.get(0).getIsFavCou rse());

}

course.save();

}

return true;

}

/**

* Sync all courses of logged in user in the current site.

*

* [MENTION=2056652]return[/MENTION] syncStatus

*/

public Boolean syncUserCourses() {

// Get userid

MoodleSiteInfo site = MoodleSiteInfo.findById(MoodleSiteInfo.class,

siteid);

if (site == null)

return false;

int userid = site.getUserid();

MoodleRestCourse mrc = new MoodleRestCourse(mUrl, token);

ArrayList<MoodleCourse> mCourses = mrc.getEnrolledCourses(userid + "");

/** Error checking **/

// Some network or encoding issue.

if (mCourses == null)

return false;

// Some network or encoding issue.

if (mCourses.size() == 0)

return false;

// Moodle exception

if (mCourses.size() == 1 && mCourses.get(0).getCourseid() == 0)

return false;

// Add siteid and isUserCourse to all courses and update

MoodleCourse course = new MoodleCourse();

List<MoodleCourse> dbCourses;

for (int i = 0; i < mCourses.size(); i++) {

course = mCourses.get(i);

course.setSiteid(siteid);

course.setIsUserCourse(true);

// Update or save in database

dbCourses = MoodleCourse.find(MoodleCourse.class,

"courseid = ? and siteid = ?", course.getCourseid() + "",

course.getSiteid() + "");

if (dbCourses.size() > 0) {

// Set app specific fields explicitly

course.setId(dbCourses.get(0).getId());

course.setIsFavCourse(dbCourses.get(0).getIsFavCou rse());

}

course.save();

}

return true;

}

/**

* Error message from the last failed sync operation.

*

* [MENTION=2056652]return[/MENTION] error

*

*/

public String getError() {

return error;

}

}

////////////////////////////////////////////

public class MoodleRestCourse {

private final String DEBUG_TAG = "MoodleRestCourses";

private String mUrl;

private String token;

public MoodleRestCourse(String mUrl, String token) {

this.mUrl = mUrl;

this.token = token;

}

public ArrayList<MoodleCourse> getAllCourses() {

ArrayList<MoodleCourse> mCourses = new ArrayList<MoodleCourse>();

String format = MoodleRestOption.RESPONSE_FORMAT;

String function = MoodleRestOption.FUNCTION_GET_ALL_COURSES;

try {

// Adding all parameters.

String params = "" + URLEncoder.encode("", "UTF-8");

// Build a REST call url to make a call.

String restUrl = mUrl + "/webservice/rest/server.php" + "?wstoken="

+ token + "&wsfunction=" + function

+ "&moodlewsrestformat=" + format;

// Fetch content now.

MoodleRestCall mrc = new MoodleRestCall();

Reader reader = mrc.fetchContent(restUrl, params);

GsonExclude ex = new GsonExclude();

Gson gson = new GsonBuilder()

.addDeserializationExclusionStrategy(ex)

.addSerializationExclusionStrategy(ex).create();

mCourses = gson.fromJson(reader,

new TypeToken<List<MoodleCourse>>() {

}.getType());

reader.close();

} catch (Exception e) {

Log.d(DEBUG_TAG, "URL encoding failed");

e.printStackTrace();

}

return mCourses;

}

public ArrayList<MoodleCourse> getEnrolledCourses(String userId) {

ArrayList<MoodleCourse> mCourses = new ArrayList<MoodleCourse>();

String format = MoodleRestOption.RESPONSE_FORMAT;

String function = MoodleRestOption.FUNCTION_GET_ENROLLED_COURSES;

try {

// Adding all parameters.

String params = "&" + URLEncoder.encode("userid", "UTF-8") + "="

+ userId;

// Build a REST call url to make a call.

String restUrl = mUrl + "/webservice/rest/server.php" + "?wstoken="

+ token + "&wsfunction=" + function

+ "&moodlewsrestformat=" + format;

// Fetch content now.

MoodleRestCall mrc = new MoodleRestCall();

Reader reader = mrc.fetchContent(restUrl, params);

GsonExclude ex = new GsonExclude();

Gson gson = new GsonBuilder()

.addDeserializationExclusionStrategy(ex)

.addSerializationExclusionStrategy(ex).create();

mCourses = gson.fromJson(reader,

new TypeToken<List<MoodleCourse>>() {

}.getType());

reader.close();

} catch (Exception e) {

Log.d(DEBUG_TAG, "URL encoding failed");

e.printStackTrace();

}

return mCourses;

}

}