Nativescript doInBackground 抛出并导致 OutOfMemory 错误
Nativescript doInBackground Thrown and Cause OutOfMemory Error
我刚接触 nativescript 并开发了几个月的程序。我遇到了同样的错误,我正在使用 radList 视图和 Web 图像缓存插件。我们得到了一个 api 用于发送产品及其图像和大约 500kb 的图像。我正在从他们的类别中制作标签,在类别中我正在为每个类别制作列表视图并在其中列出产品。我的代码就是这样;
var tabView = page.getViewById("tabViewContainer");
var meal_list = config.meal_list;
meal_list.forEach(function (item) {
var items = new observable_array_1.ObservableArray();
item.meal_list.forEach(function (item2) {
items.push(new DataItemWithImage(item2.meal_id, item2.meal_name, item2.meal_cost,"http://sezginserpen.com.tr/test_image/" + item2.meal_id + ".jpg"));
// items.push(new DataItemWithImage(item2.meal_id, item2.meal_name, item2.meal_cost,"http://pngimg.com/upload/pizza_PNG7132.png"));
});
var wrapLayout = new wrapLayoutModule.WrapLayout();
var radListView = new listViewModule.RadListView();
var layoutBase = new listViewModule.ListViewGridLayout();
layoutBase.scrollDirection = "Vertical";
layoutBase.spanCount = 2;
wrapLayout.className = "item";
wrapLayout.orientation = "horizontal";
radListView.listViewLayout = layoutBase;
radListView.items = items;//<IC:WebImage stretch="fill" height="250" class="my-image-1" src="{{ image }}></IC:WebImage>
radListView.itemTemplate = '<Border xmlns:IC="nativescript-web-image-cache" borderWidth="0.5" borderColor="lightgray"><stack-layout orientation="vertical" height="250" ><IC:WebImage horizontalAlignment="center" src="{{ image }}"></IC:WebImage><stack-layout width="100%" height="50%"> <label id="product_id_label" text="{{ id }}" style="visibility: collapsed" /><label class="align_center product_label" textWrap="true" text="{{ itemName }}" /> <label class="align_center product_label" textWrap="true" style="color:lightgray" text="{{ itemDescription }}" /> <Border borderWidth="1" borderColor="green" borderRadius="2" style="height:22%;width:95%"> <label tap="add_to_basket" class="align_center" style="background-color:white;color:green;" text="Sepete Ekle" /> </Border> </stack-layout> </stack-layout> </Border>';
wrapLayout.addChild(radListView);
var tabViewItem = new tabViewModule.TabViewItem();
tabViewItem.title = item.category.category_name,
tabViewItem.view = wrapLayout;
var tabView = page.getViewById("tabViewContainer");
tabView.items.push(tabViewItem);
});
AND XML 赞;
<drawer:rad-side-drawer id="drawer">
<drawer:rad-side-drawer.mainContent>
<!-- Home page contents -->
<stack-layout loaded="contentLoaded">
<TabView id="tabViewContainer" selectedIndex="{{ index }}" selectedColor="#d43b2b" selectedIndexChanged="change" tabsBackgroundColor="#ffffff" >
<TabView.items>
</TabView.items>
</TabView>
</stack-layout>
</drawer:rad-side-drawer.mainContent>
<drawer:rad-side-drawer.drawerContent>
<widgets:drawer-content />
</drawer:rad-side-drawer.drawerContent>
</drawer:rad-side-drawer>
知道是什么原因造成的吗?我正在使用 ımagecache,但每次都得到这个。还有我的 Stack Trace1 之一:
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask.done(AsyncTask.java:309)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)Caused by: java.lang.OutOfMemoryError: Failed to allocate a 14745612 byte allocation with 12939040 free bytes and 12MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeByteArray(Native Method)
at android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:763)
at org.nativescript.widgets.Async$Http$RequestResult.readResponseStream(Async.java:225)
at org.nativescript.widgets.Async$Http$HttpRequestTask.doInBackground(Async.java:303)
at org.nativescript.widgets.Async$Http$HttpRequestTask.doInBackground(Async.java:253)
at android.os.AsyncTask.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
... 3 more
轨迹 2:
java.lang.OutOfMemoryError: Failed to allocate a 1508364 byte allocation with 301952 free bytes and 294KB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:975)
at android.graphics.Bitmap.createBitmap(Bitmap.java:946)
at android.graphics.Bitmap.createBitmap(Bitmap.java:913)
at com.facebook.imagepipeline.memory.BitmapPool.alloc(BitmapPool.java:55)
at com.facebook.imagepipeline.memory.BitmapPool.alloc(BitmapPool.java:30)
at com.facebook.imagepipeline.memory.BasePool.get(BasePool.java:259)
at com.facebook.imagepipeline.platform.ArtDecoder.decodeStaticImageFromStream(ArtDecoder.java:137)
at com.facebook.imagepipeline.platform.ArtDecoder.decodeFromEncodedImage(ArtDecoder.java:81)
at com.facebook.imagepipeline.decoder.ImageDecoder.decodeStaticImage(ImageDecoder.java:128)
at com.facebook.imagepipeline.decoder.ImageDecoder.decodeImage(ImageDecoder.java:94)
at com.facebook.imagepipeline.producers.DecodeProducer$ProgressiveDecoder.doDecode(DecodeProducer.java:194)
at com.facebook.imagepipeline.producers.DecodeProducer$ProgressiveDecoder.access0(DecodeProducer.java:97)
at com.facebook.imagepipeline.producers.DecodeProducer$ProgressiveDecoder.run(DecodeProducer.java:129)
at com.facebook.imagepipeline.producers.JobScheduler.doJob(JobScheduler.java:207)
at com.facebook.imagepipeline.producers.JobScheduler.access[=13=]0(JobScheduler.java:27)
at com.facebook.imagepipeline.producers.JobScheduler.run(JobScheduler.java:78)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at com.facebook.imagepipeline.core.PriorityThreadFactory.run(PriorityThreadFactory.java:43)
at java.lang.Thread.run(Thread.java:818)
这是另一个,与此错误类型无关,但我也知道了:
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.bringToFront()' on a null object reference
at com.telerik.android.primitives.widget.sidedrawer.transitions.DrawerTransitionBase.setProgress(DrawerTransitionBase.java:77)
at com.telerik.android.primitives.widget.sidedrawer.transitions.DrawerTransitionBase.onEnded(DrawerTransitionBase.java:226)
at com.telerik.android.primitives.widget.sidedrawer.transitions.DrawerTransitionBase.run(DrawerTransitionBase.java:221)
at android.view.ViewPropertyAnimator$AnimatorEventListener.onAnimationEnd(ViewPropertyAnimator.java:1119)
at android.animation.ValueAnimator.endAnimation(ValueAnimator.java:1239)
at android.animation.ValueAnimator$AnimationHandler.doAnimationFrame(ValueAnimator.java:766)
at android.animation.ValueAnimator$AnimationHandler.run(ValueAnimator.java:801)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:920)
at android.view.Choreographer.doCallbacks(Choreographer.java:695)
at android.view.Choreographer.doFrame(Choreographer.java:628)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:906)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7229)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
关于如何捕获此类错误的任何想法?
感谢您的帮助。
下面的示例显示了如何从 iOS 和 Android 的 NativeScirpt 中的 TabView 中删除选项卡。
主要-page.xml
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo">
<TabView id="tabViewContainer" loaded="tabviewLoaded">
<TabView.items>
<TabViewItem title="">
<TabViewItem.view>
<Label text="This is Label in Tab 1" />
</TabViewItem.view>
</TabViewItem>
<TabViewItem title="">
<TabViewItem.view>
<Label text="This is Label in Tab 2" />
</TabViewItem.view>
</TabViewItem>
</TabView.items>
</TabView>
</Page>
主要-page.ts
import { EventData } from "data/observable";
import { Page } from "ui/page";
import {TabView} from "ui/tab-view";
import {isAndroid, isIOS} from "platform"
export function tabviewLoaded(args:EventData){
var tabview =<any> args.object;
if(isAndroid){
var tabViewgrid = tabview._grid;
console.dump(tabViewgrid.removeViewAt(0));
}
if(isIOS){
tabview._ios.tabBar.hidden = true;
}
}
主要-page.js
var platform_1 = require("platform");
function tabviewLoaded(args) {
var tabview = args.object;
if (platform_1.isAndroid) {
var tabViewgrid = tabview._grid;
console.dump(tabViewgrid.removeViewAt(0));
}
if (platform_1.isIOS) {
tabview._ios.tabBar.hidden = true;
}
}
exports.tabviewLoaded = tabviewLoaded;
我刚接触 nativescript 并开发了几个月的程序。我遇到了同样的错误,我正在使用 radList 视图和 Web 图像缓存插件。我们得到了一个 api 用于发送产品及其图像和大约 500kb 的图像。我正在从他们的类别中制作标签,在类别中我正在为每个类别制作列表视图并在其中列出产品。我的代码就是这样;
var tabView = page.getViewById("tabViewContainer");
var meal_list = config.meal_list;
meal_list.forEach(function (item) {
var items = new observable_array_1.ObservableArray();
item.meal_list.forEach(function (item2) {
items.push(new DataItemWithImage(item2.meal_id, item2.meal_name, item2.meal_cost,"http://sezginserpen.com.tr/test_image/" + item2.meal_id + ".jpg"));
// items.push(new DataItemWithImage(item2.meal_id, item2.meal_name, item2.meal_cost,"http://pngimg.com/upload/pizza_PNG7132.png"));
});
var wrapLayout = new wrapLayoutModule.WrapLayout();
var radListView = new listViewModule.RadListView();
var layoutBase = new listViewModule.ListViewGridLayout();
layoutBase.scrollDirection = "Vertical";
layoutBase.spanCount = 2;
wrapLayout.className = "item";
wrapLayout.orientation = "horizontal";
radListView.listViewLayout = layoutBase;
radListView.items = items;//<IC:WebImage stretch="fill" height="250" class="my-image-1" src="{{ image }}></IC:WebImage>
radListView.itemTemplate = '<Border xmlns:IC="nativescript-web-image-cache" borderWidth="0.5" borderColor="lightgray"><stack-layout orientation="vertical" height="250" ><IC:WebImage horizontalAlignment="center" src="{{ image }}"></IC:WebImage><stack-layout width="100%" height="50%"> <label id="product_id_label" text="{{ id }}" style="visibility: collapsed" /><label class="align_center product_label" textWrap="true" text="{{ itemName }}" /> <label class="align_center product_label" textWrap="true" style="color:lightgray" text="{{ itemDescription }}" /> <Border borderWidth="1" borderColor="green" borderRadius="2" style="height:22%;width:95%"> <label tap="add_to_basket" class="align_center" style="background-color:white;color:green;" text="Sepete Ekle" /> </Border> </stack-layout> </stack-layout> </Border>';
wrapLayout.addChild(radListView);
var tabViewItem = new tabViewModule.TabViewItem();
tabViewItem.title = item.category.category_name,
tabViewItem.view = wrapLayout;
var tabView = page.getViewById("tabViewContainer");
tabView.items.push(tabViewItem);
});
AND XML 赞;
<drawer:rad-side-drawer id="drawer">
<drawer:rad-side-drawer.mainContent>
<!-- Home page contents -->
<stack-layout loaded="contentLoaded">
<TabView id="tabViewContainer" selectedIndex="{{ index }}" selectedColor="#d43b2b" selectedIndexChanged="change" tabsBackgroundColor="#ffffff" >
<TabView.items>
</TabView.items>
</TabView>
</stack-layout>
</drawer:rad-side-drawer.mainContent>
<drawer:rad-side-drawer.drawerContent>
<widgets:drawer-content />
</drawer:rad-side-drawer.drawerContent>
</drawer:rad-side-drawer>
知道是什么原因造成的吗?我正在使用 ımagecache,但每次都得到这个。还有我的 Stack Trace1 之一:
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask.done(AsyncTask.java:309)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)Caused by: java.lang.OutOfMemoryError: Failed to allocate a 14745612 byte allocation with 12939040 free bytes and 12MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeByteArray(Native Method)
at android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:763)
at org.nativescript.widgets.Async$Http$RequestResult.readResponseStream(Async.java:225)
at org.nativescript.widgets.Async$Http$HttpRequestTask.doInBackground(Async.java:303)
at org.nativescript.widgets.Async$Http$HttpRequestTask.doInBackground(Async.java:253)
at android.os.AsyncTask.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
... 3 more
轨迹 2:
java.lang.OutOfMemoryError: Failed to allocate a 1508364 byte allocation with 301952 free bytes and 294KB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:975)
at android.graphics.Bitmap.createBitmap(Bitmap.java:946)
at android.graphics.Bitmap.createBitmap(Bitmap.java:913)
at com.facebook.imagepipeline.memory.BitmapPool.alloc(BitmapPool.java:55)
at com.facebook.imagepipeline.memory.BitmapPool.alloc(BitmapPool.java:30)
at com.facebook.imagepipeline.memory.BasePool.get(BasePool.java:259)
at com.facebook.imagepipeline.platform.ArtDecoder.decodeStaticImageFromStream(ArtDecoder.java:137)
at com.facebook.imagepipeline.platform.ArtDecoder.decodeFromEncodedImage(ArtDecoder.java:81)
at com.facebook.imagepipeline.decoder.ImageDecoder.decodeStaticImage(ImageDecoder.java:128)
at com.facebook.imagepipeline.decoder.ImageDecoder.decodeImage(ImageDecoder.java:94)
at com.facebook.imagepipeline.producers.DecodeProducer$ProgressiveDecoder.doDecode(DecodeProducer.java:194)
at com.facebook.imagepipeline.producers.DecodeProducer$ProgressiveDecoder.access0(DecodeProducer.java:97)
at com.facebook.imagepipeline.producers.DecodeProducer$ProgressiveDecoder.run(DecodeProducer.java:129)
at com.facebook.imagepipeline.producers.JobScheduler.doJob(JobScheduler.java:207)
at com.facebook.imagepipeline.producers.JobScheduler.access[=13=]0(JobScheduler.java:27)
at com.facebook.imagepipeline.producers.JobScheduler.run(JobScheduler.java:78)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at com.facebook.imagepipeline.core.PriorityThreadFactory.run(PriorityThreadFactory.java:43)
at java.lang.Thread.run(Thread.java:818)
这是另一个,与此错误类型无关,但我也知道了:
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.bringToFront()' on a null object reference
at com.telerik.android.primitives.widget.sidedrawer.transitions.DrawerTransitionBase.setProgress(DrawerTransitionBase.java:77)
at com.telerik.android.primitives.widget.sidedrawer.transitions.DrawerTransitionBase.onEnded(DrawerTransitionBase.java:226)
at com.telerik.android.primitives.widget.sidedrawer.transitions.DrawerTransitionBase.run(DrawerTransitionBase.java:221)
at android.view.ViewPropertyAnimator$AnimatorEventListener.onAnimationEnd(ViewPropertyAnimator.java:1119)
at android.animation.ValueAnimator.endAnimation(ValueAnimator.java:1239)
at android.animation.ValueAnimator$AnimationHandler.doAnimationFrame(ValueAnimator.java:766)
at android.animation.ValueAnimator$AnimationHandler.run(ValueAnimator.java:801)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:920)
at android.view.Choreographer.doCallbacks(Choreographer.java:695)
at android.view.Choreographer.doFrame(Choreographer.java:628)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:906)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7229)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
关于如何捕获此类错误的任何想法?
感谢您的帮助。
下面的示例显示了如何从 iOS 和 Android 的 NativeScirpt 中的 TabView 中删除选项卡。
主要-page.xml
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo">
<TabView id="tabViewContainer" loaded="tabviewLoaded">
<TabView.items>
<TabViewItem title="">
<TabViewItem.view>
<Label text="This is Label in Tab 1" />
</TabViewItem.view>
</TabViewItem>
<TabViewItem title="">
<TabViewItem.view>
<Label text="This is Label in Tab 2" />
</TabViewItem.view>
</TabViewItem>
</TabView.items>
</TabView>
</Page>
主要-page.ts
import { EventData } from "data/observable";
import { Page } from "ui/page";
import {TabView} from "ui/tab-view";
import {isAndroid, isIOS} from "platform"
export function tabviewLoaded(args:EventData){
var tabview =<any> args.object;
if(isAndroid){
var tabViewgrid = tabview._grid;
console.dump(tabViewgrid.removeViewAt(0));
}
if(isIOS){
tabview._ios.tabBar.hidden = true;
}
}
主要-page.js
var platform_1 = require("platform");
function tabviewLoaded(args) {
var tabview = args.object;
if (platform_1.isAndroid) {
var tabViewgrid = tabview._grid;
console.dump(tabViewgrid.removeViewAt(0));
}
if (platform_1.isIOS) {
tabview._ios.tabBar.hidden = true;
}
}
exports.tabviewLoaded = tabviewLoaded;