1

I am writing a blackberry application - after the application has started I need to get a .class file(or maybe something else like a .COD file?) from a database(I will probably have to create a web page from which to get the file) and then instantiate it and invoke its methods... Can anybody help me? Please?!?

The point is to allow students to get code on their phones and see what a method would return. A teacher would write a simple programming method that returns some integers. The students need to be able to get that method into the application. They can see the code and enter what they would expect the method to return. Then they need to be able to run the method so as to be able to see what the method returns...

Basically I want to be able to unit test some code that isn't on my blackberry yet...

I saw an advert for an app which does something similar... How can I do this: .net for BlackBerry (C and VB.NET) If you are learning ASP.NET, C# or Visual Basic.NET, then this application allows you type .NET code onto your BlackBerry®, and view the output in seconds. It is an excellent way to try out snippets of .NET code without having to fire up Visual Studio on your PC.

Code written with this application is stored on a remote server, and thus can be recalled from other devices, so it can be shared with other users of this app.

abiNerd
  • 1,976
  • 1
  • 18
  • 22

2 Answers2

1

I think you need to put your application binaries on a server to make your students able to download them OTA. (http://blackberrystorm.wikidot.com/setup-blackberry-ota-applications)

then, you can use Global Events to communicate between your app and other apps. (http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800620/What_Is_-_Global_Events_and_Global_Event_Listeners.html?nodeid=800527&vernum=0)

but accessing methods from other app, on the device in real time.., I don't think this is possible.

Abed Hawa
  • 1,372
  • 7
  • 18
  • Good suggestion. You could create common launcher which will download particular app from web and launch it. Particular app could create particular class. – Eugen Martynov Jul 03 '12 at 14:28
  • I don't need the whole application on the server though... I just need a class... even just a method... And then have the methods result displayed in the application... I basically want to be able to unit test methods in my blackberry application... Is this possible? – abiNerd Jul 06 '12 at 11:40
  • I'm not sure BB is able to do this, even if there is a hack, it will be tiring I guess, have you considered executing methods on a server and returning results to the device? this way BB device will work just like a terminal. – Abed Hawa Jul 09 '12 at 10:43
1

The BlackBerry JVM doen't support reflection, however if the applications all extend a Class that is also defined in the base application, and you can derive the fully qualified name of that Class in the downloaded software you can do something similar:

abstract public class MyDemoObject {
    abstract public void myDemoMethod();
}

Then:

Class class = Class.forName("org.some.sample.ClassName");
MyDemoObject obj = (MyDemoObject)class.newInstance();
obj.myDemoMethod();

In the downloaded app:

package org.some.sample

public class ClassName extends MyDemoObject {
    public void myDemoMethod() {
        System.out.println("package org.some.sample.myDemoMethod()");
    }
}

Kind of clunky but it does work. myDemoMethod will be running in the context of the base application, which is not a bad lesson to learn about programming for BlackBerry OS.

Richard
  • 8,920
  • 2
  • 18
  • 24
  • Thank you for your response... How do I add the class to the package though? I want the student to have the application running, download the class from a database and then run a method from that class and display the results in the application... – abiNerd Jul 06 '12 at 11:42
  • The class is put in a package with the package org.some.sample line. In java a package is really just a name space shorthand. The only way to install code on a BlackBerry OS device is to compile it to a COD. You can insall a COD with the CodeModuleManager, but I recommend using the browser and a JAD file/COD file pair to do an over the air installation. The browser has the software and permissions needed to link an installed COD file. – Richard Jul 06 '12 at 12:44