fatal exception asynctask #2 doInBackground - android-asynctask

This code crashes. Why?
#Override
protected String doInBackground(String... params) {
try {
image_compress = image_compress(changed_image);
array_image.add(Effects_change.doColorFilter((image_compress), 0,
1, 0));
array_image.add(Effects_change.doColorFilter((image_compress), 0,
0, 1));
array_image.add(Effects_change.doColorFilter((image_compress), 0,
1.2, 1.8));
array_image.add(Effects_change.doGreyscale(image_compress));
array_image.add(Effects_change.doGamma((image_compress), 0.8, 0.8,
0.8));
array_image.add(Effects_change.doGamma((image_compress), 1.8, 1.8,
1.8));
array_image.add(Effects_change.doColorFilter((image_compress), 1.0,
0, 0));
array_image.add(Effects_change.doColorFilter((image_compress), 0.5,
0.5, 0.5));
array_image.add(Effects_change.doColorFilter((image_compress), 1.5,
1.5, 1.5));
array_image.add(Effects_change.createSepiaToningEffect(
(image_compress), 100, 1.5, 0.6, 0.12));
array_image.add(Effects_change.createSepiaToningEffect(
(image_compress), 100, 0.88, 1.45, 1.43));
array_image.add(Effects_change.createSepiaToningEffect(
(image_compress), 100, 1.2, 0.87, 1.8));
array_image.add(Effects_change.decreaseColorDepth((image_compress),
32));
array_image.add(Effects_change.decreaseColorDepth((image_compress),
120));
array_image.add(Effects_change.applyReflection(image_compress));
//array_image.add(Effects_change.applynewReflection(image_compress));
array_image.add(Effects_change.applyFleaEffect(image_compress));
array_image.add(Effects_change.sharpen((image_compress), 15));
array_image.add(Effects_change.createSepiaToningEffect(
(image_compress), 200, 0.50, 0.6, 0.20));
array_image.add(Effects_change.createSepiaToningEffect(
(image_compress), 150, 1.2, 0.97, 2.1));
array_image.add(Effects_change.applyGaussianBlur(image_compress));
array_image.add(Effects_change.applyBlackFilter(image_compress));
array_image.add(Effects_change.applyMeanRemoval(image_compress));
array_image.add(Effects_change.applySnowEffect(image_compress));
array_image.add(Effects_change.smooth((image_compress), 8));
array_image.add(Effects_change.CharcoalEffect(image_compress));
array_image.add(Effects_change.tintImage((image_compress), 80));
array_image.add(Effects_change.roundCorner((image_compress), 45));
array_image.add(Effects_change.boost((image_compress), 1,
(float) 1.5));
array_image.add(Effects_change.boost((image_compress), 2,
(float) 0.30));
array_image.add(Effects_change.boost((image_compress), 3,
(float) 0.67));
array_image.add(Effects_change.emboss(image_compress));
array_image.add(Effects_change.boost((image_compress), 1,
(float) .50));
array_image.add(Effects_change.boost((image_compress), 2,
(float) 0.10));
array_image.add(Effects_change.boost((image_compress), 3,
(float) 1.5));
array_image.add(Effects_change.engrave(image_compress));
array_image.add(Effects_change.applyHueFilter((image_compress), 3));
array_image.add(Effects_change
.changeToNegativeEffect(image_compress));
array_image.add(Effects_change.SketchImage(image_compress));
array_image.add(Effects_change.doColorFilter(image_compress, 1.8, 1.2, 1));
array_image.add(Effects_change.tintImage((image_compress), 180));
array_image.add(Effects_change.applySaturationFilter(image_compress, 2));
array_image.add(Effects_change.createContrast(image_compress, 100));
array_image.add(Effects_change.applySaturationFilter((image_compress), 90));
// array_image.add(Effects_change.posterize(image_compress, 10));
// setProgress(""+(int)((total*100)/lenghtOfFile));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//array_image.add(Effects_change.setSepiaColorFilter(image_compress));
return null;
}
#Override
public void onPostExecute(String result) {
super.onPostExecute(result);
g.setAdapter(new ImageAdapter(Image_add_effects.this));
g.setOnItemSelectedListener(Image_add_effects.this);
try {
pb.dismiss();
pb=null;
} catch (Exception e) {
// TODO: handle exception
}
}
}
This is the log
04-07 22:36:08.450: W/dalvikvm(18429): threadid=13: thread exiting with uncaught exception(group=0x41fe82a0)
04-07 22:36:08.450: E/AndroidRuntime(18429): FATAL EXCEPTION: AsyncTask #2
04-07 22:36:08.450: E/AndroidRuntime(18429): java.lang.RuntimeException: An error occured while executing doInBackground()
04-07 22:36:08.450: E/AndroidRuntime(18429): at android.os.AsyncTask$3.done(AsyncTask.java:299)
04-07 22:36:08.450: E/AndroidRuntime(18429): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
04-07 22:36:08.450: E/AndroidRuntime(18429): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
04-07 22:36:08.450: E/AndroidRuntime(18429): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
04-07 22:36:08.450: E/AndroidRuntime(18429): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
04-07 22:36:08.450: E/AndroidRuntime(18429): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
04-07 22:36:08.450: E/AndroidRuntime(18429): at java.lang.Thread.run(Thread.java:856)
04-07 22:36:08.450: E/AndroidRuntime(18429): Caused by: java.lang.OutOfMemoryError
How can I resolve this?

The reason is java.lang.OutOfMemoryError meaning your computations eat too much RAM.
However without knowing what you do it is difficult to say what exactly causes the error. Probably you create too many images/bitmaps.
Here is the info on how much RAM is availiable for your app: https://stackoverflow.com/a/9940415/247013
Ideas for investigation:
make use of Bitmap.recycle() - call it whenever you don't need a processed Bitmap
try not to store the images in RAM, persisting them to files instead
looks like you're trying to pre-create an image for any possible effect in advance - consider re-architechting - do one effect only when user explicitly asks for it (on demand).

Related

Regarding to the size() in setup() function

Why I can use size(1920, 1080) in setup()
but If I use
setup()
visualContext = new VisualContext(
new Area(0, 0, 1920, 1080),
new Area(158, 150, 1340, 950)
);
size(visualContext.getGlobalArea().getWidth(), visualContext.getGlobalArea().getHeight());
There will be an error
When not using the PDE, size() can only be used inside settings().
Remove the size() method from setup(), and add the following:
public void settings() {
size(1920, 1080);
}
I can not find any doc about this topic.
Curious, can size only be initialized by constant but variable?
use settings if you want to invoke size with parameters.
VisualContext visualContext = new VisualContext(
new Area(0, 0, 1920, 1080),
new Area(158, 150, 1340, 950)
);
void settings() {
size(visualContext.getGlobalArea().getWidth(), visualContext.getGlobalArea().getHeight()); //<>//
}
https://processing.org/reference/settings_.html

No beacon detected using altbeacon api

One iPhone is used to transmit ibeacon using locate app (the proximity uuid is 2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6). The android phone is used to detect the ibeacon.
When I debug, I can get the following message:
08-30 15:33:57.051 D/BluetoothLeScanner(27939): onScanResult() - ScanResult{mDevice=6D:CC:9D:8D:3A:F3, mScanRecord=ScanRecord [mAdvertiseFlags=26, mServiceUuids=null, mManufacturerSpecificData={76=[2, 21, 47, 35, 68, 84, -49, 109, 74, 15, -83, -14, -12, -111, 27, -87, -1, -90, 0, 0, 0, 0, -59]}, mServiceData={}, mTxPowerLevel=-2147483648, mDeviceName=null], mRssi=-31, mTimestampNanos=58705755631306}
However in function RangingBeaconsInRegion, there is no beacon.
void RangingBeaconsInRegion(object sender, RangeEventArgs e)
{
await ClearData();
var allBeacons = new List<Beacon>();
if (e.Beacons.Count > 0)
{
foreach (var b in e.Beacons)
{
allBeacons.Add(b);
int rssi = b.Rssi;
System.Diagnostics.Debug.WriteLine(rssi.ToString());
}
var orderedBeacons = allBeacons.OrderBy(b => b.Distance).ToList();
await UpdateData(orderedBeacons);
}
else
{
// unknown
await ClearData();
}
}
The following is my implementation:
public class MainActivity : XFormsApplicationDroid, IBeaconConsumer
{
public MainActivity()
{
}
protected override void OnCreate(Bundle bundle)
{
BeaconManager beaconManager = BeaconManager.GetInstanceForApplication(this);
var iBeaconParser = new BeaconParser();
iBeaconParser.SetBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24");
var parser = new BeaconParser();
parser.SetBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25");
beaconManager.BeaconParsers.Add(parser);
beaconManager.Bind(this);
}
public void OnBeaconServiceConnect()
{
//obtain the beaconservie object of android
var beaconService = Xamarin.Forms.DependencyService.Get<IbeaconService>();
beaconService.InitializeService();
//beaconService.StartTransmitting();
beaconService.StartMonitoring();
beaconService.StartRanging();
}
public void InitializeService()
{
m_beaconManager = InitializeBeaconManager();
}
private BeaconManager InitializeBeaconManager()
{
BeaconManager bm = BeaconManager.GetInstanceForApplication(Xamarin.Forms.Forms.Context);
//set the scan window
bm.SetForegroundScanPeriod(1100L);
//subscribe to the events;
m_monitorNotifier.EnterRegionComplete += EnteredRegion;
m_monitorNotifier.ExitRegionComplete += ExitedRegion;
m_monitorNotifier.DetermineStateForRegionComplete += DeterminedStateForRegionComplete;
m_rangeNotifier.DidRangeBeaconsInRegionComplete += RangingBeaconsInRegion;
// constructs a new region object to be used for ranging or monitoring
m_tagRegion = new Region("myUniqueBeaconId", Identifier.Parse("E4C8A4FC-F68B-470D-959F-29382AF72CE7"), null, null);
m_tagRegion = new Region("myUniqueBeaconId", Identifier.Parse("B9407F30-F5F8-466E-AFF9-25556B57FE6D"), null, null);
m_tagRegion = new Region("myUniqueBeaconId", Identifier.Parse("2F234454-CF6d-4A0F-ADF2-F4911BA9FFA6"), null, null);
m_emptyRegion = new Region("myEmptyBeaconId", null, null, null);
bm.SetBackgroundMode(false);
//
//bm.Bind((IBeaconConsumer)Xamarin.Forms.Forms.Context);
return bm;
}
public void StartRanging()
{
BeaconManagerInstance.SetForegroundBetweenScanPeriod(0L);
m_beaconManager.AddRangeNotifier(m_rangeNotifier);
m_beaconManager.StartRangingBeaconsInRegion(m_tagRegion);
m_beaconManager.StartRangingBeaconsInRegion(m_emptyRegion);
}
If you look closely at the code that sets up the beaconParsers, you'll see that two are constructed, but only one is added like this:
beaconManager.BeaconParsers.Add(parser);
Adding a second call to add the other beacon parser should solve the problem.
Thanks, that's my mistake! After I add a second call to add the other beacon parser! there is still some strange situation: I did not launch any beacon transmitter, but when I debug, I got the following output: D/BluetoothLeScanner( 6864): onScanResult() - ScanResult{mDevice=58:D6:74:3A:34:C5, mScanRecord=ScanRecord [mAdvertiseFlags=6, mServiceUuids=null, mManufacturerSpecificData={76=[12, 14, 0, 126, 81, 116, -16, 10, 52, 84, 15, 98, 113, 29, -15, 34]}, mServiceData={}, mTxPowerLevel=-2147483648, mDeviceName=null], mRssi=-89, mTimestampNanos=122142418198514}
08-31 09:11:13.943 D/BluetoothLeScanner( 6864): onScanResult() - ScanResult{mDevice=58:D6:74:3A:34:C5, mScanRecord=ScanRecord [mAdvertiseFlags=6, mServiceUuids=null, mManufacturerSpecificData={76=[12, 14, 0, 126, 81, 116, -16, 10, 52, 84, 15, 98, 113, 29, -15, 34]}, mServiceData={}, mTxPowerLevel=-2147483648, mDeviceName=null], mRssi=-89, mTimestampNanos=122142560625598}. It seems that one beacon is detected.

keyDown() Not working Processing

I'm using Processing to make something and basically my keyDown() is not working. It supposed to be triggered when any key is pressed but the function is not being called. Code below:
int playerno=0; //determines player
boolean ready=true;
void setup() {
size(700, 700);
background(#FFFFFF);
fill(#000000);
textSize(50);
text("Press Any Key To Start", 350, 350);
}
void keyPressed() {
if (ready) {
fill(#FFFFFF);
rect(350, 350, 200, 100);
fill(#000000);
textSize(50);
text("Game Ready", 350, 350);
boolean ready=false;
}
}
This will won't work without draw function. Also you are declaring new local variable ready inside keypressed() this is bad mistake. Try move your drawing code from "keyDown()" into "drawing" like this:
void draw() {
if (ready == false) {
background(#FFFFFF); //This is needed for redrawing whole scene
fill(#FFFFFF);
rect(350, 350, 200, 100);
fill(#000000);
textSize(50);
text("Game Ready", 350, 350);
}
}
void keyPressed() {
if (ready) {
ready=false;
}
}

Switch between Jump and Run animation Andengine

I want switch between Run and Jump animations, but i have some problems :
If the Player run and i tap on the screen, the Player start Jumping (one time), and the Jumpanimation starts but don´t end , so the player is running with the Jumpanimation.
Do you know where my fault is?
My code :
// Runanimation + Player Run
public void setRunning()
{
canRun = true;
final long[] PLAYER_ANIMATE = new long[] { 100, 100, 100,};
animate(PLAYER_ANIMATE, 0, 2, true);
}
// Jumpanimation + Player Jump
public void jump()
{
if (footContacts < 1)
{
return;
}
body.setLinearVelocity(new Vector2(body.getLinearVelocity().x, 10));
final long[] PLAYER_JUMP_ANIMATE = new long[] { 100, 100, 100, 100, 100, 100};
animate(PLAYER_JUMP_ANIMATE, 0, 5,true);
}
Thx Seref
You are animating with loop boolean set to true, which means its keep looping animation. You should have some kinds of flags (booleans) like jumping and running, so inside set running method you should check if jumping equals true, and if so, stopAnimation() and animate using different frames (in this case running)

PAGE_FAULT_IN_NONPAGED_AREA error at KeWaitForSingleObject function

Can this codes cause a problem?(PAGE_FAULT_IN_NONPAGED_AREA)
KEVENT waitEvent; //allocate on stack
LARGE_INTEGER timeout;
KeInitializeEvent(&waitEvent, NotificationEvent, FALSE);
KeResetEvent(&waitEvent);
timeout.QuadPart = -(100 * 10000); // 100 ms
while(pDataChannel->useCount)
{
KeWaitForSingleObject(&waitEvent, Executive, KernelMode, FALSE, &timeout);
}
Can the waitEvent valiable be paged-out?
Is the variable must allocated on a non-paged pool?
Is pDataChannel valid? Or are you running at DISPATCH_LEVEL?
These can lead to the error you have.

Resources