我试图从AsyncTask线程中的ObjectMapper获取一个JSON格式的字符串,并且我一直在获取OutOfMemoryError并且在清单文件中已经添加了行
android:largeHeap="true"
android:hardwareAccelerated="false"
在DoInBackground中执行的AsyncTask方法:
String url = "/plano/fiscalizacao/fiscalizar";
Realm realm = Realm.getDefaultInstance();
Fiscalizacao fiscalizacao = RealmOperations.getFiscalizacaoById(realm, idFiscalizacao);
if (fiscalizacao == null)
return;
ObjectMapper mapper = new ObjectMapperProvider().createDefaultObjectMapper();
String json = mapper.writeValueAsString(fiscalizacao);
StringEntity entity = new StringEntity(json, "UTF-8");
//HttpEntity entity = new ByteArrayEntity(json.getBytes("UTF-8"));
HttpResponse response = WebServiceSupport.post(context, url, entity);
if (WebServiceSupport.validaStatus(response)) {
String str = EntityUtils.toString(response.getEntity(), "UTF-8");
}
Fiscalizacao类:
private static final long serialVersionUID = 1L;
@Nullable
private Date dataFiscalizacao;
@Nullable
private PlanoFiscalizacaoProcesso plano;
@Nullable
private String relatorio;
@Nullable
private Reparticao reparticao;
@PrimaryKey
private Long selfId;
@Nullable
private SyncStatus status_sync;
private TipoGrauAproveitamento tipoGrauAproveitamento;
private TipoMedida tipoMedida;
@Nullable
private Date versionDate;
Stacktrace到im存在的问题:
08-22 14:04:12.623 22737-32404/exi.co.mz.sigit.fiscalizacao E/UncaughtException:
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.OutOfMemoryError: Failed to allocate a 524300 byte allocation with 277842 free bytes and 271KB until OOM
at com.fasterxml.jackson.core.util.TextBuffer._charArray(TextBuffer.java:716)
at com.fasterxml.jackson.core.util.TextBuffer.expand(TextBuffer.java:675)
at com.fasterxml.jackson.core.util.TextBuffer.append(TextBuffer.java:471)
at com.fasterxml.jackson.core.io.SegmentedStringWriter.write(SegmentedStringWriter.java:67)
at com.fasterxml.jackson.core.json.WriterBasedJsonGenerator.writeRaw(WriterBasedJsonGenerator.java:476)
at com.fasterxml.jackson.core.util.DefaultPrettyPrinter$Lf2SpacesIndenter.writeIndentation(DefaultPrettyPrinter.java:382)
at com.fasterxml.jackson.core.util.DefaultPrettyPrinter.writeEndObject(DefaultPrettyPrinter.java:247)
at com.fasterxml.jackson.core.json.WriterBasedJsonGenerator.writeEndObject(WriterBasedJsonGenerator.java:179)
at com.fasterxml.jackson.core.json.WriterBasedJsonGenerator.close(WriterBasedJsonGenerator.java:882)
at com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:2727)
at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:2210)
at exi.co.mz.fiscalizacao.rest.ParcelaClient.setFiscalizacao(ParcelaClient.java:184)
at exi.co.mz.fiscalizacao.rest.ParcelaClient.doInBackground(ParcelaClient.java:239)
at exi.co.mz.fiscalizacao.rest.ParcelaClient.doInBackground(ParcelaClient.java:33)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
08-22 14:04:12.923 22737-32404/exi.co.mz.sigit.fiscalizacao E/AndroidRuntime:
FATAL EXCEPTION: AsyncTask #3
Process: exi.co.mz.sigit.fiscalizacao, PID: 22737
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.OutOfMemoryError: Failed to allocate a 524300 byte allocation with 277842 free bytes and 271KB until OOM
at com.fasterxml.jackson.core.util.TextBuffer._charArray(TextBuffer.java:716)
at com.fasterxml.jackson.core.util.TextBuffer.expand(TextBuffer.java:675)
at com.fasterxml.jackson.core.util.TextBuffer.append(TextBuffer.java:471)
at com.fasterxml.jackson.core.io.SegmentedStringWriter.write(SegmentedStringWriter.java:67)
at com.fasterxml.jackson.core.json.WriterBasedJsonGenerator.writeRaw(WriterBasedJsonGenerator.java:476)
at com.fasterxml.jackson.core.util.DefaultPrettyPrinter$Lf2SpacesIndenter.writeIndentation(DefaultPrettyPrinter.java:382)
at com.fasterxml.jackson.core.util.DefaultPrettyPrinter.writeEndObject(DefaultPrettyPrinter.java:247)
at com.fasterxml.jackson.core.json.WriterBasedJsonGenerator.writeEndObject(WriterBasedJsonGenerator.java:179)
at com.fasterxml.jackson.core.json.WriterBasedJsonGenerator.close(WriterBasedJsonGenerator.java:882)
at com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:2727)
at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:2210)
at exi.co.mz.fiscalizacao.rest.ParcelaClient.setFiscalizacao(ParcelaClient.java:184)
at exi.co.mz.fiscalizacao.rest.ParcelaClient.doInBackground(ParcelaClient.java:239)
at exi.co.mz.fiscalizacao.rest.ParcelaClient.doInBackground(ParcelaClient.java:33)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
我找到解决办法了
在使用Realm时,需要使用.copyFromRealm()从Realm数据库中提取对象
Realm realm = Realm.getDefaultInstance();
Fiscalizacao fiscalizacao = realm.copyFromRealm(RealmOperations.getFiscalizacaoById(realm, idFiscalizacao));
在我向Maven添加了HATEOAS的依赖项之后,Spring Boot不会启动: 添加得依赖项: unsatisfiedDependencyException:创建名为“Security Config”的bean时出错:通过方法“Set ContentNegotationStrategy”参数0表示的不满足依赖项;嵌套异常为org.springframework.beans.factory.un
我正在使用Spring In Action 3 Action学习Spring MVC,我已经实现了显示用户注册表的基本程序,一旦我们提交表单,它将使用进行验证。 这是我的Spring控制器: 这是我的Spitter类文件: 这是我的编辑。显示给用户注册的jsp文件: 要加载表单,我将访问URL为:,一旦表单被加载,我只需提交表单而无需输入任何详细信息,以便我可以检查我的表单是否得到验证。但是我得到
当方法运行时,我希望抛出一个异常(在测试时)。我能做的事情很少: 存根(mock.someMethod(“某些参数”)).ToThrow(new RuntimeException()); 当(mock.someMethod(“某些参数”)).thenThrow(new RuntimeException()) 放弃..... 通常我会创建一个spy对象来调用spied方法。使用stubbing我可以
我正在使用Mockito来模拟服务层的方法。 试图嘲笑以下代码行 为了嘲笑我正在使用的这个 但问题是当代码到达行
问题内容: 我有一些代码需要调试帮助,但我认为,如果我能运行其中之一,我将可以得到其余的代码(哦,我希望如此)。 我正在尝试通过sqlplus在我学校的服务器上运行的表上执行此操作,如果有帮助的话。 问题答案: 遇到错误时,指定什么错误总是有帮助的。触发器中的调用中存在语法错误。该过程需要两个参数,一个数字和一个字符串。您传入的是一个长字符串的单个参数。 假设您的表格中有一列,则该值应有效。