Sunday 18 January 2009

webdev.webserver error

I got the above error in VS.NET 2008 when running an ASP.NET app. When trying to debug or show in browser the IDE gives the error in the standard "report to microsoft" dialog box followed by the following message "unable to connect to the asp.net development server".

To fix this error:
  • Right click on the project in solution explorer.

  • Hit F4 for properties (don't right click for properties).

  • Change "Use Dynamic Ports" to false and enter a new port number. Use one quite close to the current port number, I used 1080. Default was 1071.

Thursday 15 January 2009

Show Modal form from Background Application

To show a message from within a background application we can’t just use Dialog.alert(); because this will throw errors as the application is not using the Ui thread. Use the following code to launch a message/screen from the app:

Application.getApplication().invokeAndWait(new Runnable()
{
public void run()
{
UiEngine ui = Ui.getUiEngine();
Screen screen = new Dialog("Message", new Object[]{"Ok","Cancel"}, null, 0, Bitmap.getPredefinedBitmap(Bitmap.EXCLAMATION));
ui.pushGlobalScreen(screen, 1, UiEngine.GLOBAL_MODAL);

String
modalResult = ((Dialog)screen).getSelectedValue();
}
});

Can change the screen constructor depending on screen required, the above example just gives an Ok and Cancel button. Use the invokeAndWait() method blocks the current thread and waits for user to click button to give reply.

Cannot Find .debug file error

If you launch the simulator and get the above error it means that the simulator is loaded with the wrong version of the application. Using Browse.. from the dialog box that pops up and selecting the .debug file won’t fix it.

Not sure why this happens but the version loaded and the version in the .debug file differ so any changes you make will not be reflected on the simulator. Sometimes this can happen if you have a dialog box open and you try to debug. I also got this error when I had set an icon in the project, I then removed the jpg file from the workspace but did not delete the icon resource and launched the application.

You can clear the applications from the simulator and put it back to it’s original state by using the /clear-flash command in the batch file for launching the simulator, located in:
\plugins\net.rim.eide.componentpack4.3.0_4.3.0.8\components\samples\

I just added this in, ran it once and then removed it. You can leave it in to get a fresh version of the simulator each time but it takes longer to load and simulator will always prompt to use wizard on load. You need to change something in the project and rebuild it before you will see it on the simulator.

To view all other commands that can be used in the batch file, navigate to the samples folder and use the fledge /help command.

String.Format()

When concatenating strings you can use the String.Format() method rather than adding seperate strings.

String.Format() is based on the StringBuilder class and, as such, allows you to concatenate strings with the added performance of the StringBuilder class.

Example:

int intOne = 22;
String strTwo = "Donald";
String result = String.Format("{0} is {1} years old on {3}", strTwo, intOne, dataSet.Tables["Employee"].Rows[0]["DOB"].ToString());


You can have any number of parameters, they must be passed in the correct order, e.g. first parameters replaces {0}, second parameter replaces {1} etc.

This gives the same results as the following but performance wise it is better because the compiler doesn't destroy and recreate lots of String objects.:

String result = strTwo + " is " + intOne + " years old on " + dataSet.Tables["Employee"].Rows[0]["DOB"].ToString;

Tuesday 13 January 2009

Use environment variable in DOS

I've found this very helpful when using DOS a lot. I had to navigate to C:\Program Files\eclipse\plugins\net.rim.eide.componentpack4.3.0_4.3.0.8\components\bin\ in dos a lot which was a headache so when using the command prompt I have created an environment variable to do it quicker.

To do this:

  • Right click, properties on My Computer

  • Advanced tab then Environment Variables

  • I created a new User Variable (top box) named BBEclipse. Set the path (variable value) to C:\Program Files\eclipse\plugins\net.rim.eide.componentpack4.3.0_4.3.0.8\components\bin

  • Now in command prompt you can use cd “%BBEclipse%” to navigate to that folder.
  • Free Hit Counter