I am new to Blackberry Development. In my app it is throwing an Exception,it is showing on simulator. I want to know how can I see this exception in detail like 'Logcat' in Android.
Thanks in Advance
Try like this:
try
{
//write code here;
}
catch(final Exception e)
{
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
Dialog.alert("Exception: "+e.getMessage());
System.exit(0);//if you want to close the application;
}
});
}
Enough;
If you have doubts come on StackOverFlow chat room name "Life for Blackberry" to clarify Your and our doubts
try{
......
.....
}
catch(Exception ce){
System.out.println(ce.getMessage());
}
if you are using ECLIPSE just run the application in DEBUG mode....
Then check for whichever exception occured in console pane.
Related
I want to integrate chatting into an application I made, and after following some tutorials and running the application I keep getting "Whoops! Lost connection to http://localhost:8080/ws" on my console I tried using sockjs path as"/ws" but still got the same error, please can someone explain to me what i am doing wrong ?
here is the snippet of my code:
#Configuration
#EnableWebSocketMessageBroker
public class WebSocketConfiguration extends AbstractWebSocketMessageBrokerConfigurer {
#Override
public void registerStompEndpoints(StompEndpointRegistry stompEndpointRegistry) {
stompEndpointRegistry.addEndpoint("/ws")
.setHandshakeHandler(new CustomHandshakeHandler())
.withSockJS();
}
#Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.setApplicationDestinationPrefixes("/app");
registry.enableSimpleBroker("/message");
}
}
and this is my client
var socket = new SockJS('http://localhost:8080/ws');
stompClient = Stomp.over(socket);
stompClient.connect({}, onConnected, onError);
function onConnected() {
console.log("its working");
}
function onError(error) {
console.log(error);
}
i am not sure about the CustomHandshakeHandler which you are using here. so that might be an issue to look into. also, consider to add .setAllowedOrigins("*") to your stompEndpointRegistry.
apart from that, the code looks ok and should work IMO.
If you are using Android studio emulator, try using http://10.0.2.2:8080/ws
Task<Void> task = new Task<Void>() {
public Void call() {
try {
// my task code
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return null;
}
};
task.setOnSucceeded(event -> {
Platform.runLater(new Runnable() {
#Override
public void run() {
Alert alert = new Alert(AlertType.INFORMATION, "task success", ButtonType.OK);
alert.showAndWait();
}
});
});
In my above code i am trying to display alert message from success part of task.
I have deployed the application in a remote machine and accessing the same using remote desktop connection.
when i keep my remote desktop connection window minimised i get the alert message empty. (Yes i see the message when RDC window is open)
when i focus on parent container(stage) it refreshes and shows the correct message or just alt + tab few times also works. Tried various solutions to set modality, init stage, some vm args etc nothing seems to work.
any idea why this problem is? I understand task is a seperate thread and hence i have used platform.runlater? Have i done anything wrong? any alternative solutions?
Task runs on new thread as its performing a heavy operation.
I have the following Codename One code for accessing a network resource. It is almost an exact copy of the Codename One tutorial for this use case.
public void executeRequest(){
String url = "http://www.random.net";
InfiniteProgress prog = new InfiniteProgress();
final Dialog dlg = prog.showInifiniteBlocking();
ConnectionRequest r = new ConnectionRequest() {
#Override
protected void postResponse() {
//handle changes to my form
}
#Override
protected void readResponse(InputStream input)
throws IOException {
//handle parsing data
}
#Override
protected void handleIOException(IOException err) {
super.handleIOException(err);
}
};
r.setUrl(url);
r.setPost(false);
r.addArgument("arg", "2");
r.setDuplicateSupported(true);
r.setDisposeOnCompletion(dlg);
NetworkManager.getInstance().addToQueue(r);
}
The first time I run it - no problem. If I try to "refresh" my data by calling the same method over again, the app will hang up with the InfiniteProgress dialog spinning forever. Its almost like the first network request is not ever really completing, and then the second one kind of conflicts. Any ideas what I'm doing wrong?
By default duplicate requests to the exact same URL are disabled, try invoking setDuplicatesSuppotred(true) on the connection request.
For future reference, what fixed this for me was to use
NetworkManager.getInstance().addToQueueAndWait(r);
instead. That cleared up most of my problems.
I stucked with the same problem and none of solutions worked. However, I did it this way:
final NetworkManager nm = NetworkManager.getInstance();
nm.setTimeout(3000);
then
protected void postResponse() {
...
nm.shutdown();
}
and call was made as
nm.addToQueueAndWait(request);
Maybe the fact that NetworkManager was made final did the job, but I put "shutdown" just for sure. It worked for me
i am working on UI-application that handles multiple entry point approach.
I am referring the link and try for make a demo.
Here is the code :-
public class DemoApp extends UiApplication implements RealtimeClockListener
{
private static DemoApp dmMain ;
private static final long dm_APP_ID = 0x6ef4b845de59ecf9L;
private static DemoApp getDemoApp()
{
if(dmMain == null)
{
RuntimeStore dmAppStore = RuntimeStore.getRuntimeStore();
dmMain = (DemoApp)dmAppStore.get(dm_APP_ID);
}
return dmMain;
}
private static void setDemoApp(DemoApp demoAppMain)
{
RuntimeStore dmAppStore = RuntimeStore.getRuntimeStore();
dmAppStore.remove(dm_APP_ID);
dmAppStore.put(dm_APP_ID, demoAppMain);
}
public static void main(String[] args)
{
Log.d(" Application argument "+args);
if( args.length > 0 && args[ 0 ].equals( "Demo_Alternate" ) )
{
Log.d("Running Demo_Alternate #### Running Demo_Alternate #### Running Demo_Alternate");
dmMain = new DemoApp();
dmMain.enterEventDispatcher();
setDemoApp(dmMain);
}
else
{
Log.d("Running Demo #### Running Demo #### Running Demo #### Running Demo");
getDemoApp().initializeMain();
}
}
public DemoApp()
{
this.addRealtimeClockListener(this);
}
private void initializeMain()
{
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
try
{
pushScreen(new DemoMainScreen());
} catch (Exception e)
{
Log.e(e.toString());
}
}
});
}
public void clockUpdated()
{
showMessage("DemoAppClock Updated");
Log.d("DemoAppClock Updated #### DemoAppClock Updated #### DemoAppClock Updated");
}
private void showMessage(String message)
{
synchronized (Application.getEventLock())
{
Dialog dlg = new Dialog(Dialog.D_OK, message, Dialog.OK, null, Manager.FIELD_HCENTER);
Ui.getUiEngine().pushGlobalScreen(dlg, 1, UiEngine.GLOBAL_QUEUE);
}
}
}
:- I have created an alternate entry point named Demo_Alternate , that runs at start up.
:- If the application has separate entry points, that means a separate process the link
Now my questions are :-
While running the code, I am getting "Uncaught exception : no application instance".
I just want to make one application instance - don't want separate processes.
Can we use (Application) Singleton approach for alternate entry-points?
Only looked briefly at this code, but see an obvious problem here:
dmMain.enterEventDispatcher();
setDemoApp(dmMain);
enterEventDispatcher never returns, so you never put your Application instance in RuntimeStore.
I suggest you review the following KB article, you might find its approach to accessing a RuntimeStore maintained object easier to use. Or not.
Singleton using RuntimeStore
Update
If this solution does not work, please update your original post with the corrected code.
I certainly agree with Peter, that calling setDemoApp(dmMain) after enterEventDispatcher() means it doesn't get called.
That said, I think you have a more basic misunderstanding here.
Using alternate entry points will create multiple processes. See here for more.
But, you say that you don't want separate processes. Can you tell us why not?
Separate BlackBerry processes that are designed to work together can still share data, using the RuntimeStore, for example.
Maybe you could tell us more about what your "Demo" and "Demo Alternate" are supposed to do.
When my service is installed I have a handler that starts the service after it has been installed.
private void InitializeComponent()
{
...
this.VDMServiceInstaller.AfterInstall += ServiceInstaller_AfterInstall;
}
private void ServiceInstaller_AfterInstall(object sender, InstallEventArgs e)
{
ServiceController sc = new ServiceController("MyService");
sc.Start();
}
I want to stop the service before it is uninstalled so I added an additional handler to InitializeComponent().
this.ServiceInstaller.BeforeUninstall += ServiceInstaller_BeforeUninstall;
and added the function:
private void ServiceInstaller_BeforeUninstall(object sender, InstallEventArgs e)
{
try
{
ServiceController sc = new ServiceController("MyService");
if (sc.CanStop)
{
sc.Stop();
sc.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Stopped);
}
}
catch (Exception exception)
{}
}
But the service doesn't stop before uninstall. Am I using the ServiceController.Stop() function improperly?
Would something like below help you:
protected override void OnBeforeUninstall(IDictionary savedState)
{
ServiceController controller = new ServiceController("ServiceName");
try
{
if(controller.Status == ServiceControllerStatus.Running | controller.Status == ServiceControllerStatus.Paused)
{
controller.stop();
}
controller.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan(0,0,0,15));
controller.Close();
}
catch(Exception ex)
{
EventLog log = new EventLog();
log.WriteEntry("Service failed to stop");
}
finally
{
base.OnBeforeUninstall(savedState);
}
}
This is the window I tried to prevent:
I have tested all the overrides available, and none of them are executed before the dialog box prompting to close the applications appear.
Not even the class constructor is early enough.
My conclusion is that, as the installer projects are, you cannot stop the service via code, before the dialog box.
Since there are no other ways to have code executed in the project, I don't see any way to accomplish this.
I really really wish it was different, since I badly need this myself, but there just isn't any "hook" available in the installer project, that enters early enough to solve the problem.
My best suggestion, is to make two installers.
One that acts as a wrapper for the second, and on install just starts the second installer as normal.
But on uninstall, it stops the service first, then uninstalls the second.
But this is too much of a hack for my liking, so I have not explored this further.
I wanted to do something similar, and ended up using this code in my installer project to handle when the BeforeUninstall event was triggered:
private void SessionLoginMonitorInstaller_BeforeUninstall(object sender, InstallEventArgs e)
{
try
{
using (ServiceController sv = new ServiceController(SessionLoginMonitorInstaller.ServiceName))
{
if(sv.Status != ServiceControllerStatus.Stopped)
{
sv.Stop();
sv.WaitForStatus(ServiceControllerStatus.Stopped);
}
}
}
catch(Exception ex)
{
EventLog.WriteEntry("Logon Monitor Service", ex.Message, EventLogEntryType.Warning);
}
}
The custom actions section of the project also had an action to uninstall the primary output of my Windows Service project. This worked for me and has given me a clean uninstall every time I've tested it.