• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Led notification error

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to make the notification Led blink in a certain way and when i run the app from Eclipse with my phone connected it works as expected, but when i run it directly from my phone it doesn't work as it should (showing the colors not respecting the order or the while loop). I also have a problem with the main page of the app, it is always black and doesn't show anything on it (like the button i just added) . Now after i added the button i get many markers at the "void onActionPerformed(ActionEvent e1 ){" line :"Action event cannot beresolved to a type", "syntax error on token "(" and ")" expected" and "void is an invalid type for the variable OnActionPerfermed"

How can i fix these errors ?



 
Marshal
Posts: 4499
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where did (ActionListener)/actionPerfomed/ActionEvent come from -- that looks like Swing, not Android UI. You probably want to use an OnClickListener.

Also, sleeping in the UI/main thread will cause your activity to become unresponsive.
 
Johnny Smithone
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just followed an online tutorial and that's where i found the ActionEvent. Now i'm looking how to implement onClickListener.
I think i've succeded in using the Button. Now to use the app i have to press the Button ,turn the screen off manualy and then observe the lights. After i turn the screen back on, the Led stops flashing but it also becomes unresponsive. How can i fix that ?
I also added a new line in activity_main.xml:
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Android does not support AWT and Swing, so you can't use any java.awt and javax.swing classes. Any Android GUI tutorial should have an example of how to use onClickListener.
 
Johnny Smithone
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I edited the post above yours, please have a look. I'm still having problems with the crashing part.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Ron said, you should not use Thread.sleep in the UI thread. All methods running in the UI thread should return quickly, otherwise unresponsiveness and crashes may be the consequences.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Johnny Smithone wrote:I edited the post above yours.


Please don't do that. For someone like me who comes along a little later, it's VERY hard to follow the discussion without the original code.

disk space is cheap. Please put your updated/corrected code into new posts so others can follow along whats going on.

Thanks!!!
 
Johnny Smithone
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for the editing part.

So what should i use instead Thread.sleep that will do the same thing and will this fix the crashing ?
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Johnny Smithone wrote:Sorry for the editing part. . . .

I have however edited it, because the long lines and excess blank lines make the code difficult to read.
I shall move this discussion to the Android forum.
 
Johnny Smithone
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also I am having another problem. When i run the app from ecplise with my phone connected is runs as it should but when i run the app directly from the phone the colors blink in a random order . For ex: the first color blinks 5 times , the second 2 times and the third 8 times and normally every color should blink only once in a certain order.

And with what should i replace Thread.sleep ?

I also noticed that if i remove the try/catch commands the lights turn on/off very very fast not respecting the .setLights(0xffff00,5000, 3000) times. It only uses the color but not the times (ms)
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using Thread.sleep is fine, you just can't do it on the UI thread (which is where GUI handlers are run). I generally use an AsyncTask for background processing. That has the benefit of having callbacks to run code on the UI thread should the need arise.
 
Johnny Smithone
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you help me with the logcat ?

 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What about it? Which tag are you using for logging in your app?
 
Johnny Smithone
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote: Which tag are you using for logging in your app?



Sorry but i don't understand your question .
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You asked for help about the logcat output. Since there is no exception in it, I assumed that your app logged something into it that you wanted us to take a look at - not so?
 
Johnny Smithone
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I opened the logcat when i started the app and copied all the lines including the crash-ing part of the app.
This is a much smaller part and i hope you can tell me why does the app crash and why it doesn't work the same when i run the app directly from the phone as when i run it from eclipse.

Thanks



Logcat
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
These are the interesting parts:

02-16 19:33:19.817: E/NotificationService(765): Not posting notification with icon==0: Notification(pri=0 contentView=com.example.led/0x1090064 vibrate=null sound=null defaults=0x0 flags=0x11 kind=[null])
02-16 19:33:19.817: E/NotificationService(765): WARNING: In a future release this will crash the app: com.example.led


Android warns that the way you're creating the notification is not future-proof.


02-16 19:33:20.097: I/InputDispatcher(765): Dropped event because the current application is not responding and the user has started interacting with a different application.


Android warns that the app is not responding - that indicates that the UI thread is not returning quickly; are you still doing the Thread.sleep in it?


02-16 19:33:20.767: W/ActivityManager(765): Activity pause timeout for ActivityRecord{42d2d498 u0 com.example.led/.MainActivity t6}
02-16 19:33:21.527: I/ActivityManager(765): Killing 5161:com.example.led/u0a154 (adj 2): remove task
02-16 19:33:21.557: I/WindowState(765): WIN DEATH: Window{42639258 u0 com.example.led/com.example.led.MainActivity}


And that's the result - the UI thread is not being relinquished, thus the app appears frozen and is killed.
 
Johnny Smithone
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried using your ideea : AsyncTask but i connont implement it. I just don't know how to use it .
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to keep it simple you can also create a Thread on your own that starts a Runnable, just like you would in a non-Android Java app.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic