Vatsa dude

Greenhorn
+ Follow
since Apr 29, 2009
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Vatsa dude

Hi,
I am following this link http://developer.android.com/guide/topics/search/search-dialog.html to build a simple 'Search Dialog' into my 'Photo' applications. Ultimately I intend to use the search dialog to search for photos within albums. So far, I have implemented the following:

1) Created 'searchable.xml' under res/xml dir:



2) Created a new Activity entry in AndroidManifest.xml



3) Created a new Activity class


The above steps should suffice to create the simple 'Search Dialog' interface, correct? Am I missing something ? I understand I will need a separate activity for displaying the search results. Any guidance on how to proceed is appreciated.

Thanks
11 years ago
I will have some code by tonight. Here's my idea.

1)Use the main thread for the Official
2)Create two new threads for Blue and Red player.
3)While the run() method for the player threads are executing, they will always check (within their internal loop), if the official has called STOP.


Here's where I am not very clear

1) How do I synchronize the 2 players - meaning how do I guarantee that there will be a PONG(Red) if and only if there is a preceding PING(Blue). There cannot be a PONG without a PING, right?
2) Players exchange the ball at most one more time after official STOPS the game - Should I control this simply by using a variable or is there some synchrnization technique to achieve this.

I guess my questions will make more sense once I publish the code.

Thanks
Sri
Hi,
Can anyone please give me some hints on the approach for solving this problem?

Sorry, I might have got the description wrong..

I need to develop a solution with the following properties: Please note this is not a homework assignment, I was given this problem by a friend of mine to think about. I am new to "Threads" concept. Can anyone advice me on how to start? Do I need to have 3 classes that extend Runnable. What are the important things to consider?

1. Use 3 threads
a. one thread for the Official
b. one thread for the Blue player
c. and thread for the Red player
2. The Official starts the game (with a message to the screen)
3. The players alternatively write their pings (Blue) and pongs (Red) to the screen as fast as they can
4. After 10 seconds the official STOPS
5. The players exchange the ball at most one more time
6. Both players threads cleanly stop, writing a corresponding message to the screen
7. The referee writes the last message
8. The program terminates

The output should look like this:

Official: Players, start game
Blue: Ping
Red: Pong
Blue: Ping
Red: Pong
Blue: Ping
Red: Pong
Blue: Ping
Red: Pong

Blue: Ping
Red: Pong
Blue: Ping
Red: Pong
Official: Players, STOP!!
Blue: Ping
Red: Pong
Blue: I’m done playing
Red: I’m done playing
I need to develop a solution with the following properties: Please note this is not a homework assignment, I was given this problem by a friend of mine to think about. I am new to "Threads" concept. Can anyone advice me on how to start? Do I need to have 3 classes that extend Runnable. What are the important things to consider?

1. Use 3 threads
a. one thread for the Official
b. one thread for the Blue player
c. and thread for the Red player
2. The Official starts the game (with a message to the screen)
3. The players alternatively write their pings (Red) and pongs (Green) to the screen as fast as they can
4. After 10 seconds the official STOPS
5. The players exchange the ball at most one more time
6. Both players threads cleanly stop, writing a corresponding message to the screen
7. The referee writes the last message
8. The program terminates

The output should look like this:

Official: Players, start game
Blue: Ping
Red: Pong
Blue: Ping
Red: Pong
Blue: Ping
Red: Pong
Blue: Ping
Red: Pong

Blue: Ping
Red: Pong
Blue: Ping
Red: Pong
Referee: Players, s
Blue: Ping
Red: Pong
Blue: I’m done playing
Red: I’m done playing

Can some one please suggest a solution. I am blank having tried this for a long time..
12 years ago
Hi, I have a client calling code like this:



Requirement - Return a single Iterator<String> that chains together the array of Iterator<String>s in the order that
they are provided, but skips {@code null} values.

actual method implmentation of iterateStrings



How do I copy the stringIterators to a LIst. I thought of doing that, then in a for loop, removing the null values and returning the Iterator<String>..Please advice.
12 years ago
I'm sorry, I might have misunderstood the problem. I had to duplicate a class as a Singleton similar to 'MyCache' below called 'SingletonCache'. Can compile-time type checking be improved in the code below? (Except for changing <Object, Object> to specific type like <String,String>

12 years ago
Only solution I can think of is changing <Object, Object> to <String, String> all over the code.. Is that it?
12 years ago
Can anyone please suggest how I can improve compile-time type checking in the following piece of code?

12 years ago
null error is resolved..But,I see most of you commenting that the Iterator is not coded perfectly. Here's the requirement (an extra step to the initial requirement). Not sure how to proceed in the most efficient way..Can you please help?

Calling code- client



Actual method implementation

12 years ago
Sorry, my bad.

does the trick..
Method is supposed to return Iterator<String> with null values removed. Can you please suggest a better solution?

Thanks
Sri
12 years ago
Same exception with:

. I think its some strange behavior with the Iterator, but I cannot figure out the exact reason.
12 years ago
I am puzzled why I am getting a NullPointer exception in the blow code - Error on line no 12. If I check for something like "abc", it works fine.

Calling code:


12 years ago
Hi,
I have a requirement to duplicate an inner class MyClass to a Singleton. I've attempted to do this by implementing MySingleton. I am not sure how to use the _instance in the get and put method of MyClass. Can you please advice?

12 years ago