• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Null pointer exception probably due to synchronisation issues; problem in starting activity

 
Ranch Hand
Posts: 52
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Swastik Dey wrote:Make these two changes and see if you get any difference




I tried with these changes. But still I receive only the first message and nothing after that (2nd message is sent 5 seconds after 1st message).

LogCat:

 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Madhu

It seems we need to think this in a little different way, i.e. instead of push from server, it can be pull from client. At a specific time interval the client sends a request to server, and the server based on the message validity sends back a response to client.
As per the following code the server will send two different messages at 10 seconds interval.




 
Madhu Nandan
Ranch Hand
Posts: 52
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Swastik Dey wrote:Make these two changes and see if you get any difference




I think the TimerTask is running every second and each time it runs, it tries to connect on a different socket. The port number is fixed (1200 in this case) but the socket number keeps changing every time it connects. What I need to do is connect just once, then keep looking for new incoming messages. I have to run the part which looks for new incoming messages as/in a TimerTask. I think this is the cause of the problem. What do you feel?
 
Madhu Nandan
Ranch Hand
Posts: 52
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Swastik Dey wrote:Madhu

It seems we need to think this in a little different way, i.e. instead of push from server, it can be pull from client. At a specific time interval the client sends a request to server, and the server based on the message validity sends back a response to client.
As per the following code the server will send two different messages at 10 seconds interval.






Hi Swastik,

I put only the data reading part in doInBackground of AsyncTask in a TimerTask. But still I can read only the first message sent from the server and not any message sent after that. See the AsyncTask code and LogCat below. If you have suggestions, please tell me.



LogCat

 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you find anything wrong with the approach that I told you, i.e. instead of push to device go for pull from device.
 
Madhu Nandan
Ranch Hand
Posts: 52
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Swastik Dey wrote:Do you find anything wrong with the approach that I told you, i.e. instead of push to device go for pull from device.



About pull from server, I feel it is a good approach. Will try and inform you.

Regarding current situation, I think the TimerTask is running every second and each time it runs, it tries to connect on a different socket. The port number is fixed (1200 in this case) but the socket number keeps changing every time it connects. What I need to do is connect just once, then keep looking for new incoming messages. I have to run the part which looks for new incoming messages as/in a TimerTask. I think this is the cause of the problem. What do you feel?
 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Probably you are right. Another point is in the pull from server approach code maintainability will be better and overhead on server is less, because it will send a response only when it gets a request.
 
Madhu Nandan
Ranch Hand
Posts: 52
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Swastik Dey wrote:Probably you are right. Another point is in the pull from server approach code maintainability will be better and overhead on server is less, because it will send a response only when it gets a request.



I will explain my situation. The Android app will run and communicate with the application running in the car PC. And the messages from the car PC are sent randomly based on how the car is being driven. For example, shiftDirection is a message which will be set to 1 and sent when the RPM is high enough and the driver has not shifted to the next gear. The Android app has to just respond to the messages it receives and do actions like show an image or display driver assistance info, etc. So the Android app really has no control over the messages it can receive. So will the pull approach really work here?
 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I hope this time it solves your purpose



 
Madhu Nandan
Ranch Hand
Posts: 52
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry...nothing here
 
Madhu Nandan
Ranch Hand
Posts: 52
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Swastik Dey wrote:I hope this time it solves your purpose





Hi Swastik,

I tried the above without the changed SendServer. It helped a lot. Thank you.

The server is the app in the car PC which gets messages with updated values every 100 milliseconds and sends those messages to the Android app.

So when I receive more than one message and I have to display an image or a text info for each message received, it hangs. I am trying to incorporate some things like this: after a particular message is received, I have to kind of freeze all other execution so that I can show some image or info related to the received message and after that resume all the execution.

Thanks a lot again.
 
Madhu Nandan
Ranch Hand
Posts: 52
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Swastik Dey wrote:I hope this time it solves your purpose





Hi Swastik,

When I run the application (with the above code), how can I stop the app? Once I start it, the app keeps running all the time, phone kind of hangs and is not possible to stop it. Only way is I have to keep pressing "Home" button on phone many times and then got o Settings-App-Manage app and stop this app by pressing "Force Stop". Could you suggest a way out of this?

Regards,
Madhu
 
Madhu Nandan
Ranch Hand
Posts: 52
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Swastik Dey wrote:I hope this time it solves your purpose





Hi Swastik,

When I used this code for client, it works alright. The server was another Java app running in Eclipse. When I tried to receive message from my colleague's app (developed in Rhapsody and I think C++), I receive the message only after his app is closed and not while his app is running and sending messages. Do you have any idea why this happens?

My situation: I run the client code on Android phone (HTC Desire). If the server is a java app running in Eclipse, then I can receive data sent by this server on my Android phone. When I try to receive data from another app (say abc, which can be considered to be acting as server), then I can connect to the app but cannot receive any data. Instead of connecting the real phone to abc, if I try connecting the client from emulator, then I can receive the data sent from abc only after abc is closed, not when it is running and sending data. Real phone & abc doesn't work-connection is established but no data

The java server is like this:

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic