Steve Luke

+ Follow
since Jan 28, 2003
Steve likes ...
IntelliJ IDE Java Python
Parkesburg, PA, USA
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
(keep public parts private until JForum day)
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt
Moderation Tools

Recent posts by Steve Luke

First thing you need to do is enter Developer Mode (this is typically done in the Settings menu but varies by Android version and model so search to find out how to do it). then turn on USB debugging. When debugging is on, run the app from your IDE using the phone, then change to the LogCat view.
3 years ago

Jan Seer wrote:
08-27 12:31:02.410: E/AndroidRuntime(2032): Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
08-27 12:31:02.410: E/AndroidRuntime(2032): at android.view.ViewRootImpl.setView(
08-27 12:31:02.410: E/AndroidRuntime(2032): at android.view.WindowManagerGlobal.addView(
08-27 12:31:02.410: E/AndroidRuntime(2032): at android.view.WindowManagerImpl.addView(
08-27 12:31:02.410: E/AndroidRuntime(2032): at
08-27 12:31:02.410: E/AndroidRuntime(2032): at systemSpecificPackage.AndroidErrorManagement.showErrorMessage(
08-27 12:31:02.410: E/AndroidRuntime(2032): at com.example.alertdialogtest.MainActivity.displayErrorMessage(
08-27 12:31:02.410: E/AndroidRuntime(2032): ... 14 more

Okay, from this part of the error message, it looks like the Application as a Context doesn't provide the correct display context required to display an alert. try to change the AndroidErrorManagement class to below(ish):

so this takes the application context that you pass in, and, when the display is needed, uses the System Service to get the current WindowManager, which has access to the Display, which can be used to create a proper DisplayContext. I isolated the new work into its own method, and changed the initial context name to be more descriptive (uiContext doesn't make sense now, since we know it can't be used for UI). Also note that I intentionally create the context for the display at the time of making the dialog because we don't know how the display may have changed from construction of the class to the dialog request, or from one request to another. So this makes sure the dialog request keeps up with the display (I think)
3 years ago
Can you post the full stack trace of the error message? The message says there is a problem executing a method on the activity, but you need to find out which method is being called and from where (and from that you can hopefully figure out the why it is being called and what is making it fail)
3 years ago

Zhiming Shi wrote:

You only have one point, which you reuse, changing its location over and over again. If you need multiple points, then you need to make multiple Point instances, not re-use the same one.

Also, you should not be reading the file in during the onDraw() method. If the file doesn't change while the application is running then the file should be read in the MyView constructor and the points stored for later use. If the file does change then you should have a separate utility for detecting the changes and modifying the list. Reading from a file can be slow, and can slow down your UI. It can lead to poor performance and hangs. So it should never be done in the UI thread.
3 years ago

Zhiming Shi wrote:I've made a small breakthrough, but every time I click the button my app crashes.

What error message do you get in LogCat when the app crash. LogCat should have the stack trace which will pinpoint where the error occurs and why.
3 years ago
Probably the same(ish) way as doing as a content. A couple of things to thing about:
1) Make sure the view you intend to draw on has a predefined size. If not, it may (will likely) be shrunk to 0px wide and 0px tall.
2) You may find it easiest to position things with a RelativeLayout to avoid unwanted resizing
3a) You may find it easier to make the layout with the surface view in it, then get it out of the view using findViewById()
3b) Alternatively, you should put a placeholder FrameLayout where you want the surface view, then get the FrameLayout using findViewById() and adding your surface view to the frame

If you are having problems, show the layout, a simple version of the code, and a screenshot of the results, and details about the difference between expectations and results so we can help you with the issue.
3 years ago
It is really hard to tell what the problem is, because we know nothing about the code which does any of the work, nor do we know the error you are getting. So any suggestions are a shot in the dark. It most likely is either different instances/class loaders being used when setting the context versus using it, or a timing issue, where the error message is sent before the code which sets the context. To fix that, try putting break points at key points in your code, and run the application in debug mode, looking for order of execution and the values of key objects. If you don't know how to do that, then pepper your code with identifying LogCat messages so you know when things occur by watching the LogCat output.

Here is a scheme that should work - no details just an outline of how things might be put together, such that your shared package (which could be used as a library rather than just a package) would have access to the ErrorManager and need no knowledge about anything platform specific.

First, lets do some architecture. The first thing we will need is an ErrorManagement construct. If there is not going to be shared code among the different platform implementations, then you minds well make it an interface. If there will be shared code, use an abstract class:

We will use a factory to distribute ErrorManagement instances to anyone who wants one. We want the factory to be generic, not platform specific, so we will create another interface which has a method which will deliver platform-specific ErrorManagement implementations to the factory (the factory is a single, go-to location anyone can reach to get an ErrorManagement instance, this interface will be used to generate platform-specific implementations):

Now we have everything we need for the factory that can be used to get ErrorManagement instances upon demand:

Any code in any package would use the following code to get an ErrorManagement instance and call its showErrorMessage() method:

Now we need the Android specific stuff. First, we need an Android specific ErrorManagement implementation that knows how to build the AlertDialog...

Then we need to create an ErrorManagementSource implementation to create and deliver the AndroidErrorManagement to the factory upon need. Since AndroidErrorManagement needs a Context, we will need to make sure it is created in a location that has access to an Android context. We also need to make sure it is created before any chance of needing to use it. In a desktop application, that might be the main() method or the constructor of your main class. But for Android, the Application instance's onCreate() method is a good place to start:

Now if you setup your manifest properly to use the Application class you created above as the app's Application scope, the AndroidErrorManagement instance will be created, an ErrorManagementSource which delivers that instance to all askers will be created and passed to ErrorManagementFactory, and the ErrorManagementFactory will be ready to distribute the AndroidErrorManagement instance to anyone who calls ErrorManagementFactory.getErrorManagement() as soon as the application is created (barring any typos or other errors).
3 years ago
"<1>" is a synonym for "<Button-1>" == the Left Most Mouse Button. you want to use "1" for the keyboard button 1.
3 years ago
Don't guess at fixes. The first thing you need to do is identify where the problem is. The stack trace in your first part tells you that. What is it?
3 years ago
Hi sam,

Look through that log file. It gives you the cause of the error, what is it? Where does it occur?
3 years ago

Robert Stepp wrote:Thanks, Skye, for your thoughtful response. I especially liked your clarifying println examples. Thanks, also to Campbell. BUT!

I must not have expressed myself clearly. The heart of my question was:

"According to the operator precedence table the assignment operator has much lower precedence than either the prefix or postfix forms of the increment operator. "

And that is where Campbell's statement about the value of the expression comes in. The x++ expression has a value and a side effect. The operation occurs first, and its value is generated. Its value is the value of x before the increment. So that is what gets assigned to y. The operation's side effect is that x is incremented, but that doesn't come into play when determining the expression's value. Where as the ++x expression also has a value and a side effect. The operation occurs first and its value is generated. In this case the value is the value of x after the increment. So that is what is assigned to y.

edit: fixed an accidental bad word
3 years ago
I haven't used it (I don't write games) but this is the service that Google provides:

It has leaderboards, saved games, etc... So it is a great resource.
3 years ago
Is the translation_description a valid parameter for a String resource? I have never seen it and it is not in the documentation as far as I can see.
3 years ago
Good: build a prototype that can be modified to run with various levels of parallelism. Pit it in real world system. Test and measure with real world data. Analyze results. Look for bottlenecks. Modify addressing bottlenecks. Repeat

Bad: try to design a system or come up with ideas without knowing specifics.
3 years ago
If you ask me, your object graph is too flat, and it puts too many responsibilities on too few things. A ChessBoard should conceptually be about a map of pieces, it doesn't really need to know about players.

What I would think a better design would be:
A ChessRoom has a ChessGame (and maybe other things)
- A ChessGame has 2 Players and a ChessBoard
-- A ChessBoard has ChessPieces

The ChessBoard cares naught about players, and only about the positions of its pieces and legality and results of moves.
A ChessGame would control each player's access to the board, making sure they each get their turn.
A Player would need a reference to the board so it can make its move.
3 years ago