Skip to main content

Application Error when using Resources

7 replies [Last post]
bjbcats
Offline
Joined: 2008-08-05

Hi,

I get an "Application Error" on a Sony Ericsson Z310i when I include this line of code:

Resources r = Resources.open("/" + theme + ".res");

Without it, the obfuscated jar is 81K, with it is 90K, the phone says it has 11Mb of memory. The app runs fine without this line. The app also runs fine using resources on a Samsung A412 and a Motorola V6 MAXX, so I guess it's something in the Java implementation on the SE. According to the SE docs the Z310i uses their "Java 7 Platform" which seems to have all the good stuff.

How might go about tracking what the problem is ?

Thanks,

Bryan

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
bjbcats
Offline
Joined: 2008-08-05

Hi Shai,

Turns out the problem is with obfuscating. Doesn't like Progaurd 4.2 or 4.3beta1 for some reason. App works fine with non-obfuscated code.

I might have a play with some of the Progaurd options to see if I can track it.

Thanks,

Bryan

Shai Almog

Hi,
we had some issues with proguard in the past which we mentioned in
the readme. Try using version 4.0 or 4.0.1 that might help.

> Hi Shai,
>
> Turns out the problem is with obfuscating. Doesn't like Progaurd
> 4.2 or 4.3beta1 for some reason. App works fine with non-obfuscated
> code.
>
> I might have a play with some of the Progaurd options to see if I
> can track it.
>
> Thanks,
>
> Bryan
> [Message sent by forum member 'bjbcats' (bjbcats)]
>
> http://forums.java.net/jive/thread.jspa?messageID=303290
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>

Shai Almog
http://lwuit.blogspot.com/

[att1.html]

yakkity
Offline
Joined: 2009-01-19

Shai,

I'm trying this out by using a cellrenderer which contains 2 containers and each container 2 labels.

Now one of these labels has a description in it, so the text is quite large ... , and I want this one to have the ticker effect. I have used the code given on your blog and the example above, but [b]I can't seem to get in the animate() method of the list.[/b]

Any idea?

Thanks.

Shai Almog

Hi,
SE platform 7 works great for us and is perfectly supported we test
LWUIT on it on a regular basis. Try wrapping your code in try catch
as described here:
http://lwuit.blogspot.com/2008/07/lwuit-porting-and-device-issues.html

However, for SE I would highly recommend using the SE specific tools
and a cable to connect your phone to your PC. This allows you to view
all of the printouts on your console which REALLY helps in debugging.
SE also ships with on device debugging although this is somewhat
flaky and slow but I was able to get it to work a couple of times.

On Oct 3, 2008, at 1:39 PM, lwuit-users@mobileandembedded.org wrote:

> Hi,
>
> I get an "Application Error" on a Sony Ericsson Z310i when I
> include this line of code:
>
> Resources r = Resources.open("/" + theme + ".res");
>
> Without it, the obfuscated jar is 81K, with it is 90K, the phone
> says it has 11Mb of memory. The app runs fine without this line.
> The app also runs fine using resources on a Samsung A412 and a
> Motorola V6 MAXX, so I guess it's something in the Java
> implementation on the SE. According to the SE docs the Z310i uses
> their "Java 7 Platform" which seems to have all the good stuff.
>
> How might go about tracking what the problem is ?
>
> Thanks,
>
> Bryan
> [Message sent by forum member 'bjbcats' (bjbcats)]
>
> http://forums.java.net/jive/thread.jspa?messageID=303135
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>

Shai Almog
http://lwuit.blogspot.com/

[att1.html]

Qunhuan Mei

Hi Shai,

When I show our LWUIT based test app to our designer, he thinks the vertical scrolling animation slows the response so I turned if off by adding lst.setSmoothScrolling(false). But seems to me this has a side effect. It also turns off the cell tickering if applicable, or indeed any other cell animations altogether (it actually stops calling to animate()).

Ideally, I suppose, the List's setSmoothScrolling(false) should only stop scrolling, not tickering or any other animation (i.e. the call to animate() should not be stopped).

The following is a test case using your code from http://lwuit.blogspot.com/2008/06/implementing-selected-item-ticker-in.html. You may comment out the myList.setSmoothScrolling(false) to see the difference.

~~~~~~~~~~~~~~~~~~~~~~~~~

import com.sun.lwuit.Command;
import com.sun.lwuit.Component;
import com.sun.lwuit.Container;

import com.sun.lwuit.geom.Dimension;
import com.sun.lwuit.Display;
import com.sun.lwuit.list.DefaultListCellRenderer;
import com.sun.lwuit.Form;
import com.sun.lwuit.Label;
import com.sun.lwuit.Graphics;

import com.sun.lwuit.animations.Transition;
import com.sun.lwuit.animations.CommonTransitions;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.plaf.Style;

import com.sun.lwuit.List;

import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.layouts.BoxLayout;
import com.sun.lwuit.plaf.UIManager;
import com.sun.lwuit.util.Resources;
import java.util.Hashtable;
import javax.microedition.midlet.MIDlet;

/**
* Bootstraps the UI toolkit demos
*
*/
public class ProblemMIDlet extends MIDlet { //implements ActionListener {//, Painter {

protected void startApp() {

Display.init(this);
Form f = new Form("Ticker List");

final TickerRenderer renderer = new TickerRenderer();

List myList = new List(new String[]{"First", "Second", "Really long string that goes on and on and on and on and on and on",
"and on and on and on and on and on and on and on and on and on and on and on and on",
"Well enough already with the damn long strings this is really getting old...",
"A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 !!!!....."
}) {

private long tickTime = System.currentTimeMillis();
private int lastSelection = -1;

public boolean animate() {
System.out.println(" in animate");
boolean val = super.animate();
if (hasFocus()) {
long currentTime = System.currentTimeMillis();
if (currentTime - tickTime > 300) {
if (lastSelection == getSelectedIndex()) {
renderer.incrementPosition();
} else {
lastSelection = getSelectedIndex();
renderer.resetPosition();
}
return true;
}
}
return val;
}
};
myList.setSmoothScrolling(false);
myList.setListCellRenderer(renderer);
f.setLayout(new BorderLayout());
f.addComponent(BorderLayout.CENTER, myList);
f.show();
}

protected void pauseApp() {
}

protected void destroyApp(boolean arg0) {
}

class TickerRenderer extends DefaultListCellRenderer {

private int position;

public void resetPosition() {
position = 0;
}

public void incrementPosition() {
position += 5;
}

public void paint(Graphics g) {
if (hasFocus()) {
String text = getText();
Style s = getStyle();
int width = s.getFont().stringWidth(text);
if (getWidth() >= width) {
super.paint(g);
return;
}
UIManager.getInstance().getLookAndFeel().setFG(g, this);
int actualPosition = position % width;
g.translate(-actualPosition, 0);
g.drawString(text, getX() + s.getPadding(LEFT), getY());
g.translate(width + 20, 0);
g.drawString(text, getX(), getY());
g.translate(actualPosition - 20 - width, 0);
} else {
super.paint(g);
}
}

public Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected) {
super.getListCellRendererComponent(list, value, index, isSelected);
return this;
}
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~

What do you think?

Many thanks,

Qunhuan

[att1.html]

Shai Almog

Hi,
Its the other way around. setSmoothScrolling(true) which is the
default implicitly registers your component as animated. Setting it
to false doesn't perform the register animated for you. You need to
call form.registerAnimated, which up until now you could get away
without since smooth scrolling did that for you.

> Hi Shai,
>
> When I show our LWUIT based test app to our designer, he thinks the
> vertical scrolling animation slows the response so I turned if off
> by adding lst.setSmoothScrolling(false). But seems to me this has a
> side effect. It also turns off the cell tickering if applicable, or
> indeed any other cell animations altogether (it actually stops
> calling to animate()).
>
> Ideally, I suppose, the List’s setSmoothScrolling(false) should
> only stop scrolling, not tickering or any other animation (i.e. the
> call to animate() should not be stopped).
>
> The following is a test case using your code from http://
> lwuit.blogspot.com/2008/06/implementing-selected-item-ticker-
> in.html. You may comment out the myList.setSmoothScrolling(false)
> to see the difference.
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~
>
> import com.sun.lwuit.Command;
> import com.sun.lwuit.Component;
> import com.sun.lwuit.Container;
>
> import com.sun.lwuit.geom.Dimension;
> import com.sun.lwuit.Display;
> import com.sun.lwuit.list.DefaultListCellRenderer;
> import com.sun.lwuit.Form;
> import com.sun.lwuit.Label;
> import com.sun.lwuit.Graphics;
>
> import com.sun.lwuit.animations.Transition;
> import com.sun.lwuit.animations.CommonTransitions;
> import com.sun.lwuit.events.ActionEvent;
> import com.sun.lwuit.events.ActionListener;
> import com.sun.lwuit.plaf.Style;
>
> import com.sun.lwuit.List;
>
>
> import com.sun.lwuit.layouts.BorderLayout;
> import com.sun.lwuit.layouts.BoxLayout;
> import com.sun.lwuit.plaf.UIManager;
> import com.sun.lwuit.util.Resources;
> import java.util.Hashtable;
> import javax.microedition.midlet.MIDlet;
>
> /**
> * Bootstraps the UI toolkit demos
> *
> */
> public class ProblemMIDlet extends MIDlet { //implements
> ActionListener {//, Painter {
>
> protected void startApp() {
>
> Display.init(this);
> Form f = new Form("Ticker List");
>
> final TickerRenderer renderer = new TickerRenderer();
>
> List myList = new List(new String[]{"First", "Second",
> "Really long string that goes on and on and on and on and on and on",
> "and on and on and on and on and on and on and
> on and on and on and on and on and on",
> "Well enough already with the damn long strings
> this is really getting old...",
> "A B C D E F G H I J K L M N O P Q R S T U V W
> X Y Z 0 1 2 3 4 5 6 7 8 9 !!!!....."
> }) {
>
> private long tickTime = System.currentTimeMillis();
> private int lastSelection = -1;
>
> public boolean animate() {
> System.out.println(" in animate");
> boolean val = super.animate();
> if (hasFocus()) {
> long currentTime = System.currentTimeMillis();
> if (currentTime - tickTime > 300) {
> if (lastSelection == getSelectedIndex()) {
> renderer.incrementPosition();
> } else {
> lastSelection = getSelectedIndex();
> renderer.resetPosition();
> }
> return true;
> }
> }
> return val;
> }
> };
> myList.setSmoothScrolling(false);
> myList.setListCellRenderer(renderer);
> f.setLayout(new BorderLayout());
> f.addComponent(BorderLayout.CENTER, myList);
> f.show();
> }
>
>
> protected void pauseApp() {
> }
>
> protected void destroyApp(boolean arg0) {
> }
>
>
> class TickerRenderer extends DefaultListCellRenderer {
>
> private int position;
>
> public void resetPosition() {
> position = 0;
> }
>
> public void incrementPosition() {
> position += 5;
> }
>
> public void paint(Graphics g) {
> if (hasFocus()) {
> String text = getText();
> Style s = getStyle();
> int width = s.getFont().stringWidth(text);
> if (getWidth() >= width) {
> super.paint(g);
> return;
> }
> UIManager.getInstance().getLookAndFeel().setFG(g,
> this);
> int actualPosition = position % width;
> g.translate(-actualPosition, 0);
> g.drawString(text, getX() + s.getPadding(LEFT), getY
> ());
> g.translate(width + 20, 0);
> g.drawString(text, getX(), getY());
> g.translate(actualPosition - 20 - width, 0);
> } else {
> super.paint(g);
> }
> }
>
> public Component getListCellRendererComponent(List list,
> Object value, int index, boolean isSelected) {
> super.getListCellRendererComponent(list, value, index,
> isSelected);
> return this;
> }
> }
> }
> ~~~~~~~~~~~~~~~~~~~~~~~~~
>
> What do you think?
>
> Many thanks,
>
> Qunhuan
>
>

Shai Almog
http://lwuit.blogspot.com/

[att1.html]

Qunhuan Mei

Hi again Shai,

This time, I truly got what you mean. (I am sorry for being so "slow").

Really much appreciate your help!

Qunhuan

From: Shai.Almog@Sun.COM [mailto:Shai.Almog@Sun.COM]
Sent: 03 October 2008 16:02
To: users@lwuit.dev.java.net
Subject: Re: List's setSmoothScrolling(false) turns all list cell's "animation" off - a problem?

Hi,
Its the other way around. setSmoothScrolling(true) which is the default implicitly registers your component as animated. Setting it to false doesn't perform the register animated for you. You need to call form.registerAnimated, which up until now you could get away without since smooth scrolling did that for you.

Hi Shai,

When I show our LWUIT based test app to our designer, he thinks the vertical scrolling animation slows the response so I turned if off by adding lst.setSmoothScrolling(false). But seems to me this has a side effect. It also turns off the cell tickering if applicable, or indeed any other cell animations altogether (it actually stops calling to animate()).

Ideally, I suppose, the List's setSmoothScrolling(false) should only stop scrolling, not tickering or any other animation (i.e. the call to animate() should not be stopped).

The following is a test case using your code from http://lwuit.blogspot.com/2008/06/implementing-selected-item-ticker-in.html. You may comment out the myList.setSmoothScrolling(false) to see the difference.

~~~~~~~~~~~~~~~~~~~~~~~~~

import com.sun.lwuit.Command;
import com.sun.lwuit.Component;
import com.sun.lwuit.Container;

import com.sun.lwuit.geom.Dimension;
import com.sun.lwuit.Display;
import com.sun.lwuit.list.DefaultListCellRenderer;
import com.sun.lwuit.Form;
import com.sun.lwuit.Label;
import com.sun.lwuit.Graphics;

import com.sun.lwuit.animations.Transition;
import com.sun.lwuit.animations.CommonTransitions;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.plaf.Style;

import com.sun.lwuit.List;

import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.layouts.BoxLayout;
import com.sun.lwuit.plaf.UIManager;
import com.sun.lwuit.util.Resources;
import java.util.Hashtable;
import javax.microedition.midlet.MIDlet;

/**
* Bootstraps the UI toolkit demos
*
*/
public class ProblemMIDlet extends MIDlet { //implements ActionListener {//, Painter {

protected void startApp() {

Display.init(this);
Form f = new Form("Ticker List");

final TickerRenderer renderer = new TickerRenderer();

List myList = new List(new String[]{"First", "Second", "Really long string that goes on and on and on and on and on and on",
"and on and on and on and on and on and on and on and on and on and on and on and on",
"Well enough already with the damn long strings this is really getting old...",
"A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 !!!!....."
}) {

private long tickTime = System.currentTimeMillis();
private int lastSelection = -1;

public boolean animate() {
System.out.println(" in animate");
boolean val = super.animate();
if (hasFocus()) {
long currentTime = System.currentTimeMillis();
if (currentTime - tickTime > 300) {
if (lastSelection == getSelectedIndex()) {
renderer.incrementPosition();
} else {
lastSelection = getSelectedIndex();
renderer.resetPosition();
}
return true;
}
}
return val;
}
};
myList.setSmoothScrolling(false);
myList.setListCellRenderer(renderer);
f.setLayout(new BorderLayout());
f.addComponent(BorderLayout.CENTER, myList);
f.show();
}

protected void pauseApp() {
}

protected void destroyApp(boolean arg0) {
}

class TickerRenderer extends DefaultListCellRenderer {

private int position;

public void resetPosition() {
position = 0;
}

public void incrementPosition() {
position += 5;
}

public void paint(Graphics g) {
if (hasFocus()) {
String text = getText();
Style s = getStyle();
int width = s.getFont().stringWidth(text);
if (getWidth() >= width) {
super.paint(g);
return;
}
UIManager.getInstance().getLookAndFeel().setFG(g, this);
int actualPosition = position % width;
g.translate(-actualPosition, 0);
g.drawString(text, getX() + s.getPadding(LEFT), getY());
g.translate(width + 20, 0);
g.drawString(text, getX(), getY());
g.translate(actualPosition - 20 - width, 0);
} else {
super.paint(g);
}
}

public Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected) {
super.getListCellRendererComponent(list, value, index, isSelected);
return this;
}
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~

What do you think?

Many thanks,

Qunhuan

Shai Almog
http://lwuit.blogspot.com/

[att1.html]