John Lockheart

Ranch Hand
+ Follow
since Oct 13, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by John Lockheart

Yes, whole error. Threads need to be used because the socket connect() call is blocking, and will stall the main thread so you have to let the UI continue when connecting.  But no bluetooth connection works not even to a standard device i bought online...it's paired to the phone and works but in my code the socket connection fails 100% of the time.
5 years ago
I am getting the error:

E/DEMO_APP: Socket connection failed on device
   java.io.IOException: read failed, socket might closed or timeout, read ret: -1
       at android.bluetooth.BluetoothSocket.readAll(BluetoothSocket.java:925)
       at android.bluetooth.BluetoothSocket.readInt(BluetoothSocket.java:939)
       at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:494)
       at com.hudngo.android.BluetoothService$ConnectedThread.run(BluetoothService.java:120)

The android phone is paired with the bluetooth device, I see it when scanning paired devices, I connect to the device I want based on Mac address and the device object I pass is correct. But the connection always fails, I want to have my android mobile app connect and be able to receive messages from the bluetooth device so it can execute code on the mobile app based on actions done on the bluetooth device. I've tried many things and the connection always fails. I sampled code off the android developer docs.

I also tried using my car as a test bluetooth device since the phone is paired, connects to it, and I should be able to read in data from the car but that fails too trying to use both client / server socket code, accept() ends up stalling then failing as well when trying the other way: tmp2 = Bluetooth.bluetoothAdapter.listenUsingRfcommWithServiceRecord("testing", mmUUID); and my car gives me a uuid to read in and use..so must be my connection code if nothing is working even with a real working bt device.

Service class


Main activity call
5 years ago
I understand that, but How do I go about implementing action listeners for all the panels I create in a class. I need to know when buttons are clicked on those panels. How can I retrieve a button click event from a newly created panel and process it in my main class?
16 years ago
I have a seperate class which extends JPanel. It will occupy the center of a frame. I want add multiple controls to it, but i'm not sure how.



The four buttons will take up the entire West area. The labels stacked on top of eachother beside the TextFields/CheckBox (which are also stacked on eachother) in the Center area. Then the Label on top of the ListBox (which takes up the rest left over space) in the East area.

Any ideas? Below is my class with the code I implemented so far. Any help would be great.



[ March 20, 2008: Message edited by: John Lockheart ]
[ March 20, 2008: Message edited by: John Lockheart ]
16 years ago
I've tried a couple of math formula's, and using java.text.decimalformatter buut, I'm not having much luck. I need something that not only works for decimals with a large amount of numbers after the decimal point. But also something that works for converting an int 30, to double 30.0 and than gives me 30.00...if possible. Is it?
16 years ago
What's the best way to go about checking if a String being searched for is contained within another String (ignoring case).

ex) Cat is contained in Catastraphy

I searched the string class online but found no functions that might help me do this. Maybe just using indexOf() with a string parameter, because that way if I don't get back an index it's not there, and if I do it is there? I'm trying to keep a record of which strings contain other strings, like all the strings in a list that contain the word "Cat" for example. Thanks
16 years ago
I created my own generic Queue to hold a wide range of objects. I use it as both a standard queue and a priority queue. With methods "enter" and "priorityEnter" depending on which one it is. When I use it as a priority queue I need to do ordered inserts of two diffrent kind of objects.

Data (abstract superclass)
-Rooms extends Data
-People extends Data
-Events extends Data (abstract superclass)
-Event1 extends Events
-Event2 extends Events
-Event3 extends Events

*People contains method getPriority()
*Events contains method getTime()

People and Events need to be stored in the priority queue sorting Poeple by a variable called priority, and Events by a variable called time. I can easily use instance of to determine if i'm working with a People object and perform the desired cast and perform my ordered insert. But I can only go as far as using instanceof to determine if it's an Events object, than it can't find the method getTime() in Events to do the ordered insert. Since there are diffrent kinds of events I don't want to re-write the code 3 times using the appropriate cast for each Event object. What can I do?



So I know that the parameter i'm working with is an instanceof Events ( could be any one of them ). The getTime() method is inside the Events class, and should be inherited by all of the classes that extend it. How do I access it? Or do I have to re-write the code for every class that extends is and go instanceof Event1, instanceof Event2 etc...?

So since Events is abstract, and the method getTime cannot be instantiated except only from one of Events subclasses. How can I write the code once, but cast it to the specific event and perform the ordered insert? If this is possible I can eliminate the duplicate code I wrote for "People", because I perform a "People" cast, but other than that the code is identical.
[ January 25, 2008: Message edited by: John Lockheart ]
16 years ago
ya, i'm just following a class i'm not actually taking. Were programming all of our own sorts and data structures, and not using any of java's built in stuff. I got the code all figured out now...i'm doing 128 unicode characters, but treating upper and lowercase letters the same when putting them in bins. Each bin contains a Doubly Linked Circular list. When the sort is completed, is it more memory efficient to link the bins all together, then print out the results? Or, pop out all the results in order from each bin into a bin , then print the contents of the newly filled bin? The bins are contained inside an array, so upon initialization ill just create 1 extra bin for the second method i was talking about.
17 years ago
I have a doubly linked circular list class, and a bin class which merely implements methods from the list class, and is itself a list. Inside the bin class is where i need my radix sort method. When radix sorting strings, using the LSD method (least significant digit) i.e. right to left. Where do I begin? Anyone have basic code for dealing with strings that I could examine??
17 years ago
thanks, but I want as little overhead as possible...something I can write inside my main method without creating an output stream over and over again. Isn't there anyway I can distinguish which file is causing the exception in the code I already have? When I tried writing a try catch block for closing the output file (when i wrote it seperate from input file), it gave my a compile time error saying that closing the output file wouldn't generate an IO Exception...is that right?
[ July 13, 2007: Message edited by: John Lockheart ]
17 years ago
I want to simultaneously read and write, read in a file, enter the lines into a data structure, then call a method that returns an augmented data structure which will be written to file. I also want to catch all exceptions and use the proper prompts when errors occur. Can someone help me clean up this code? Does my code catch exceptions generated by both files, or only one? I want to be specific and include the filename in the prompt as well...

17 years ago
thanks, I was using (char) as opposed to (Character). I haven't worked with simple primitives so long I guess I forgot.
17 years ago
I have created my own Queue class, along with a Linear Linked list class, and a node class. A Linear Linked list contains Nodes, with a single character as a value, and a link pointing to the next node. The Queue class just contains a Linear Linked list. Now, I store each character in a node by using the new Character() wrapper class. When I pull out values from my queue, i can't cast them as characters. I get the error message "inconvertable types". And I do not want to store anything but Objects inside my nodes, because it gives flexibility. Why can't I cast an object to char? I didn't seem to have a problem storing a char as an object. Please don't ask me to post code, because all it is, is char c = queue.pop(), where pop returns an object.
17 years ago
This is a split of this post which was originally intended to discuss a specific problem with recursion.

The original topic got hijacked into a discussion of stack overflows and compiler optimizations. While this topic could be very interesting, it is likely to be a distraction to the original poster. Hence the split. The original poster's question, and all the posts since that point are listed below.

Andrew


I got this far but can't get the code working properly. Recursion is sometimes difficult for me to grasp. The whole premise for this code is you are given the command "S 0 1" => Is set 0 a subset of set 1?

[ June 24, 2007: Message edited by: Andrew Monkhouse ]
17 years ago