Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
Posts: 119
Registered: ‎10-23-2009
My Device: Not Specified
Accepted Solution

Error after build in mobile.

I run on simulator success. But after build in mobile : it throw an exception Illegalargument exception. What i must do?

Somebody know how to debug on mobile?

Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Error after build in mobile.

Which part of the code is throwing exception?


Use Search. "Accept Solution" If the problem is resolved.
New Developer
Posts: 119
Registered: ‎10-23-2009
My Device: Not Specified

Re: Error after build in mobile.

Absolutely, i don't know which part of code throw an exception. So i must study how to debug on mobile.

Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Error after build in mobile.

First you could make use of System Outs to know till which part of code is running and what has to be done next.


Use Search. "Accept Solution" If the problem is resolved.
New Developer
Posts: 119
Registered: ‎10-23-2009
My Device: Not Specified

Re: Error after build in mobile.

Can you fix it for me? I will send you my source code Smiley Sad. I must pay a lot of time and create many topic to solve this problem. But now it is not resolved. I think it is not a large problem with you. Please!

Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Error after build in mobile.

If you post your code, any other users will also help you fix the problem.

 

You could give a look at the below sticky thread if you are new to BB development.

 

http://supportforums.blackberry.com/t5/Java-Development/Useful-links-for-novice-and-experienced-prog...


Use Search. "Accept Solution" If the problem is resolved.
New Developer
Posts: 119
Registered: ‎10-23-2009
My Device: Not Specified

Re: Error after build in mobile.

Here is my code make an error : 

 

I think the error appear when i use WebBitmapField and load data to set for. Here is my code, please pay attention to getData method and contructor   : 

 

/*
 * UploadScreen.java
 * 
 * Version: 1.0
 *
 * Created date: 18-Oct-2008
 * 
 * Copyright: N/A
 * 
 * Modification Logs:
 *   DATE        AUTHOR      DESCRIPTION
 *  --------------------------------------------------------
 *  18-Oct-2008  ChienPV     First create
 */
package com.sonic.roxio.blackberry.mpu.ui;

import java.io.IOException;
import java.io.InputStream;
import java.util.Vector;

import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;

import net.rim.device.api.i18n.ResourceBundle;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Characters;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.ContextMenu;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.Screen;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.Menu;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;

import com.sonic.roxio.blackberry.mpu.persistence.Account;
import com.sonic.roxio.blackberry.mpu.persistence.Photoshow;
import com.sonic.roxio.blackberry.mpu.resource.Constants;
import com.sonic.roxio.blackberry.mpu.resource.MobilePhotoUploaderResource;
import com.sonic.roxio.blackberry.mpu.ui.control.PhotoshowList;
import com.sonic.roxio.blackberry.mpu.ui.control.WebBitmapField;
import com.sonic.roxio.blackberry.mpu.ui.control.showButton;
import com.sonic.roxio.blackberry.mpu.util.DebugUtils;
import com.sonic.roxio.blackberry.mpu.util.ImageUtils;
import com.sonic.roxio.blackberry.mpu.util.ServiceUtils;

public class ChoosePhotoshowScreen extends MainScreen implements MobilePhotoUploaderResource, Constants, FieldChangeListener {
        // define resources
        private static ResourceBundle _resources = ResourceBundle.getBundle(BUNDLE_ID, BUNDLE_NAME);

        // for GUI
        private UiApplication uiApplication;
        private Vector elements;
        protected PhotoshowList photoshowList; 
        static Bitmap background = ImageUtils.getBitmapResource("background.png");
        static Bitmap noIcon = ImageUtils.getBitmapResource("noIcon.jpeg");
        showButton[] listOfShow;
        Vector list;
        Vector saveList = new Vector();
        boolean stop = false;
        int first = 0;
        int last = 0;
        StringBuffer rawResponse;
        
        
        VerticalFieldManager verticalContainer = new VerticalFieldManager(
                        USE_ALL_WIDTH | USE_ALL_HEIGHT | Field.FIELD_HCENTER) {
                protected void paintBackground(Graphics graphics) {
                        Manager manager = getManager();
                        int scroll = manager.getVerticalScroll();
                        graphics.drawBitmap(0, scroll, SCREEN_WIDTH, SCREEN_HEIGHT, background, 0, 0);
                };
        };

        HorizontalFieldManager horizontalContainer = new HorizontalFieldManager(
                        USE_ALL_WIDTH | VERTICAL_SCROLL | VERTICAL_SCROLLBAR) {
                
                protected void sublayout(int maxWidth, int maxHeight) {
                        super.sublayout(maxWidth, SCREEN_HEIGHT);
                }
        };
        
        HorizontalFieldManager horizontalContainer1 = new HorizontalFieldManager(
                        USE_ALL_WIDTH | VERTICAL_SCROLL | VERTICAL_SCROLLBAR) {
            
                        protected void sublayout(int maxWidth, int maxHeight) {
                                super.sublayout(maxWidth, SCREEN_HEIGHT);
                        }
        };
        
        LabelField recentShowLabel = new LabelField("Recent ");
        
        WebBitmapField[] image;

    public ChoosePhotoshowScreen(Vector elements, Vector list) {
                    
        super(VERTICAL_SCROLL | VERTICAL_SCROLLBAR);
        VerticalFieldManager showIconManager;
        LabelField titleLabel = new LabelField(_resources.getString(CHOOSE_PHOTOSHOW_SCREEN_TITLE)){
            public void paint(Graphics graphics){
                graphics.setColor(Color.WHITE);
                super.paint(graphics);
            }
        };
        titleLabel.setFont(FONT_BOLD);
    
        HorizontalFieldManager titleManager = new HorizontalFieldManager(FIELD_HCENTER);
        titleManager.add(titleLabel);
                   
        LabelField recentShowLabel = new LabelField("Recent show "){
            public void paint(Graphics graphics){
                    graphics.setColor(Color.WHITE);
                    super.paint(graphics);
            }
            };
        recentShowLabel.setFont(FONT_BOLD);
        HorizontalFieldManager recentShowManager = new HorizontalFieldManager();                
        recentShowManager.add(recentShowLabel);
                            
        LabelField allShowLabel = new LabelField("All shows "){
        public void paint(Graphics graphics){
                graphics.setColor(Color.WHITE);
                super.paint(graphics);
        }
        };
        allShowLabel.setFont(FONT_BOLD);            
        HorizontalFieldManager allShowManager = new HorizontalFieldManager();
        allShowManager.add(allShowLabel);
                                       
        uiApplication = UiApplication.getUiApplication();

        this.elements = elements;
        this.list = list;     
        listOfShow = new showButton[list.size() + 1]; 
        verticalContainer.add(titleManager);                   
        Photoshow selectedShow = Account.getInstance().getPhotoshow();
        for (int i = 0; i < listOfShow.length; i++)
        {
            if (i == 0) 
            {
                if (selectedShow != null) saveList.addElement(selectedShow);                
                else saveList.addElement(list.elementAt(0));
            }
            else saveList.addElement(list.elementAt(i - 1));
        }
        image = new WebBitmapField[saveList.size()];
        //recent show
        verticalContainer.add(recentShowManager);
        if (selectedShow != null)
        {
            showIconManager = new VerticalFieldManager(VerticalFieldManager.FIELD_HCENTER 
                | VerticalFieldManager.FIELD_VCENTER | VerticalFieldManager.USE_ALL_WIDTH
                | VerticalFieldManager.USE_ALL_HEIGHT | DrawStyle.HCENTER | DrawStyle.VCENTER)
                {
               protected void sublayout( int maxWidth, int maxHeight )
               {
                   //set your width
                   int width = 50;
                   //set your height
                   int height = 50;
             
                   super.sublayout( width, height);
                   setExtent( width, height);
                }                                                     
            };
            image[0] = new WebBitmapField(Field.FIELD_HCENTER);
            showIconManager.add(image[0]);
            
            Photoshow recentShow = (Photoshow)saveList.elementAt(0);
            listOfShow[0] = new showButton(recentShow.getTitle(), Field.FOCUSABLE);
            listOfShow[0].setChangeListener(this);
            
            HorizontalFieldManager showManager = new HorizontalFieldManager();
            showManager.add(showIconManager);
            showManager.add(listOfShow[0]);
            verticalContainer.add(showManager);                                           
        }
        //all shows
        verticalContainer.add(allShowManager);
        for (int i = 1; i < saveList.size(); i++)
        {
            showIconManager = new VerticalFieldManager(VerticalFieldManager.FIELD_HCENTER 
                | VerticalFieldManager.FIELD_VCENTER | VerticalFieldManager.USE_ALL_WIDTH
                | VerticalFieldManager.USE_ALL_HEIGHT | DrawStyle.HCENTER | DrawStyle.VCENTER)
                {
                   protected void sublayout( int maxWidth, int maxHeight )
                   {
                       //set your width
                       int width = 50;
                       //set your height
                       int height = 50;
                 
                       super.sublayout( width, height);
                       setExtent( width, height);
                    }                                                     
                };
            image[i] = new WebBitmapField(Field.FIELD_HCENTER);
            showIconManager.add(image[i]);
            
            Photoshow aShow = (Photoshow)saveList.elementAt(i);
            listOfShow[i] = new showButton(aShow.getTitle(), Field.FOCUSABLE);
            listOfShow[i].setChangeListener(this);
            
            HorizontalFieldManager showManager = new HorizontalFieldManager();
            showManager.add(showIconManager);
            showManager.add(listOfShow[i]);
            verticalContainer.add(showManager);                         
        }      
        if (selectedShow != null) first = 0;
        else first = 1;
        if (saveList.size() > 4) last = 4;
        else last = saveList.size() - 1; 
        getData();                
        this.add(verticalContainer);
    }                       
    UploadScreen uploader = null;                
    public void openSelectStyleScreen(){
        final Photoshow selectedShow = (Photoshow)photoshowList.get(photoshowList.getSelectedIndex());
        if (selectedShow != null && !selectedShow.isExpired()) {
                Thread selectStyleThread = new Thread() {
                public void run() {
                    Vector vtCategory = new Vector();
                    try{
                        vtCategory = ServiceUtils.getCategoryAndStyle();
                        final SelectStyle selectStyle = new SelectStyle(vtCategory, selectedShow, elements);
                        uiApplication.invokeAndWait(new Runnable(){
                            public void run(){
                                    uiApplication.pushScreen(selectStyle);
                            }
                        });     
                    }
                    catch(Exception ex){
                        DebugUtils.error("CreateNewShowScreen.openSelectStyleScreen.run()."+ex.toString());
                        displayMessage(_resources.getString(MSG_ERROR_CONTACTING_SERVER));
                    }
                }
            };
            selectStyleThread.start();
        } 
        else {
            displayMessage("Photoshow is expired.");
        }
    }

    private void displayMessage(final String text) {
        uiApplication.invokeLater(new Runnable() {
            public void run() {
                Dialog.alert(text);
            }
        });
    }
        
    private void openMainScreen() {
        int screenCount = uiApplication.getScreenCount();
        for (int i = 0; i < screenCount; i++) {
            Screen activeScreen = uiApplication.getActiveScreen();
            if (!(activeScreen instanceof com.sonic.roxio.blackberry.mpu.ui.MainScreen)) {
                activeScreen.close();
            } 
            else {
                break;
            }
        }
    }
        
    public void updateShow()
    {
        Photoshow currentPhotoShow = null;
        for (int i = 0; i < saveList.size(); i++)
            if ((listOfShow[i] != null) && (listOfShow[i].checkSelected()))
            {
                currentPhotoShow = (Photoshow)saveList.elementAt(i);
            }
        if (currentPhotoShow != null && !currentPhotoShow.isExpired()) {
        final PhotoLibraryScreen library = new PhotoLibraryScreen(false);
        library.setCurrentPhotoshow(currentPhotoShow);
        uiApplication.invokeAndWait(new Runnable(){
            public void run() {
                uiApplication.pushScreen(library);
            }
        });
        };     
    }
        
    private MenuItem uploadMenuItem = new MenuItem(_resources.getString(UPLOAD_BUTTON), 1, 1) {
        public void run() {
            updateShow();
        }
    };
        
        // create back menu item
    private MenuItem backMenuItem = new MenuItem("Back", 2, 2) {
        public void run() {
                //uiApplication.getActiveScreen().close();
                openMainScreen();
        }
    };
        
    public boolean keyChar(char c, int status, int time)
    {
        switch (c) {
            case Characters.ESCAPE :                                
                openMainScreen();
                return true;
            case Characters.ENTER :
                super.keyChar(c, status, time);
                updateShow();
                return true;
                    
            default :
                return super.keyChar(c, status, time);                  
        }
    }
        
        /**
         * Overrides makeMenu() in superclass
         */
    protected void makeMenu(Menu menu, int instance){
        ContextMenu contextMenu = ContextMenu.getInstance();
        contextMenu.setTarget(this);
        contextMenu.clear();
        
        this.makeContextMenu(contextMenu);
        
        menu.deleteAll();
        menu.add(contextMenu);
    }
        
    /**
         * Overrides makeContextMenu() in superclass
         */            
    public void makeContextMenu(ContextMenu contextMenu) {
            if (elements.size() == 0) contextMenu.addItem(uploadMenuItem);
            contextMenu.addItem(backMenuItem);
    }       

    protected boolean navigationClick(int status, int time) 
    {
        //fieldChangeNotify(0);
            super.navigationClick(status, time);
            return true;
    }

    public void fieldChanged(Field field, int context) {
            if (field instanceof showButton)
            {
                    updateShow();
            }                       
    }       
                
    public void getData()
    {
    	UiApplication.getUiApplication().invokeLater(new Runnable() 
    	{  
	        public void run()  
	        {        
	            //while (!stop)
	            //{
	                while (first <= last)
	                {
	                    Photoshow aShow = (Photoshow)saveList.elementAt(first);
	                    String url = aShow.getIconURL();
	                    String head = url.substring(0, 45);
	                    String end = url.substring(45, url.length());
	                    url = head + "w50/h50/" + end;
	                    rawResponse = new StringBuffer();    
	                    HttpConnection connection = null;  
	                    InputStream inputStream = null;    
	                    try  
	                    {  
	                        connection = (HttpConnection) Connector.open(url, Connector.READ, true);  
	                        inputStream = connection.openInputStream();  
	                        byte[] responseData = new byte[10000];  
	                        int length = 0;                         
	                        while (-1 != (length = inputStream.read(responseData)))  
	                        {                               
	                            rawResponse.append(new String(responseData, 0, length));
	                        }  
	                        int responseCode = connection.getResponseCode();  
	                        if (responseCode != HttpConnection.HTTP_OK)  
	                        {  
	                            throw new IOException("HTTP response code: " + responseCode);  
	                        }                               	                                    
	                                    inputStream.close();
	                                    connection.close();                              
	                    }  
	                    catch (final Exception ex)  
	                    {                                   
	                    }  
	                    finally  
	                    {                                     
	                        String result = rawResponse.toString();  
	                        image[first].callback(result);
	                        first++;                                
	                    //inputStream.close();  
	                    inputStream = null;  
	                    //connection.close();  
	                    connection = null;                                                 
	                    }  
	                }                                
	                if (first >= last) stop = true;          
	        }  
	    });  
    }
}

 WebBitmapField code : 

 

package com.sonic.roxio.blackberry.mpu.ui.control;
import com.sonic.roxio.blackberry.mpu.util.WebDataCallback;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.EncodedImage;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.BitmapField;

public class WebBitmapField extends BitmapField implements WebDataCallback
{  
     private EncodedImage bitmap = null;  
     public String inform = "No Icon";
     public WebBitmapField(long style)  
     {      
    	super(null, style);    	
     }        

	public Bitmap getBitmap()  
     {  
         if (bitmap == null) return null;  
         return bitmap.getBitmap();  
     }  
	
	protected void paint(Graphics graphics)
	{
		graphics.setColor(Color.WHITE);
        graphics.fillRect(0, 0, 50, 50);
        graphics.setColor(Color.BLACK);
        //graphics.setFont(FONT_BOLD);
        graphics.drawText(inform, 0, 15);
		super.paint(graphics);
	}        

	public void callback(final String data)  
    {  
         if (data.startsWith("Exception")) return;  
   
         
             byte[] dataArray = data.getBytes();  
             bitmap = EncodedImage.createEncodedImage(dataArray, 0,  
                     dataArray.length);   
             /*
             if (bitmap != null)
             {
            	 inform = "";
            	 invalidate();
             }*/
             setImage(bitmap); 
        
     }
}  

 

 

 

New Developer
Posts: 119
Registered: ‎10-23-2009
My Device: Not Specified

Re: Error after build in mobile.

After comment  "image[first].callback(result);" line in getData() method. I built to my device and it is not throw an exception. What the mater with this method callback? Pls help.

New Developer
Posts: 119
Registered: ‎10-23-2009
My Device: Not Specified

Re: Error after build in mobile.

 

public void callback(final String data)  
       {  
           if (data.startsWith("Exception")) return;  
     
           try  
           {  
               byte[] dataArray = data.getBytes();  
               bitmap = EncodedImage.createEncodedImage(dataArray, 0,  
                       dataArray.length);  
               setImage(bitmap);  
           }  
           catch (final Exception e){}  
       }  

 Here is my method make an error in my program. I use it to load an image from url. The image is jpeg type. So when i build my program it make an error.

 

Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Error after build in mobile.

What is your setImage doing?


Use Search. "Accept Solution" If the problem is resolved.