First Android app: pictures not refreshing - android

im very new to Java and Android Programming and am currently trying to write my first Android App.
The App shows 3 Dices, and depending on what combination the dices Show, the App says "yes" "no" or "ultra yes".
My Problem is, when hitting the Button to Re-Roll, sometimes the Pictures of single Dices do not get Updated and then the Answer is wrong (i hope it is somehow clear what i mean)
In this Screenshots you can see what i mean. The first Picture everything is correct (2 dices showing the same numbers means a "No"). Then i hit the Reroll button again and somehow the Pictures didn't get updated.. This occures Randomly, sometimes it works correct 10+ times.
http://image-upload.de/image/gbYhNq/ce3ef664bd.png
http://image-upload.de/image/j8jSTv/97ed7d0f7e.png
The Code of the APP:
http://pastebin.com/360DwFcg
thanks in Advance from a newbie ;)

Your random dice number generation is wrong. It creates a random number from one to seven.
This is probably a long shot, but since your answer is "ultra yes", then all three dice are the same value. So maybe you just got a lucky 7, 7, 7, in which case no images are updated. Just change your random generation to
(int) (Math.random() * 6 + 1)

Related

Kotlin , code enters if statemant even when condition is false

I'm really confused here ... looks like a really silly mistake but I don't know what's happening. Here's little snippet of my code :
if (tempDeltaDeviation > standardDeltaDeviation) {
Log.e(TAG, "handleMessage: plus $tempDeltaDeviation : $standardDeltaDeviation")
scaleUpAnimation(deltaAnimStep, "Delta", binding.deltaImg)
}
Really basic stuff, right ? Well checking the logs I can see :
handleMessage: plus 1.57756888292539E14 : 7.8364593205657E13
Dunno but last time I was checking 1 was much smaller than 7 so why app enters if statement ?
1.57756888292539E14 is in fact larger than 7.8364593205657E13.
These numbers are represented in scientific notation which is used to work with very small or very large numbers. 1.57756888292539E14 means: 1.57756888292539 * 10^14. By increasing the number after E by one we actually increase the resulting number 10 times. By increasing it by 6, we increase the resulting number million times (10^6 = 1000000).
Making things simple, your numbers are really:
157756888292539 (1.57756888292539 * 100000000000000)
78364593205657 (7.8364593205657 * 10000000000000)
As you can see, the first number is actually bigger.

Generate only not generated random numbers in a certain range android studio? [duplicate]

This question already has answers here:
How to generate a random permutation in Java?
(3 answers)
Closed 1 year ago.
Hi in my Android application I need to generate all numbers(not together but when I call the function say generateAnyRandom()) in a certain range.
For example, say my range is 1 to 1000 and when I call generateAnyRandom() it should give a random number within the range. In this way, if again I call the function it should give me another random number which must be different from the existing one. And more importantly, I will call the function maximum of 1000 times as the range is 1 to 1000 and it should give me always a number that was not generated yet. That means I want to generate all the numbers from 1 to 1000 not in one shot but only when I call it.
Please help. It is a critical question for me?
This is a known problem.
Put the numbers 1..1000 into some container; an array, list, or whatever.
Shuffle the contents of the container into random order.
Retrieve the numbers from the shuffled container in order.
As you correctly point out, this will only work 1000 times before the container is exhausted. You should pick a type of container that allows you to easily perform a random shuffle. Check the various built-in functions for the different container types.

App Inventor 2 "Invalid Index 0, Size is 0" Error

I am trying to create an Exercise Tracker app in App Inventor 2 for a school project, and everything seemed to be going great until I made it to the third screen.
I hit my start button and it said Invalid Index 0, Size is 0.
This is my code: MY CODE.
Randy: Here is al link to an .aia file for my app. Using this, you should be able to view all my code. Let me know what you find!!!!
It will be in the comments-sorry!!!
First of all,your open another screen's screen no was invalid.
After i fixed it and tested it in the AppInventor's Emulator and it didn't show any error.
But I suspect that your problem was came from the data type of the global Time.The data type for the global Time is integer and the data that you store in the TinyDB is not only contents integer value (you can try to displays it in a label).So I would suggest you to store it in "Text/String" type rather than "Number/Integer".
Below is my way to store the Date and Time in the TinyDB after proper format it:

Maintain 3 days log - Android

I have a location service in my app. For debug purposes, i want to log (to text file) some events like "new coordinate", "service onDestroy", "service onStartCommand", "coordinate sent to backend", and so on.
But im facing with a problem. The log file gets 350+ new lines each day .. so.. in 3 days i have a file with 1000 lines.
My idea is to maintain only the 3 (or N in that case) last days and delete the content that was written 3+ days ago.
But:
I don't want to check in every write if there are old lines to be removed
I don't want to set an alarm that fires every 3 days to erase the old data.
Can you please tell me if you know another efficient way to handle this situation?
Without a way to index into the text file, there's really no way to solve it without reading each line of the file (up to a certain point), parsing it and finding the date.
Don't keep a file. Keep a database. Have one of the columns be "created time". Then you can easily delete the rows that with a created time older than some threshold.
getContentResolver().delete(
yourUri,
"created_time < ?",
new String[] { System.currentTimeIllis() - Integer.toString(TimeUnit.DAYS.toMillis(3)
);
(Or something, please test your own SQL ...)
As a side note, a 1,000 line text file is nothing. Reading and parsing it is not significant unless you are doing it often. If you read and trimmed the file 1x per day, no problem.
Another solution would be to rotate the files (log --> log.1, log.1 --> log.2, ..., log.n-1 ---> log.n). This of course doesn't set a hard limit on the size of any particular file.

Count until zero

I am beginner and trying to write some calculations with App Inventor 2.
I am trying to write a code to calculate Net present value.
The formula of NPV = - investment + CF/(1+i)power up by years of investment, which means if years of investment are > 1 the second part of formula will repeat until it reached the number of years.
I successfully code the formula for one year that works correct, but have problem with the "repeating" the second part powered by number of years.
I tried to declare years as variable to use it as powering number but think something is wrong with it.
In my opinion I need to split the powering number somewhere to memory and then increase it by 1 until the required number. However have no clue how to do it.
Can anyone help?
Screenshot of the blocks
Following the calculation from the NPB Calculator,
this is converted into blocks the following
Note: for a better clarity and to avoid such long calculation blocks as in your screenshot, I used External Inputs instead of Inline Inputs, which is the default. You can switch that from the context menu after doing a right mouse click onto one of the calculation blocks.
EDIT: screenshot updated for changing cashflows using a list.See also
How to work with Lists by Saj and
How to work with Lists and Lists of lists (pdf) by appinventor.org

Categories

Resources