Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (482)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (550)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Crazy/Useful - on device debugging idea  (Read 907 times)
0 Members and 1 Guest are viewing this topic.
Offline wooD

Senior Newbie




J2ME Developer


« Posted 2005-01-18 12:48:30 »

I thought I would share a piece of code I used recently in debugging an application on a specific device. It did help solve the problem, but it wasn't pretty. I'm sure it could be more robust, but it worked for me.  Just a note, I'm big on arrays and not using vectors for anything when I code j2me. The device I was debugging on was already close to memory limits so this code uses arrays.  The screen was very small as well and 5 lines was all I could fit.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
  Font msgFont;
  String errorLines[];

  public yourConstructor()
    {  
    msgFont = Font.getFont(Font.FACE_PROPORTIONAL,Font.STYLE_PLAIN,Font.SIZE_SMALL);
    errorLines = new String[5];
    }

  public void addLine(String st)
    {
    int i;
    for (i=1;i<errorLines.length;i++)
      {
      errorLines[i-1] = errorLines[i];
      }
    errorLines[errorLines.length-1] = st;

    System.out.println("added line = "+st);
    this.repaint();
    }

  public void paint(Graphics g)
    {  
    /* Your normal paint code here */


    /* print out and put the error lines to the screen */
    System.out.println("ErrorLines.len="+errorLines.length);
    int top = getHeight()-(errorLines.length*msgFont.getHeight());
    int i;
    for (i=0;i<errorLines.length;i++)
      {
      if (errorLines[i]!=null)
        {
        g.drawString(errorLines[i],2,top,Graphics.LEFT | Graphics.TOP);
        }
      top+=msgFont.getHeight();
      }

    }

  public void codeToTest()
    {
     addLine("This is a test");
    }


I spent some time originally trying to catch System.out so I could just see the messages I was already puting out in the emulator, but security restrictions caused that idea to fail.

Hope this helps someone out there.

Wood

Offline shmoove

Junior Member




Doh!


« Reply #1 - Posted 2005-01-19 06:19:36 »

I have a similar setup with some addition.
On top of displaying the errors on screen, I can also save them in the RMS (and use a second MIDlet in the Suite to read those logs), or send them to a server with will save the data in a database. A few final static booleans control which of the logging methods will be activated from a general purpose raiseError() method:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
private static final boolean LOG_UI = true;
private static final boolean LOG_CONSOLE = true;
private static final boolean LOG_RMS = false;
private static final boolean LOG_NET = false;

public static void raiseError(String error) {
  if (LOG_CONSOLE ) {
    System.out.println(error);
  }
  if (LOG_UI) {
    // something similar to what you did
 }
  if (LOG_RMS) {
    // save the error in the an RMS record
 }
  if (LOG_NET) {
    // send the error to a remote logging server
 }
}

Since the conditions are final variables, the compiler/obfuscator will remove any unused methods from the final application.

shmoove
Offline ribot

Junior Member




Ribot - mobile UI specialist


« Reply #2 - Posted 2005-01-19 19:37:04 »

I have a similar system linked to my static Util.log function using an additonal debug midlet in my suite - very very handy.  You've given me some ideas as to the remote logging which could be very useful.

Could it be feasible to send any logs via bluetooth (not having implemented any bluetooth applications so far)?

http://ribot.co.uk - design agency focused on mobile
http://www.retrospecs.co.uk - online vintage eyewear store
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline shmoove

Junior Member




Doh!


« Reply #3 - Posted 2005-01-20 07:23:54 »

I haven't dabbled into bluetooth either, but I see no reason why it shouldn't work.

shmoove
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CopyableCougar4 (14 views)
2014-08-22 19:31:30

atombrot (28 views)
2014-08-19 09:29:53

Tekkerue (25 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (15 views)
2014-08-16 06:20:21

Tekkerue (22 views)
2014-08-16 06:12:11

Rayexar (61 views)
2014-08-11 02:49:23

BurntPizza (39 views)
2014-08-09 21:09:32

BurntPizza (31 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!