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
Developer
Posts: 813
Registered: ‎05-29-2012
My Device: see later
My Carrier: see later
Accepted Solution

iLLEGALARGUMENT EXception on touch event

package mypackage;

import java.util.Vector;



import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FocusChangeListener;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.TouchEvent;
import net.rim.device.api.ui.TouchGesture;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.XYRect;
import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.SeparatorField;
import net.rim.device.api.ui.component.Status;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;

public class PlaylistTab extends MainScreen  implements FocusChangeListener{


	private int _xCoord = 0; //The x coordinate for the top left corner of the image.
	private int _yCoord = 0; //The y coordinate for the top left corner of the image.
	private int _xTouch = 0; //The x coordinate of the previous touch point.
	private int _yTouch = 0; //The y coordinate of the previous touch point.

	private LabelField tab1;

	private LabelField tab2;

	private LabelField tab3;

	private LabelField spacer1;

	private LabelField spacer2;

	private VerticalFieldManager tabArea;

	private LabelField tab1Heading;

	private BasicEditField tab1Field1;

	private BasicEditField tab1Field2;

	private LabelField tab2Heading;

	private BasicEditField tab2Field1;

	private BasicEditField tab2Field2;

	private LabelField tab3Heading;

	private BasicEditField tab3Field1;

	private BasicEditField tab3Field2;

	private VerticalFieldManager tab1Manager;
	private VerticalFieldManager tab2Manager;
	private VerticalFieldManager tab3Manager;
	int tabNum = 1;
	public PlaylistTab()
	{
		super(NO_VERTICAL_SCROLL | NO_VERTICAL_SCROLLBAR);
		//HorizontalFieldManager hManager = new HorizontalFieldManager();
		HorizontalFieldManager hManager = new HorizontalFieldManager(NO_VERTICAL_SCROLL | NO_VERTICAL_SCROLLBAR | NO_HORIZONTAL_SCROLL  | NO_HORIZONTAL_SCROLLBAR);
		Font font = getFont().derive(Font.PLAIN, 35);
		tab1 = new LabelField("Songs", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_SELECT)
		{
			protected boolean navigationClick(int status,int time){

				return true;
			}
			protected void layout(int width, int height) {
				super.layout(width, height);
				//    this.setExtent(this.getWidth(), 60);
				this.setMargin( ( getHeight() - this.getPreferredHeight()), 0, 0, (getWidth() - this.getPreferredWidth()));
			}
		};
		tab2 = new LabelField("Album", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_SELECT)
		{
			protected boolean navigationClick(int status,int time){

				return true;
			}
			protected void layout(int width, int height) {
				super.layout(width, height);
				//    this.setExtent(this.getWidth(), 60);
				this.setMargin( ( getHeight() - this.getPreferredHeight()), 0, 0, (getWidth() - this.getPreferredWidth()));
			}
		};
		tab3 = new LabelField("Artist", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_SELECT)
		{
			protected boolean navigationClick(int status,int time){

				return true;
			}
			protected void layout(int width, int height) {
				super.layout(width, height);
				//    this.setExtent(this.getWidth(), 60);
				this.setMargin( ( getHeight() - this.getPreferredHeight()), 0, 0, (getWidth() - this.getPreferredWidth()));
			}
		};
		spacer1 = new LabelField(" | ", LabelField.NON_FOCUSABLE);
		spacer2 = new LabelField(" | ", LabelField.NON_FOCUSABLE);

		tab1.setFocusListener(this);
		tab2.setFocusListener(this);
		tab3.setFocusListener(this);
		hManager.add(tab3);
		hManager.add(spacer1);
		hManager.add(tab2);
		hManager.add(spacer2);
		hManager.add(tab1);

		add(hManager);
		add(new SeparatorField());

		tab1Manager = new VerticalFieldManager(VERTICAL_SCROLL | VERTICAL_SCROLLBAR );
		tab2Manager = new VerticalFieldManager(VERTICAL_SCROLL | VERTICAL_SCROLLBAR );
		tab3Manager = new VerticalFieldManager(VERTICAL_SCROLL | VERTICAL_SCROLLBAR );

		tabArea = displayTab3();
		add(tabArea);

	}
	public void focusChanged(Field field, int eventType) {
		if (tabArea != null) {
			if (eventType == FOCUS_GAINED) {
				if (field == tab1) {
					System.out.println("Switch to Tab 1");
					delete(tabArea);
					tabArea = displayTab1();
					add(tabArea);
				} else if (field == tab2) {
					System.out.println("Switch to Tab 2");
					System.out.println("Switch to Tab 1");
					delete(tabArea);
					tabArea = displayTab2();
					add(tabArea);
				} else if (field == tab3) {
					System.out.println("Switch to Tab 3");
					System.out.println("Switch to Tab 1");
					delete(tabArea);
					tabArea = displayTab3();
					add(tabArea);
				}
			}
		}

	}

	public VerticalFieldManager displayTab1() {
		try
		{
			tabNum = 3;
			final VerticalFieldManager Content= new VerticalFieldManager(Manager.USE_ALL_WIDTH|Manager.VERTICAL_SCROLL);
			Content.setMargin(5,0,0,0);
			int mas  = 0 ;
			Vector oleg = new Vector();
			SQLManager poligs = new SQLManager();
			poligs.getSongDownload(oleg, 0);
			while(mas < oleg.size())
			{
				Song temp = (Song) oleg.elementAt(mas);
				Content.add(new A_Song(temp.songId, temp.songName, false,temp.albumCover,temp));
				mas++;
			}
			tab1Manager.deleteAll();

			HorizontalFieldManager topManager = new HorizontalFieldManager() 
			{ 
				public void paint(Graphics graphics) 
				{ 	
					graphics.setBackgroundColor(0x00000000); 
					graphics.clear(); super.paint(graphics);
				} 
				protected void sublayout( int maxWidth, int maxHeight ) 
				{ 
					int width = Display.getWidth(); 
					int height = this.getPreferredHeight(); 
					super.sublayout( width, height); 
					setExtent( width, height); 
				} 
			};
			CustomTextBox editField = new CustomTextBox(); 
			int pol = Display.getWidth() / 2;
			editField.setWidth(pol); 
			ButtonField button = new ButtonField("Search"); 
			topManager.add(editField); 
			topManager.add(button);

			//	tab1Manager.add(topManager);
			tab1Manager.add(Content);
		}
		catch(final Exception e)
		{

			e.printStackTrace();
			System.out.println("------------------- ");
		}
		return tab1Manager;
	}

	public VerticalFieldManager displayTab2() {
		try
		{
			tabNum = 2;
			final VerticalFieldManager Content= new VerticalFieldManager(Manager.USE_ALL_WIDTH|Manager.VERTICAL_SCROLL);
			Content.setMargin(5,0,0,0);
			int mas  = 0 ;
			Vector oleg = new Vector();
			SQLManager poligs = new SQLManager();
			poligs.getSongDownloads(oleg, 0);
			while(mas < oleg.size())
			{
				Albums temp = (Albums) oleg.elementAt(mas);
				Content.add(new A_Album(temp.albumId, temp.albumName, false,temp.albumCover,temp));
				mas++;
			}
			tab2Manager.deleteAll();
			tab2Manager.add(Content);
		}
		catch(final Exception e)
		{

			e.printStackTrace();
			System.out.println("------------------- ");
		}
		return tab2Manager;
	}

	public VerticalFieldManager displayTab3() {
		try
		{
			tabNum = 1;
			final VerticalFieldManager Content= new VerticalFieldManager(Manager.USE_ALL_WIDTH|Manager.VERTICAL_SCROLL);
			Content.setMargin(5,0,0,0);
			int mas  = 0 ;
			Vector oleg = new Vector();
			SQLManager poligs = new SQLManager();
			poligs.getSongDownloadss(oleg, 0);
			while(mas < oleg.size())
			{
				Artist temp = (Artist) oleg.elementAt(mas);
				//Content.add(new A_AddSingersFM(temp.songId, temp.songName, false,temp.albumCover,temp,-1, tb, logIn,logOut,1,0,0, Register));
				Content.add(new A_Artisti(temp.artistId, temp.artistName, false,temp.artistPhoto,temp));
				//	int m = temp.getSongId();
				mas++;
			}
			tab3Manager.deleteAll();
			tab3Manager.add(Content);
		}
		catch(final Exception e)
		{

			e.printStackTrace();
			System.out.println("------------------- ");
		}
		return tab3Manager;
	}
	protected boolean touchEvent(TouchEvent touchEvent)
	{
		int eventCode = touchEvent.getEvent();

		if(eventCode == TouchEvent.GESTURE){
			System.out.println("SWIPE GESTURE");
			TouchGesture g = touchEvent.getGesture();
			int gesturecode = g.getEvent();
			int direction = g.getSwipeDirection();

			//gallery.setHorizontalScroll(page_two, true);
			if(direction == TouchGesture.SWIPE_WEST)
			{

				if(tabNum == 3)
				{
					delete(tabArea);
					tabArea = displayTab2();
					add(tabArea);
				}
				else if(tabNum == 2)
				{
					delete(tabArea);
					tabArea = displayTab3();
					add(tabArea);
				}
			}


			if(direction == TouchGesture.SWIPE_EAST)
			{

				if(tabNum == 1)
				{
					try
					{
						delete(tabArea);
					}
					catch(Exception e)
					{
						try
						{
							tabArea = displayTab2();
						}
						catch(Exception ef)
						{
							add(tabArea);
							return false;
						}
						add(tabArea);
						return false;
					}
					try
					{
						tabArea = displayTab2();
					}
					catch(Exception ef)
					{
						add(tabArea);
						return false;
					}
					add(tabArea);
					return false;

				}
				else if(tabNum == 2)
				{
					try
					{
						delete(tabArea);
					}
					catch(Exception e)
					{
						try
						{
							tabArea = displayTab1();
						}
						catch(Exception ef)
						{
							add(tabArea);
							return false;
						}
						add(tabArea);
						return false;
					}
					try
					{
						tabArea = displayTab1();
					}
					catch(Exception ef)
					{
						add(tabArea);
						return false;
					}
					add(tabArea);
					return false;
				}
			}            
		}
		//The touch event was not consumed.
		return false;
	}
}


 

 

On touch events,east or west navigation  I get illegalargument exception.and my page crashing.

However, when I run the same code via debugger it works fine.I put my debug togglepoints inside touchevent ifs and elses.

 

And to note, if it crashes and i click on illegal argument exception..i go back to main page and as if the function touchevent been invoked twice and 2 tabs been jumped.

 

It works fine though thru debugger.any help?

 

 

Developer
Posts: 813
Registered: ‎05-29-2012
My Device: see later
My Carrier: see later

Re: iLLEGALARGUMENT EXception on touch event

app error 104

uncaught illegalargumentexception

scroll for available commands

 

 

i scroll

vm internet test vo

 

 

i scroll

vm times ivt

 

i scroll

virtual memory physical protection test cvmpptti

 

 

and if scroll more ,more stuff...

 

but funny is with debugger it works perfect.simply perfect

 

 

Developer
Posts: 813
Registered: ‎05-29-2012
My Device: see later
My Carrier: see later

Re: iLLEGALARGUMENT EXception on touch event

did some changes, and now its no more jumping two tabs..but just one.

if u see my code, break; is missing at end of case navigation.swipe

 

but i still get uncaught illegalexception

 

	protected boolean touchEvent(TouchEvent message)
	{
		try
		{
			int eventCode = message.getEvent();
	
			if(eventCode == TouchEvent.GESTURE){
				System.out.println("SWIPE GESTURE");
				TouchGesture g = message.getGesture();
				int gesturecode = g.getEvent();

	
				switch(gesturecode) {
	    		
		    		case TouchGesture.SWIPE:
						int direction = g.getSwipeDirection();
					//gallery.setHorizontalScroll(page_two, true);
					if(direction == TouchGesture.SWIPE_WEST)
					{
		
						if(tabNum == 3)
						{
							delete(tabArea);
							tabArea = displayTab2();
							add(tabArea);
						}
						else if(tabNum == 2)
						{
							delete(tabArea);
							tabArea = displayTab3();
							add(tabArea);
						}
					}
		
		
					if(direction == TouchGesture.SWIPE_EAST)
					{
		
						if(tabNum == 1)
						{
							
									delete(tabArea);
									tabArea = displayTab2();
									add(tabArea);
									return super.touchEvent(message);
						}
		
						}
						else if(tabNum == 2)
						{
							
								delete(tabArea);
								tabArea = displayTab1();
								add(tabArea);
								return super.touchEvent(message);
						
						} 
					
					if(tabNum == 1)
						tab3.setFocusListener(this);
					else if(tabNum == 2)
						tab2.setFocusListener(this);
					else  if(tabNum == 3)
						tab1.setFocusListener(this);
					break;
				}
			}
				//The touch event was not consumed.
				return super.touchEvent(message);
		}
		catch(Exception eol)
		{
			return super.touchEvent(message);
		}
	}
}


 

Developer
Posts: 813
Registered: ‎05-29-2012
My Device: see later
My Carrier: see later

Re: iLLEGALARGUMENT EXception on touch event

[ Edited ]

very strange i did this and it worked

 

 

protected boolean touchEvent(TouchEvent message)
	{
		try
		{
			int eventCode = message.getEvent();
	
			if(eventCode == TouchEvent.GESTURE){
				System.out.println("SWIPE GESTURE");
				TouchGesture g = message.getGesture();
				int gesturecode = g.getEvent();

	
				switch(gesturecode) {
	    		
		    		case TouchGesture.SWIPE:
						int direction = g.getSwipeDirection();
					//gallery.setHorizontalScroll(page_two, true);
					if(direction == TouchGesture.SWIPE_WEST)
					{
		
						if(tabNum == 3)
						{
						//	delete(tabArea);
						//	tabArea = displayTab2();
						//	add(tabArea);
							tab2.setFocus();
							return super.touchEvent(message);
						}
						else if(tabNum == 2)
						{
						//	delete(tabArea);
						//	tabArea = displayTab3();
						//	add(tabArea);
							tab3.setFocus();
							return super.touchEvent(message);
						}
					}
					else if(direction == TouchGesture.SWIPE_EAST)
					{
		
						if(tabNum == 1)
						{
							
									//delete(tabArea);
									//tabArea = displayTab2();
									//add(tabArea);
									tab2.setFocus();
									return super.touchEvent(message);
						
		
						}
						else if(tabNum == 2)
						{
							
								//delete(tabArea);
								//tabArea = displayTab1();
								//add(tabArea);
								tab1.setFocus();
								return super.touchEvent(message);
						
						} 
} break; } } //The touch event was not consumed. return super.touchEvent(message); } catch(Exception eol) { return super.touchEvent(message); } }

 

 

 

i do this on tab2.setfocus(), if i call setfocus it works..but if icall it seperately liek that it doesnt and crashes. very strange

//	delete(tabArea);
						//	tabArea = displayTab2();
						//	add(tabArea);


Highlighted
Developer
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: iLLEGALARGUMENT EXception on touch event

I think that the reason for your problem is that you are trying to delete a field which does not belong to the screen/manager or add a field which already has a manager...

 

Anyway, you already solved it...