I’ve just started using Backendless, and I created a simple timer to see how the custom business logic works. All the code does is save the current time as a string into a data table every minute (so I don’t have to wait around for something to happen). However, I keep on getting the error “Unable to adapt response to <classname>”. I’ve looked at other similar problems, which have generally suggested solutions along the lines of making sure that your class has a default constructor without parameters as well as getter/setter methods, but despite doing this, the error still persists. (New rows are added to the table, but without the timestamp column.) This is my code:
package com.myapp.timers;
import com.backendless.Backendless;
import com.backendless.logging.LogBuffer;
import com.backendless.logging.Logger;
import com.backendless.servercode.annotation.BackendlessTimer;
import java.util.Date;
/**
* TestTimer is a timer.
* It is executed according to the schedule defined in Backendless Console. The
* class becomes a timer by extending the TimerExtender class. The information
* about the timer, its name, schedule, expiration date/time is configured in
* the special annotation - BackendlessTimer. The annotation contains a JSON
* object which describes all properties of the timer.
*/
@BackendlessTimer("{'startDate':1469567100000,'frequency':{'schedule':'custom','repeat':{'every':60}},'timername':'test'}")
public class TestTimer extends com.backendless.servercode.extension.TimerExtender
{
@Override
public void execute( String appVersionId ) throws Exception
{
LogBuffer.getInstance().setLogReportingPolicy(1, 0);
final Logger log = Logger.getLogger(TestTimer.class);
Test test = new Test();
test.setTimestamp(new Date().toString());
Backendless.Persistence.of(Test.class).save(test);
log.info("Logged.");
}
}
class Test {
String timestamp;
public Test() {
super();
}
public void setTimestamp(String timestamp) {
this.timestamp = timestamp;
}
public String getTimestamp() {
return timestamp;
}
}
Did I miss something? Thanks in advance.
Test class should be public and nested
If by nested, you mean nested within TestTimer, then I tried that and it gave me the error “Cannot use inner or anonymous classes. Make sure the class is public. It cannot be inner or anonymous”. This is what my code looks like now:
@BackendlessTimer("{'startDate':1469567100000,'frequency':{'schedule':'custom','repeat':{'every':60}},'timername':'test'}")
public class TestTimer extends com.backendless.servercode.extension.TimerExtender
{
@Override
public void execute( String appVersionId ) throws Exception
{
LogBuffer.getInstance().setLogReportingPolicy(1, 0);
final Logger log = Logger.getLogger(TestTimer.class);
Test test = new Test();
test.setTimestamp(new Date().toString());
Backendless.Persistence.of(Test.class).save(test);
log.info("Logged.");
}
public class Test {
String timestamp;
public Test() {
super();
}
public void setTimestamp(String timestamp) {
this.timestamp = timestamp;
}
public String getTimestamp() {
return timestamp;
}
}
}
By nested I mean it should not be a part of any other class
That solved the issue, thanks so much! One final question: it doesn’t appear to be logging properly. I checked the logging folder in the server files, and while it does show logs from some of my other test code, “Logged.” never shows up anywhere. Why is this?
I Also Got The Error Message "Unable To Adapt The Response to " but my information got updated in list …Why this fault message pop up?
package hello.tech.sampark;
import java.util.Date;
public class Info {
private String name;
private String mail;
private String optional;
private String address;
private String date;
private String number;
private Date updated;
private Date objectId;
private String userEmail;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMail() {
return mail;
}
public void setMail(String mail) {
this.mail = mail;
}
public String getOptional() {
return optional;
}
public void setOptional(String optional) {
this.optional = optional;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public Date getUpdated() {
return updated;
}
public void setUpdated(Date updated) {
this.updated = updated;
}
public Date getObjectId() {
return objectId;
}
public void setObjectId(Date objectId) {
this.objectId = objectId;
}
public String getUserEmail() {
return userEmail;
}
public void setUserEmail(String userEmail) {
this.userEmail = userEmail;
}
}