Congratulations!

[Valid RSS] This is a valid RSS feed.

Recommendations

This feed is valid, but interoperability with the widest range of feed readers could be improved by implementing the following recommendations.

Source: https://fsiblog.io/feed/

  1. <?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
  2. xmlns:content="http://purl.org/rss/1.0/modules/content/"
  3. xmlns:wfw="http://wellformedweb.org/CommentAPI/"
  4. xmlns:dc="http://purl.org/dc/elements/1.1/"
  5. xmlns:atom="http://www.w3.org/2005/Atom"
  6. xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
  7. xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
  8. xmlns:media="http://search.yahoo.com/mrss/" >
  9.  
  10. <channel>
  11. <title>FSIBLOG</title>
  12. <atom:link href="https://fsiblog.io/feed/" rel="self" type="application/rss+xml" />
  13. <link>https://fsiblog.io</link>
  14. <description>Future Stack Innovations Blog</description>
  15. <lastBuildDate>Sat, 12 Jul 2025 06:53:10 +0000</lastBuildDate>
  16. <language>en-US</language>
  17. <sy:updatePeriod>
  18. hourly </sy:updatePeriod>
  19. <sy:updateFrequency>
  20. 1 </sy:updateFrequency>
  21. <generator>https://wordpress.org/?v=6.8.1</generator>
  22.  
  23. <image>
  24. <url>https://fsiblog.io/wp-content/uploads/2024/09/FSIBLOG-Logo-100x100.webp</url>
  25. <title>FSIBLOG</title>
  26. <link>https://fsiblog.io</link>
  27. <width>32</width>
  28. <height>32</height>
  29. </image>
  30. <site xmlns="com-wordpress:feed-additions:1">241886150</site> <item>
  31. <title>How Do I Fix the Game Maker Studio Android Error at Compile</title>
  32. <link>https://fsiblog.io/how-do-i-fix-the-game-maker-studio-android-error-at-compile/</link>
  33. <comments>https://fsiblog.io/how-do-i-fix-the-game-maker-studio-android-error-at-compile/#respond</comments>
  34. <dc:creator><![CDATA[Sneed Cody]]></dc:creator>
  35. <pubDate>Sat, 12 Jul 2025 06:53:08 +0000</pubDate>
  36. <category><![CDATA[Android Game]]></category>
  37. <category><![CDATA[Do I Fix the Game Maker Studio Android Error at Compile]]></category>
  38. <category><![CDATA[Fix the Game Maker Studio Android Error at Compile]]></category>
  39. <guid isPermaLink="false">https://fsiblog.io/?p=2991</guid>
  40.  
  41. <description><![CDATA[I recently ran into a frustrating issue while compiling an Android APK in GameMaker Studio Pro v1.4.1567. After setting everything up and hitting the build button, I got this error: Error Code BUILD FAILED C:\Program Files\Android_SDK\tools\ant\build.xml:649: The following error occurred while executing this line: C:\Program Files\Android_SDK\tools\ant\build.xml:694: null returned: 1 At first glance, it looked like [&#8230;]]]></description>
  42. <content:encoded><![CDATA[
  43. <p>I recently ran into a frustrating issue while compiling an Android APK in <strong>GameMaker Studio Pro v1.4.1567</strong>. After setting everything up and hitting the build button, I got this error:</p>
  44.  
  45.  
  46.  
  47. <h2 class="wp-block-heading">Error Code</h2>
  48.  
  49.  
  50.  
  51. <pre class="wp-block-preformatted"><code>BUILD FAILED  <br>C:\Program Files\Android_SDK\tools\ant\build.xml:649: The following error occurred while executing this line:  <br>C:\Program Files\Android_SDK\tools\ant\build.xml:694: null returned: 1</code></pre>
  52.  
  53.  
  54.  
  55. <p>At first glance, it looked like a cryptic build issue. But after some digging, I figured out what was wrong and how to fix it. In this post, I’ll walk you through everything from identifying the cause to enhancing your test project with Android features.</p>
  56.  
  57.  
  58.  
  59. <h2 class="wp-block-heading">Basic GameMaker Android Build Code</h2>
  60.  
  61.  
  62.  
  63. <p>Before troubleshooting, I like to make sure the project itself is working. Here’s a super simple GML code snippet that runs on Android:</p>
  64.  
  65.  
  66.  
  67. <pre class="wp-block-preformatted"><code>// Create Event<br>show_message("Hello Android!");</code></pre>
  68.  
  69.  
  70.  
  71. <p>This helps verify whether GameMaker can successfully compile and launch your game on Android. If this doesn’t build, chances are something is off in your SDK/NDK or Java setup.</p>
  72.  
  73.  
  74.  
  75. <h3 class="wp-block-heading">The Compile Error</h3>
  76.  
  77.  
  78.  
  79. <p>If your build fails with this message:</p>
  80.  
  81.  
  82.  
  83. <pre class="wp-block-preformatted"><code>BUILD FAILED  <br>C:\Program Files\Android_SDK\tools\ant\build.xml:649:  <br>C:\Program Files\Android_SDK\tools\ant\build.xml:694: null returned: 1</code></pre>
  84.  
  85.  
  86.  
  87. <p>It means ANT (the build system used by GameMaker Studio 1.x) ran into a problem usually related to paths, tools, or missing dependencies.</p>
  88.  
  89.  
  90.  
  91. <h3 class="wp-block-heading">Explanation of the Error</h3>
  92.  
  93.  
  94.  
  95. <p>The error comes from <strong>Apache ANT</strong>, which uses XML scripts (<code>build.xml</code>) to handle compiling the Java/Android parts of your GameMaker project.</p>
  96.  
  97.  
  98.  
  99. <p>Specifically:</p>
  100.  
  101.  
  102.  
  103. <ul class="wp-block-list">
  104. <li><strong>Line 694 fails</strong> when ANT expects a valid return value or path, but gets <code>null</code>.</li>
  105.  
  106.  
  107.  
  108. <li>It returns <code>exit code 1</code>, which is a generic “something broke” signal.</li>
  109. </ul>
  110.  
  111.  
  112.  
  113. <p>This usually points to something being <strong>misconfigured, outdated, or missing</strong> in your Android toolchain.</p>
  114.  
  115.  
  116.  
  117. <h3 class="wp-block-heading">Like Causes &amp; Fix</h3>
  118.  
  119.  
  120.  
  121. <p>Here’s a quick table of what might be going wrong and how I fixed it:</p>
  122.  
  123.  
  124.  
  125. <figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>Cause</th><th> Fix</th></tr></thead><tbody><tr><td><strong>Incompatible SDK version</strong></td><td>I was using <strong>API 13</strong>, but upgrading to <strong>API 14 or 16</strong> made the build work without errors. Even though GameMaker says API 10+, modern tools sometimes reject older APIs.</td></tr><tr><td><strong>NDK mismatch</strong></td><td>I’m using <strong>NDK r10e</strong>, which is the right version for GameMaker 1.4. Make sure it’s installed properly and the path is set: <code>C:\Android\ndk\android-ndk-r10e</code>.</td></tr><tr><td><strong>Incorrect Java version</strong></td><td>GameMaker 1.4 doesn’t like newer Java versions. I had to uninstall Java 11 and reinstall <strong>Java JDK 1.7.0_80</strong>. That fixed a lot of ANT issues.</td></tr><tr><td><strong>Missing Build Tools</strong></td><td>GameMaker prefers <strong>Build Tools 22.0.1</strong>. If you’re using a newer SDK Manager, you’ll need to find and manually install that version from Google’s archives.</td></tr></tbody></table></figure>
  126.  
  127.  
  128.  
  129. <h2 class="wp-block-heading">My GameMaker Android Configuration Checklist</h2>
  130.  
  131.  
  132.  
  133. <p>Here’s what finally worked for me. Double-check these:</p>
  134.  
  135.  
  136.  
  137. <ul class="wp-block-list">
  138. <li><strong>SDK Location:</strong><br><code>C:\Program Files\Android_SDK</code></li>
  139.  
  140.  
  141.  
  142. <li><strong>NDK Location:</strong><br><code>C:\Android\ndk\android-ndk-r10e</code></li>
  143.  
  144.  
  145.  
  146. <li><strong>JDK Location:</strong><br><code>C:\Program Files\Java\jdk1.7.0_80</code></li>
  147.  
  148.  
  149.  
  150. <li><strong>Build Tools Version:</strong><br><code>22.0.1</code> installed inside:<br><code>C:\Program Files\Android_SDK\build-tools\22.0.1</code></li>
  151.  
  152.  
  153.  
  154. <li><strong>Target SDK in GameMaker Project Settings:</strong><br>Set to match the installed Android API level (I used 14 or 16).</li>
  155. </ul>
  156.  
  157.  
  158.  
  159. <h2 class="wp-block-heading">More Practice Functionality to Add in Your Game Code</h2>
  160.  
  161.  
  162.  
  163. <p>Once your basic build is working, you might want to test some actual Android-specific features. Here’s what I added to my test project:</p>
  164.  
  165.  
  166.  
  167. <h3 class="wp-block-heading">Vibrate the Device</h3>
  168.  
  169.  
  170.  
  171. <pre class="wp-block-preformatted"><code>// Create Event<br>if (os_type == os_android) {<br>    show_message("Running on Android");<br>    android_vibrate(500); // Vibrate for 500 ms<br>}</code></pre>
  172.  
  173.  
  174.  
  175. <h3 class="wp-block-heading">Play Background Music</h3>
  176.  
  177.  
  178.  
  179. <pre class="wp-block-preformatted"><code>// Create Event<br>audio_play_sound(snd_music, 1, true); // Loop the background music</code></pre>
  180.  
  181.  
  182.  
  183. <p><em>Note: Make sure <code>snd_music</code> is added to your project’s sound assets.</em></p>
  184.  
  185.  
  186.  
  187. <h3 class="wp-block-heading">Animate a Sprite</h3>
  188.  
  189.  
  190.  
  191. <pre class="wp-block-preformatted"><code>// Step Event<br>image_speed = 0.2; // Slows down the sprite animation</code></pre>
  192.  
  193.  
  194.  
  195. <p>Attach a multi frame sprite to your object to make it animate smoothly on-screen.</p>
  196.  
  197.  
  198.  
  199. <h2 class="wp-block-heading">Final Thought</h2>
  200.  
  201.  
  202.  
  203. <p>If you&#8217;re still sticking with <strong>GameMaker Studio 1.4</strong>, you&#8217;re not alone I get the appeal of its simplicity. But working with older SDKs and tools means you&#8217;ll occasionally run into strange build issues like this.</p>
  204.  
  205.  
  206.  
  207. <p>Just remember most of the time, it’s about <strong>toolchain compatibility</strong> especially Java, NDK, and build tools. Take the time to align those, and your Android builds will compile like butter.</p>
  208. ]]></content:encoded>
  209. <wfw:commentRss>https://fsiblog.io/how-do-i-fix-the-game-maker-studio-android-error-at-compile/feed/</wfw:commentRss>
  210. <slash:comments>0</slash:comments>
  211. <post-id xmlns="com-wordpress:feed-additions:1">2991</post-id> </item>
  212. <item>
  213. <title>How to Fix a Error While Building Unity3D Android Game</title>
  214. <link>https://fsiblog.io/how-to-fix-a-error-while-building-unity3d-android-game/</link>
  215. <comments>https://fsiblog.io/how-to-fix-a-error-while-building-unity3d-android-game/#respond</comments>
  216. <dc:creator><![CDATA[Sneed Cody]]></dc:creator>
  217. <pubDate>Sat, 12 Jul 2025 06:29:17 +0000</pubDate>
  218. <category><![CDATA[Android Game]]></category>
  219. <category><![CDATA[Fix a Error While Building Unity3D Android Game]]></category>
  220. <category><![CDATA[How to Fix a Error While Building Unity3D Android Game]]></category>
  221. <guid isPermaLink="false">https://fsiblog.io/?p=2987</guid>
  222.  
  223. <description><![CDATA[While building my Android game using Unity3D, I ran into a frustrating error that brought development to a halt. I was integrating the Facebook SDK and PlayFab SDK, and everything seemed fine until I tried to build for Android. Suddenly, Unity threw an error about plugins &#8220;colliding with each other.&#8221; If you&#8217;re working with third-party [&#8230;]]]></description>
  224. <content:encoded><![CDATA[
  225. <p>While building my Android game using Unity3D, I ran into a frustrating error that brought development to a halt. I was integrating the <strong>Facebook SDK</strong> and <strong>PlayFab SDK</strong>, and everything seemed fine until I tried to build for Android. Suddenly, Unity threw an error about plugins <em>&#8220;colliding with each other.&#8221;</em> If you&#8217;re working with third-party SDKs, chances are you’ll face something similar. Here&#8217;s how I tackled it, what I learned, and how you can avoid it.</p>
  226.  
  227.  
  228.  
  229. <h2 class="wp-block-heading"><strong>Initial Setup</strong></h2>
  230.  
  231.  
  232.  
  233. <p>In my case, the project setup was fairly standard:</p>
  234.  
  235.  
  236.  
  237. <ul class="wp-block-list">
  238. <li><strong>Unity3D</strong> project targeting <strong>Android</strong></li>
  239.  
  240.  
  241.  
  242. <li>Minimum SDK version: <strong>19</strong> (recommended for modern support)</li>
  243.  
  244.  
  245.  
  246. <li>Integrated:
  247. <ul class="wp-block-list">
  248. <li><strong>Facebook SDK for Unity</strong></li>
  249.  
  250.  
  251.  
  252. <li><strong>PlayFab SDK</strong></li>
  253. </ul>
  254. </li>
  255. </ul>
  256.  
  257.  
  258.  
  259. <p>Everything was working great in the editor. But when I hit <strong>Build</strong>, Unity gave me this error:</p>
  260.  
  261.  
  262.  
  263. <h2 class="wp-block-heading"><strong>Error Detail</strong></h2>
  264.  
  265.  
  266.  
  267. <pre class="wp-block-preformatted"><code>Found plugins with same names and architectures, <br>Assets/Plugins/Android/libs/android-support-v4.jar (ARMv7) <br>and Assets/Plugins/Android/android-support-v4.jar (ARMv7). <br>Assign different architectures or delete the duplicate.</code></pre>
  268.  
  269.  
  270.  
  271. <h3 class="wp-block-heading">What does that mean?</h3>
  272.  
  273.  
  274.  
  275. <p>Basically, Unity found <strong>two versions</strong> of the same file (<code>android-support-v4.jar</code>) in different folders. One was in:</p>
  276.  
  277.  
  278.  
  279. <ul class="wp-block-list">
  280. <li><code>Assets/Plugins/Android/libs/</code></li>
  281.  
  282.  
  283.  
  284. <li>The other in <code>Assets/Plugins/Android/</code></li>
  285. </ul>
  286.  
  287.  
  288.  
  289. <p>Because both are targeting the same architecture (ARMv7), Unity doesn’t know which one to use. This results in a <strong>build failure</strong>.</p>
  290.  
  291.  
  292.  
  293. <h2 class="wp-block-heading"><strong>Initial Code Facebook + PlayFab Integration</strong></h2>
  294.  
  295.  
  296.  
  297. <p>Here’s a simplified version of my <code>GameManager.cs</code> script:</p>
  298.  
  299.  
  300.  
  301. <pre class="wp-block-preformatted"><code>using UnityEngine;<br>using PlayFab;<br>using PlayFab.ClientModels;<br>using Facebook.Unity;<br><br>public class GameManager : MonoBehaviour<br>{<br>    void Start()<br>    {<br>        if (!FB.IsInitialized)<br>        {<br>            FB.Init(OnFBInitComplete, OnHideUnity);<br>        }<br>        else<br>        {<br>            FB.ActivateApp();<br>        }<br><br>        PlayFabLogin();<br>    }<br><br>    void OnFBInitComplete()<br>    {<br>        if (FB.IsInitialized)<br>        {<br>            FB.ActivateApp();<br>        }<br>        else<br>        {<br>            Debug.LogError("Failed to initialize Facebook SDK");<br>        }<br>    }<br><br>    void OnHideUnity(bool isGameShown)<br>    {<br>        Time.timeScale = isGameShown ? 1 : 0;<br>    }<br><br>    void PlayFabLogin()<br>    {<br>        var request = new LoginWithCustomIDRequest { CustomId = "UnityPlayer", CreateAccount = true };<br>        PlayFabClientAPI.LoginWithCustomID(request, <br>            result => Debug.Log("PlayFab Login Success!"),<br>            error => Debug.LogError("PlayFab Login Error: " + error.GenerateErrorReport())<br>        );<br>    }<br>}</code></pre>
  302.  
  303.  
  304.  
  305. <h2 class="wp-block-heading"><strong>Attempt Fix &amp; A New Problem</strong></h2>
  306.  
  307.  
  308.  
  309. <p>Thinking I’d solved the issue, I deleted the file from <code>libs/</code>. But then, Unity gave me a <strong>new error</strong>:</p>
  310.  
  311.  
  312.  
  313. <pre class="wp-block-preformatted"><code>Main manifest has &lt;uses-sdk /> but library uses minSdkVersion='15'</code></pre>
  314.  
  315.  
  316.  
  317. <p>This happened because the <strong>Facebook SDK</strong> expects a <strong>minimum SDK version of 15</strong>, but my Unity project didn’t specify it properly. When Unity merges all the manifest files (which it does automatically), it found a mismatch.</p>
  318.  
  319.  
  320.  
  321. <h2 class="wp-block-heading"><strong>The Fix</strong></h2>
  322.  
  323.  
  324.  
  325. <h3 class="wp-block-heading"><strong>Resolve the Plugin Collision</strong></h3>
  326.  
  327.  
  328.  
  329. <ul class="wp-block-list">
  330. <li>Keep <strong>one</strong> copy of <code>android-support-v4.jar</code>.</li>
  331.  
  332.  
  333.  
  334. <li>I kept the one in: <code>Assets/Plugins/Android/android-support-v4.jar</code></li>
  335.  
  336.  
  337.  
  338. <li>Then deleted: <code>Assets/Plugins/Android/libs/android-support-v4.jar</code></li>
  339. </ul>
  340.  
  341.  
  342.  
  343. <h3 class="wp-block-heading"><strong>Match the SDK Versions</strong></h3>
  344.  
  345.  
  346.  
  347. <ul class="wp-block-list">
  348. <li>Go to <code>Edit > Project Settings > Player > Android</code>.</li>
  349.  
  350.  
  351.  
  352. <li>Under <strong>Other Settings</strong>, set:
  353. <ul class="wp-block-list">
  354. <li><strong>Minimum API Level</strong> to <strong>API 15</strong> or higher.</li>
  355.  
  356.  
  357.  
  358. <li>I recommend <strong>API 19</strong> or even <strong>API 21</strong> for better device coverage.</li>
  359. </ul>
  360. </li>
  361. </ul>
  362.  
  363.  
  364.  
  365. <h3 class="wp-block-heading"><strong>Verify AndroidManifest.xml</strong></h3>
  366.  
  367.  
  368.  
  369. <p>Ensure your main <code>AndroidManifest.xml</code> looks like this:</p>
  370.  
  371.  
  372.  
  373. <pre class="wp-block-preformatted"><code>&lt;uses-sdk android:minSdkVersion="15" android:targetSdkVersion="30" /></code></pre>
  374.  
  375.  
  376.  
  377. <p>And make sure no library manifest files are overriding this.</p>
  378.  
  379.  
  380.  
  381. <h2 class="wp-block-heading"><strong>Plugin Checker Script</strong></h2>
  382.  
  383.  
  384.  
  385. <p>To avoid these problems in the future, I created a Unity Editor tool that checks for duplicate <code>.jar</code> files. Here’s the code:</p>
  386.  
  387.  
  388.  
  389. <pre class="wp-block-preformatted"><code>// Editor/PluginChecker.cs<br>using UnityEditor;<br>using UnityEngine;<br>using System.IO;<br><br>public class PluginChecker : EditorWindow<br>{<br>    [MenuItem("Tools/Check Android Plugin Duplicates")]<br>    static void CheckForDuplicates()<br>    {<br>        string[] jars = Directory.GetFiles("Assets/Plugins/Android", "*.jar", SearchOption.AllDirectories);<br>        var duplicates = new System.Collections.Generic.Dictionary&lt;string, string>();<br><br>        foreach (string path in jars)<br>        {<br>            string fileName = Path.GetFileName(path);<br>            if (duplicates.ContainsKey(fileName))<br>                Debug.LogWarning($"Duplicate plugin found: {fileName}\n- {duplicates[fileName]}\n- {path}");<br>            else<br>                duplicates[fileName] = path;<br>        }<br>    }<br>}</code></pre>
  390.  
  391.  
  392.  
  393. <p>Just run it from <strong>Unity&#8217;s top menu</strong> under:<br><img src="https://s.w.org/images/core/emoji/15.1.0/72x72/1f6e0.png" alt="🛠" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <code>Tools &gt; Check Android Plugin Duplicates</code></p>
  394.  
  395.  
  396.  
  397. <h2 class="wp-block-heading"><strong>Final Thought</strong></h2>
  398.  
  399.  
  400.  
  401. <p>Plugin conflicts in Unity especially when working with Android SDKs are more common than I expected. But the fix usually comes down to <strong>clearing out duplicates</strong>, <strong>setting the correct SDK version</strong>, and <strong>making sure your manifest files play nicely together</strong>. If you’re working with multiple SDKs like Facebook and PlayFab, take the time to manage your Android plugins cleanly. And always double-check your build settings before going live.</p>
  402. ]]></content:encoded>
  403. <wfw:commentRss>https://fsiblog.io/how-to-fix-a-error-while-building-unity3d-android-game/feed/</wfw:commentRss>
  404. <slash:comments>0</slash:comments>
  405. <post-id xmlns="com-wordpress:feed-additions:1">2987</post-id> </item>
  406. <item>
  407. <title>How to Fix a Wordly Guess Game Error StringIndexOutOfBoundsException</title>
  408. <link>https://fsiblog.io/how-to-fix-a-wordly-guess-game-error-stringindexoutofboundsexception/</link>
  409. <comments>https://fsiblog.io/how-to-fix-a-wordly-guess-game-error-stringindexoutofboundsexception/#respond</comments>
  410. <dc:creator><![CDATA[Sneed Cody]]></dc:creator>
  411. <pubDate>Fri, 11 Jul 2025 06:30:53 +0000</pubDate>
  412. <category><![CDATA[JavaScript]]></category>
  413. <category><![CDATA[Game]]></category>
  414. <category><![CDATA[Fix a Wordly Guess Game Error StringIndexOutOfBoundsException]]></category>
  415. <category><![CDATA[How to Fix a Wordly Guess Game Error StringIndexOutOfBoundsException]]></category>
  416. <guid isPermaLink="false">https://fsiblog.io/?p=2984</guid>
  417.  
  418. <description><![CDATA[I was building a simple Wordle style game error using Java Swing. The idea was straightforward let the player enter a five letter word, compare it against a random five-letter word selected from a .txt file, and highlight each letter based on correctness. When I hardcoded the target word like this: String check_word = "moizz"; [&#8230;]]]></description>
  419. <content:encoded><![CDATA[
  420. <p>I was building a simple <strong>Wordle style game</strong> <strong>error</strong> using Java Swing. The idea was straightforward let the player enter a five letter word, compare it against a random five-letter word selected from a <code>.txt</code> file, and highlight each letter based on correctness.</p>
  421.  
  422.  
  423.  
  424. <p>When I hardcoded the target word like this:</p>
  425.  
  426.  
  427.  
  428. <pre class="wp-block-preformatted"><code>String check_word = "moizz";</code></pre>
  429.  
  430.  
  431.  
  432. <p>Everything worked beautifully. The program read the user&#8217;s input, compared characters, and displayed results via colored labels green for correct position, yellow for wrong position, and gray for letters not in the word.</p>
  433.  
  434.  
  435.  
  436. <p>Then I decided to make the game dynamic. Instead of using a hardcoded word, I loaded words from a file:</p>
  437.  
  438.  
  439.  
  440. <pre class="wp-block-preformatted"><code>BufferedReader reader = new BufferedReader(new FileReader("targetWords.txt"));</code></pre>
  441.  
  442.  
  443.  
  444. <p><strong>And that’s when the problem started.</strong></p>
  445.  
  446.  
  447.  
  448. <h2 class="wp-block-heading">The Unexpected Error</h2>
  449.  
  450.  
  451.  
  452. <p>As soon as I used the file-sourced word, my game crashed with this error:</p>
  453.  
  454.  
  455.  
  456. <pre class="wp-block-preformatted"><code>java.lang.StringIndexOutOfBoundsException: String index out of range: 5</code></pre>
  457.  
  458.  
  459.  
  460. <p>I was confused. My word list only had five-letter words. Why was it failing?</p>
  461.  
  462.  
  463.  
  464. <p>I spent <strong>hours</strong> trying to debug this. I printed the words. I checked lengths. I even thought Java had a glitch!</p>
  465.  
  466.  
  467.  
  468. <h2 class="wp-block-heading">What’s Causing the Error</h2>
  469.  
  470.  
  471.  
  472. <p>After calming down and taking a step back, I revisited the error:</p>
  473.  
  474.  
  475.  
  476. <pre class="wp-block-preformatted"><code>StringIndexOutOfBoundsException: String index out of range: 5</code></pre>
  477.  
  478.  
  479.  
  480. <p>That means I tried to access a character at an index that doesn&#8217;t exist.</p>
  481.  
  482.  
  483.  
  484. <p>In Java, <strong>string indexing starts at 0</strong>, so if your word has five characters, the valid indexes are <strong>0 to 4</strong>.</p>
  485.  
  486.  
  487.  
  488. <p>But here’s what my code did:</p>
  489.  
  490.  
  491.  
  492. <pre class="wp-block-preformatted"><code>char first = take_word.charAt(1);<br>...<br>char fifth = take_word.charAt(5); // Out of bounds!</code></pre>
  493.  
  494.  
  495.  
  496. <p><strong>Boom There&#8217;s the bug.</strong></p>
  497.  
  498.  
  499.  
  500. <p>By calling <code>charAt(5)</code>, I was trying to access the <strong>6th character</strong>. If the word was exactly five letters, this index didn’t exist — and Java doesn’t forgive that.</p>
  501.  
  502.  
  503.  
  504. <p>Even worse, if the input string (either user or file-based) was shorter than five characters due to whitespace or a mistake, this error would be thrown <strong>immediately</strong>.</p>
  505.  
  506.  
  507.  
  508. <h2 class="wp-block-heading">Root Cause in the File Read Version</h2>
  509.  
  510.  
  511.  
  512. <p>This issue only occurred when I used words from the file. Here&#8217;s what was happening:</p>
  513.  
  514.  
  515.  
  516. <ul class="wp-block-list">
  517. <li>Some lines had <strong>extra spaces</strong>, or the word had <strong>newline characters</strong>.</li>
  518.  
  519.  
  520.  
  521. <li>The <code>.trim()</code> call was missing or misused.</li>
  522.  
  523.  
  524.  
  525. <li>And, of course, I had that nasty <code>charAt(5)</code>.</li>
  526. </ul>
  527.  
  528.  
  529.  
  530. <p>So it wasn’t just about bad indexing I also had to <strong>validate word lengths properly</strong> and <strong>clean up file input</strong>.</p>
  531.  
  532.  
  533.  
  534. <h2 class="wp-block-heading">Fix and Best Practices</h2>
  535.  
  536.  
  537.  
  538. <p>After learning my lesson, I rewrote the file handling and input validation logic. Here&#8217;s how I cleaned it up:</p>
  539.  
  540.  
  541.  
  542. <ul class="wp-block-list">
  543. <li>I only add words from the file if they’re <strong>exactly 5 letters</strong>.</li>
  544.  
  545.  
  546.  
  547. <li>I trimmed everything aggressively.</li>
  548.  
  549.  
  550.  
  551. <li>I looped through characters from index <code>0 to 4</code> — not 5.</li>
  552.  
  553.  
  554.  
  555. <li>I added user-friendly GUI feedback if the input is invalid.</li>
  556. </ul>
  557.  
  558.  
  559.  
  560. <h2 class="wp-block-heading">Improve Code with More Feature</h2>
  561.  
  562.  
  563.  
  564. <pre class="wp-block-preformatted"><code>try {<br>    BufferedReader reader = new BufferedReader(new FileReader("E:\\WordyGame\\src\\wordygame\\targetWords.txt"));<br>    List&lt;String> words = new ArrayList&lt;>();<br>    String line;<br><br>    // Load and clean words from file<br>    while ((line = reader.readLine()) != null) {<br>        String[] wordsLine = line.trim().split("\\s+"); // Split by whitespace<br>        for (String word : wordsLine) {<br>            if (word.trim().length() == 5) {<br>                words.add(word.trim().toLowerCase());<br>            }<br>        }<br>    }<br>    reader.close();<br><br>    if (words.isEmpty()) {<br>        JOptionPane.showMessageDialog(this, "No valid 5-letter words found in file!");<br>        return;<br>    }<br><br>    // Pick a random word<br>    Random rand = new Random();<br>    String check_word = words.get(rand.nextInt(words.size()));<br>    System.out.println("Target Word: " + check_word);<br><br>    // Get user input<br>    String take_word = type_word.getText().trim().toLowerCase();<br>    System.out.println("User Word: " + take_word);<br><br>    // Validate input<br>    if (take_word.length() != 5) {<br>        JOptionPane.showMessageDialog(this, "Only 5-letter words are allowed.");<br>        return;<br>    }<br><br>    // Compare and update GUI<br>    JLabel[] wordLabels = {word_1, word_2, word_3, word_4, word_5};<br>    for (int i = 0; i &lt; 5; i++) {<br>        char userChar = take_word.charAt(i);<br>        char targetChar = check_word.charAt(i);<br><br>        wordLabels[i].setText(String.valueOf(userChar));<br>        <br>        if (userChar == targetChar) {<br>            wordLabels[i].setBackground(Color.GREEN); // Correct position<br>        } else if (check_word.indexOf(userChar) >= 0) {<br>            wordLabels[i].setBackground(Color.YELLOW); // Wrong position<br>        } else {<br>            wordLabels[i].setBackground(Color.LIGHT_GRAY); // Not found<br>        }<br>    }<br><br>} catch (Exception e) {<br>    e.printStackTrace();<br>    JOptionPane.showMessageDialog(this, "An error occurred: " + e.getMessage());<br>}</code></pre>
  565.  
  566.  
  567.  
  568. <h2 class="wp-block-heading">Extra Practice Feature to Add</h2>
  569.  
  570.  
  571.  
  572. <p>Once I got the base game working, I realized there were so many ways to make it better. Here are some ideas I added to my to-do list:</p>
  573.  
  574.  
  575.  
  576. <ul class="wp-block-list">
  577. <li><strong>Turn-based system</strong> (like 6 attempts)</li>
  578.  
  579.  
  580.  
  581. <li><strong>Win/Loss messages</strong></li>
  582.  
  583.  
  584.  
  585. <li><strong>Timer or countdown</strong></li>
  586.  
  587.  
  588.  
  589. <li><strong>History tracking</strong> (previous guesses)</li>
  590.  
  591.  
  592.  
  593. <li><strong>Dynamic feedback</strong> just like Wordle (color-coded per character)</li>
  594. </ul>
  595.  
  596.  
  597.  
  598. <p>Each of these could enhance the experience and help me sharpen my Java skills even more.</p>
  599.  
  600.  
  601.  
  602. <h2 class="wp-block-heading">Final Thought</h2>
  603.  
  604.  
  605.  
  606. <p>In the end, this small bug taught me a big lesson never assume your input is clean or the length is as expected. By properly validating data, trimming whitespace, and carefully using string indexes, I was able to fix the issue and improve my game. Debugging can be frustrating, but it&#8217;s also where the real learning happens.</p>
  607. ]]></content:encoded>
  608. <wfw:commentRss>https://fsiblog.io/how-to-fix-a-wordly-guess-game-error-stringindexoutofboundsexception/feed/</wfw:commentRss>
  609. <slash:comments>0</slash:comments>
  610. <post-id xmlns="com-wordpress:feed-additions:1">2984</post-id> </item>
  611. <item>
  612. <title>How to Fix NullPointerException Swing Card Game Error in Java?</title>
  613. <link>https://fsiblog.io/how-to-fix-nullpointerexception-swing-card-game-error-in-java/</link>
  614. <comments>https://fsiblog.io/how-to-fix-nullpointerexception-swing-card-game-error-in-java/#respond</comments>
  615. <dc:creator><![CDATA[Sneed Cody]]></dc:creator>
  616. <pubDate>Fri, 11 Jul 2025 06:15:23 +0000</pubDate>
  617. <category><![CDATA[Game]]></category>
  618. <category><![CDATA[JavaScript]]></category>
  619. <category><![CDATA[Fix NullPointerException Swing Card Game Error in Java?]]></category>
  620. <category><![CDATA[How to Fix NullPointerException Swing Card Game Error in Java?]]></category>
  621. <guid isPermaLink="false">https://fsiblog.io/?p=2981</guid>
  622.  
  623. <description><![CDATA[I’m currently working on a Java Swing card game for an assignment, and I ran into a frustrating problem: I kept getting a NullPointerException whenever I tried to display a card image after clicking a button. After a bit of digging and testing, I finally figured out what was wrong and I’d love to share [&#8230;]]]></description>
  624. <content:encoded><![CDATA[
  625. <p>I’m currently working on a <strong>Java Swing card game</strong> for an assignment, and I ran into a frustrating problem: I kept getting a <code>NullPointerException</code> whenever I tried to display a card image after clicking a button. After a bit of digging and testing, I finally figured out what was wrong and I’d love to share it with you so you don’t fall into the same trap!</p>
  626.  
  627.  
  628.  
  629. <h2 class="wp-block-heading">The Problem NullPointerException in Swing</h2>
  630.  
  631.  
  632.  
  633. <p>Here&#8217;s the simplified version of the original code I wrote in my <code>CardGamePanel.java</code> class:</p>
  634.  
  635.  
  636.  
  637. <h3 class="wp-block-heading">Original Code Snippet</h3>
  638.  
  639.  
  640.  
  641. <pre class="wp-block-preformatted"><code>Graphics g;<br><br>CardGamePanel() {<br>    D.buildDeck();<br>    for (int i = 0; i &lt; cards.length; i++) {<br>        Random r = new Random();<br>        int num1 = r.nextInt(52);                       <br>        cards[i] = new DisplayableCard("1.png", 30, 30);            <br>    }<br>}<br><br>public void go() {<br>    if (count &lt; 9) {<br>        cards[count].display(g); // ERROR HERE<br>    }<br>    count++;<br>}</code></pre>
  642.  
  643.  
  644.  
  645. <p>And here&#8217;s the display method from the <code>DisplayableCard.java</code> class:</p>
  646.  
  647.  
  648.  
  649. <pre class="wp-block-preformatted"><code>public void display(Graphics g) {<br>    image = new ImageIcon(getClass().getResource(imageFilename)).getImage();<br>    g.drawImage(image, x, y, null); // ERROR HERE<br>}</code></pre>
  650.  
  651.  
  652.  
  653. <h2 class="wp-block-heading">The Error</h2>
  654.  
  655.  
  656.  
  657. <p>When I clicked the &#8220;Flip&#8221; button, this error was thrown:</p>
  658.  
  659.  
  660.  
  661. <pre class="wp-block-preformatted"><code>Exception in thread "AWT-EventQueue-1"<br>java.lang.NullPointerException<br>    at DisplayableCard.display(DisplayableCard.java:16)<br>    at CardGamePanel.go(CardGamePanel.java:31)</code></pre>
  662.  
  663.  
  664.  
  665. <p>At first glance, I thought something was wrong with how I loaded the image. But the real problem was deeper.</p>
  666.  
  667.  
  668.  
  669. <h2 class="wp-block-heading">What’s Actually Wrong?</h2>
  670.  
  671.  
  672.  
  673. <p>The error was coming from <code>Graphics g</code>, which was <code>null</code>. I had declared <code>Graphics g</code> in the class, but <strong>I never initialized it</strong>. In Java Swing, <code>Graphics</code> is automatically passed to components when they’re drawn using the <code>paintComponent(Graphics g)</code> method—not manually!</p>
  674.  
  675.  
  676.  
  677. <p>So by calling <code>cards[count].display(g);</code> with an uninitialized <code>g</code>, I was asking Java to draw on nothing!</p>
  678.  
  679.  
  680.  
  681. <h2 class="wp-block-heading">The Fix Use paintComponent() and Repaint()</h2>
  682.  
  683.  
  684.  
  685. <p>To fix the error, I needed to:</p>
  686.  
  687.  
  688.  
  689. <ul class="wp-block-list">
  690. <li>Let Swing handle the graphics.</li>
  691.  
  692.  
  693.  
  694. <li>Call <code>repaint()</code> when I wanted the cards to appear.</li>
  695.  
  696.  
  697.  
  698. <li>Move all drawing logic into the <code>paintComponent()</code> method, where <code>Graphics g</code> is safely initialized by the system.</li>
  699. </ul>
  700.  
  701.  
  702.  
  703. <h2 class="wp-block-heading">Final Working Code</h2>
  704.  
  705.  
  706.  
  707. <h3 class="wp-block-heading"><code>CardGamePanel.java</code></h3>
  708.  
  709.  
  710.  
  711. <pre class="wp-block-preformatted"><code>class CardGamePanel extends JPanel {<br>    private DisplayableCard[] cards = new DisplayableCard[10];<br>    private int count = 0;<br><br>    public CardGamePanel() {<br>        for (int i = 0; i &lt; cards.length; i++) {<br>            cards[i] = new DisplayableCard("1.png", 30 + i * 40, 30); // Spread cards out<br>        }<br>    }<br><br>    public void go() {<br>        if (count &lt; cards.length) {<br>            count++;<br>            repaint(); // Triggers paintComponent<br>        }<br>    }<br><br>    @Override<br>    protected void paintComponent(Graphics g) {<br>        super.paintComponent(g);<br>        for (int i = 0; i &lt; count; i++) {<br>            cards[i].display(g); // Now g is initialized correctly<br>        }<br>    }<br>}</code></pre>
  712.  
  713.  
  714.  
  715. <h3 class="wp-block-heading"> <code>DisplayableCard.java</code></h3>
  716.  
  717.  
  718.  
  719. <pre class="wp-block-preformatted"><code>public class DisplayableCard extends Card implements Displayable {<br>    private int x, y;<br>    private Image image;<br><br>    public DisplayableCard(String filename, int x, int y) {<br>        this.x = x;<br>        this.y = y;<br>        this.image = new ImageIcon(getClass().getResource(filename)).getImage();<br>    }<br><br>    public void display(Graphics g) {<br>        g.drawImage(image, x, y, null); // Safe to use now<br>    }<br>}</code></pre>
  720.  
  721.  
  722.  
  723. <hr class="wp-block-separator has-alpha-channel-opacity"/>
  724.  
  725.  
  726.  
  727. <h3 class="wp-block-heading"><code>Simple.java</code></h3>
  728.  
  729.  
  730.  
  731. <pre class="wp-block-preformatted"><code>public class Simple extends JApplet {<br>    private CardGamePanel cgp;<br>    private JButton btnD = new JButton("Flip");<br><br>    public void init() {<br>        cgp = new CardGamePanel();<br>        JPanel panel2 = new JPanel();<br>        panel2.add(btnD);<br><br>        btnD.addActionListener(new ActionListener() {<br>            public void actionPerformed(ActionEvent e) {<br>                cgp.go(); // Safely triggers repaint<br>            }<br>        });<br><br>        add(cgp, BorderLayout.CENTER);<br>        add(panel2, BorderLayout.SOUTH);<br>        setSize(500, 500);<br>    }<br></code></pre>
  732.  
  733.  
  734.  
  735. <h2 class="wp-block-heading">Additional Practice Feature to Add</h2>
  736.  
  737.  
  738.  
  739. <p>Now that the error is fixed, here are some fun and educational ideas to improve your card game:</p>
  740.  
  741.  
  742.  
  743. <h3 class="wp-block-heading">Shuffle the Cards</h3>
  744.  
  745.  
  746.  
  747. <pre class="wp-block-preformatted"><code>Collections.shuffle(Arrays.asList(cards));</code></pre>
  748.  
  749.  
  750.  
  751. <h3 class="wp-block-heading">Add Card Flip Animation</h3>
  752.  
  753.  
  754.  
  755. <p>Use <code>javax.swing.Timer</code> to create a delay and animate the flipping.</p>
  756.  
  757.  
  758.  
  759. <h3 class="wp-block-heading">Track Score or Turns</h3>
  760.  
  761.  
  762.  
  763. <pre class="wp-block-preformatted"><code>private int playerScore = 0;<br>JLabel scoreLabel = new JLabel("Score: 0");<br>// Update label when player wins a round</code></pre>
  764.  
  765.  
  766.  
  767. <h3 class="wp-block-heading">Load Real Card Images Dynamically</h3>
  768.  
  769.  
  770.  
  771. <pre class="wp-block-preformatted"><code>String filename = "cards/" + rank + suit + ".png"; // e.g., "2H.png"</code></pre>
  772.  
  773.  
  774.  
  775. <h3 class="wp-block-heading">Add Multiplayer Support</h3>
  776.  
  777.  
  778.  
  779. <p>Alternate turns with a boolean flag:</p>
  780.  
  781.  
  782.  
  783. <pre class="wp-block-preformatted"><code>boolean isPlayer1Turn = true;</code></pre>
  784.  
  785.  
  786.  
  787. <h2 class="wp-block-heading">Summary</h2>
  788.  
  789.  
  790.  
  791. <figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>Issue</th><th>Solution</th></tr></thead><tbody><tr><td><code>NullPointerException</code> caused by using null <code>Graphics</code></td><td>Use <code>paintComponent(Graphics g)</code></td></tr><tr><td>Manually calling <code>display(g)</code></td><td>Call <code>repaint()</code> to trigger redraw</td></tr><tr><td>Static card positions</td><td>Use loops and spacing for layout</td></tr></tbody></table></figure>
  792.  
  793.  
  794.  
  795. <h2 class="wp-block-heading">Final Thought</h2>
  796.  
  797.  
  798.  
  799. <p>Building this card game has taught me a lot about <strong>Swing graphics</strong>, <strong>event-driven programming</strong>, and <strong>debugging common Java errors</strong>. If you&#8217;re also struggling with <code>NullPointerException</code>, don’t worry it’s one of the most common issues in Java. The key is understanding how Swing handles painting and always letting the framework manage <code>Graphics</code>.</p>
  800. ]]></content:encoded>
  801. <wfw:commentRss>https://fsiblog.io/how-to-fix-nullpointerexception-swing-card-game-error-in-java/feed/</wfw:commentRss>
  802. <slash:comments>0</slash:comments>
  803. <post-id xmlns="com-wordpress:feed-additions:1">2981</post-id> </item>
  804. <item>
  805. <title>How Did I Fix the Exception Error That Crash My First Java Game</title>
  806. <link>https://fsiblog.io/how-did-i-fix-the-exception-error-that-crash-my-first-java-game/</link>
  807. <comments>https://fsiblog.io/how-did-i-fix-the-exception-error-that-crash-my-first-java-game/#respond</comments>
  808. <dc:creator><![CDATA[Sneed Cody]]></dc:creator>
  809. <pubDate>Thu, 10 Jul 2025 07:34:44 +0000</pubDate>
  810. <category><![CDATA[Game]]></category>
  811. <category><![CDATA[JavaScript]]></category>
  812. <category><![CDATA[Did I Fix the Exception Error That Crash My First Java Game]]></category>
  813. <category><![CDATA[Fix the Exception Error That Crash My First Java Game]]></category>
  814. <guid isPermaLink="false">https://fsiblog.io/?p=2976</guid>
  815.  
  816. <description><![CDATA[I recently started learning Java and was super excited to build something fun a simple game window using Java’s Canvas and JFrame. It felt like I was stepping into the world of game development. Everything seemed to go well until I ran the program and saw this dreaded error: Error Code Exception in thread "main" [&#8230;]]]></description>
  817. <content:encoded><![CDATA[
  818. <p>I recently started learning Java and was super excited to build something fun a simple game window using Java’s <code>Canvas</code> and <code>JFrame</code>. It felt like I was stepping into the world of game development. Everything seemed to go well until I ran the program and saw this dreaded error:</p>
  819.  
  820.  
  821.  
  822. <h2 class="wp-block-heading">Error Code</h2>
  823.  
  824.  
  825.  
  826. <pre class="wp-block-preformatted"><code>Exception in thread "main" java.lang.Error: Unresolved compilation problem:</code></pre>
  827.  
  828.  
  829.  
  830. <p>At first, I had no idea what this meant. It didn’t tell me much except that <em>something</em> was wrong in the code. After some digging (and a lot of trial and error), I discovered a tiny mistake that caused it all. Here’s how I fixed the error and used the experience to add cool new features that made the project more exciting.</p>
  831.  
  832.  
  833.  
  834. <h2 class="wp-block-heading">The Working Java Code</h2>
  835.  
  836.  
  837.  
  838. <pre class="wp-block-preformatted"><code>package Happily.Insane.Rain;<br><br>import java.awt.Canvas;<br>import java.awt.Dimension;<br>import javax.swing.JFrame;<br><br>public class Game extends Canvas implements Runnable {<br>    private static final long serialVersionUID = 1L;<br><br>    public static int width = 300;<br>    public static int height = width / 16 * 9; // FIXED: Added 'int'<br>    public static int scale = 3;<br><br>    private Thread thread;<br>    private JFrame frame;<br>    private boolean running = false;<br><br>    public Game() {<br>        Dimension size = new Dimension(width * scale, height * scale);<br>        setPreferredSize(size);<br><br>        frame = new JFrame();<br>    }<br><br>    public synchronized void start() {<br>        System.out.println("Game started.");<br>        running = true;<br>        thread = new Thread(this, "Display");<br>        thread.start();<br>    }<br><br>    public synchronized void stop() {<br>        System.out.println("Stopping game...");<br>        running = false;<br>        try {<br>            thread.join();<br>        } catch (InterruptedException e) {<br>            e.printStackTrace();<br>        }<br>    }<br><br>    public void run() {<br>        long lastTime = System.currentTimeMillis();<br>        int frames = 0;<br><br>        while (running) {<br>            System.out.println("Running...");<br>            frames++;<br><br>            if (System.currentTimeMillis() - lastTime >= 1000) {<br>                System.out.println("FPS: " + frames);<br>                frames = 0;<br>                lastTime += 1000;<br>            }<br><br>            try {<br>                Thread.sleep(16); // ~60 FPS<br>            } catch (InterruptedException e) {<br>                e.printStackTrace();<br>            }<br>        }<br><br>        System.out.println("Game stopped.");<br>    }<br><br>    public static void main(String[] args) {<br>        Game game = new Game();<br>        game.frame.setResizable(false);<br>        game.frame.setTitle("Rain - " + width * scale + "x" + height * scale); // &#x1fa9f; Display dimensions<br>        game.frame.add(game);<br>        game.frame.pack();<br>        game.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<br>        game.frame.setLocationRelativeTo(null);<br>        game.frame.setVisible(true);<br><br>        game.start();<br>    }<br>}</code></pre>
  839.  
  840.  
  841.  
  842. <h3 class="wp-block-heading">What Was the Error and How Did I Fix It?</h3>
  843.  
  844.  
  845.  
  846. <p>The problem was with this line:</p>
  847.  
  848.  
  849.  
  850. <pre class="wp-block-preformatted"><code>public static height = width / 16 * 9;</code></pre>
  851.  
  852.  
  853.  
  854. <p>Java threw a compilation error because I forgot to declare the <strong>data type</strong> of the variable <code>height</code>. Unlike Python or JavaScript, Java requires you to explicitly state types like <code>int</code>, <code>double</code>, or <code>String</code>.</p>
  855.  
  856.  
  857.  
  858. <h3 class="wp-block-heading">Fix Version:</h3>
  859.  
  860.  
  861.  
  862. <pre class="wp-block-preformatted"><code>public static int height = width / 16 * 9;</code></pre>
  863.  
  864.  
  865.  
  866. <p>Once I made this small fix, the program compiled and launched the window as expected.</p>
  867.  
  868.  
  869.  
  870. <h2 class="wp-block-heading">Adding More Practice Functionality</h2>
  871.  
  872.  
  873.  
  874. <p>After fixing the error, I didn’t want to stop there. I figured I could learn more by improving the program:</p>
  875.  
  876.  
  877.  
  878. <ul class="wp-block-list">
  879. <li>Added <strong>window dimensions</strong> to the title bar</li>
  880.  
  881.  
  882.  
  883. <li>Simulated a <strong>frame rate counter (FPS)</strong></li>
  884.  
  885.  
  886.  
  887. <li>Printed clear <strong>start and stop messages</strong></li>
  888.  
  889.  
  890.  
  891. <li>Controlled the loop using <code>Thread.sleep()</code> to mimic real-time frame updates</li>
  892. </ul>
  893.  
  894.  
  895.  
  896. <p>This helped me understand how a basic game loop works running continuously, printing updates, and handling timing.</p>
  897.  
  898.  
  899.  
  900. <h3 class="wp-block-heading">What I Learned Through This Experience</h3>
  901.  
  902.  
  903.  
  904. <p><strong>Pay attention to your syntax</strong>, especially when using a strongly typed language like Java. The compiler doesn’t always give helpful messages, but with patience and curiosity, I figured it out.</p>
  905.  
  906.  
  907.  
  908. <p>Here are my key takeaways:</p>
  909.  
  910.  
  911.  
  912. <ul class="wp-block-list">
  913. <li><strong>Always declare variable types</strong> in Java no shortcuts.</li>
  914.  
  915.  
  916.  
  917. <li><strong>Use <code>System.out.println</code></strong> often to debug and observe behavior.</li>
  918.  
  919.  
  920.  
  921. <li><strong><code>Thread.sleep()</code></strong> is your friend when simulating time and frames.</li>
  922.  
  923.  
  924.  
  925. <li><strong>Keep building and experimenting.</strong> Every improvement deepens your understanding.</li>
  926. </ul>
  927.  
  928.  
  929.  
  930. <h2 class="wp-block-heading">Final Thought</h2>
  931.  
  932.  
  933.  
  934. <p>Starting with Java game development was intimidating at first, especially when cryptic errors popped up. But fixing that single line not only solved the problem it opened the door to understanding threads, game loops, and UI basics. The process of debugging, improving, and experimenting turned frustration into motivation.</p>
  935. ]]></content:encoded>
  936. <wfw:commentRss>https://fsiblog.io/how-did-i-fix-the-exception-error-that-crash-my-first-java-game/feed/</wfw:commentRss>
  937. <slash:comments>0</slash:comments>
  938. <post-id xmlns="com-wordpress:feed-additions:1">2976</post-id> </item>
  939. <item>
  940. <title>How to Fix The Java Game Crash Error When My Human Tried to Attack the Orc</title>
  941. <link>https://fsiblog.io/how-to-fix-the-java-game-crash-error-when-my-human-tried-to-attack-the-orc/</link>
  942. <comments>https://fsiblog.io/how-to-fix-the-java-game-crash-error-when-my-human-tried-to-attack-the-orc/#respond</comments>
  943. <dc:creator><![CDATA[Sneed Cody]]></dc:creator>
  944. <pubDate>Thu, 10 Jul 2025 07:07:11 +0000</pubDate>
  945. <category><![CDATA[Game]]></category>
  946. <category><![CDATA[Fix The Java Game Crash Error When My Human Tried to Attack the Orc]]></category>
  947. <category><![CDATA[How to Fix The Java Game Crash Error When My Human Tried to Attack the Orc]]></category>
  948. <guid isPermaLink="false">https://fsiblog.io/?p=2973</guid>
  949.  
  950. <description><![CDATA[When I first started building a small Java combat game between a Human and an Orc, I was excited to see them fight with swords and axes. But instead of battle cries, I kept getting a frustrating error in the console: Exception in thread "main" java.lang.NullPointerException at Player.attack(Player.java:72) at Main.main(Main.java:15) This was my first major [&#8230;]]]></description>
  951. <content:encoded><![CDATA[
  952. <p>When I first started building a small Java combat game between a <strong>Human</strong> and an <strong>Orc</strong>, I was excited to see them fight with swords and axes. But instead of battle cries, I kept getting a frustrating error in the console:</p>
  953.  
  954.  
  955.  
  956. <pre class="wp-block-preformatted"><code>Exception in thread "main" java.lang.NullPointerException<br>    at Player.attack(Player.java:72)<br>    at Main.main(Main.java:15)</code></pre>
  957.  
  958.  
  959.  
  960. <p>This was my first major blocker. But after some digging and learning, I figured out what was going wrong, fixed the issue, and even made my code more robust using best practices like getters/setters and null checks.</p>
  961.  
  962.  
  963.  
  964. <p>Let me walk you through the issue, how I solved it, and what improvements I made along the way!</p>
  965.  
  966.  
  967.  
  968. <h2 class="wp-block-heading">Error Diagnosis:</h2>
  969.  
  970.  
  971.  
  972. <p>The error pointed me to this line in my <code>Player</code> class:</p>
  973.  
  974.  
  975.  
  976. <pre class="wp-block-preformatted"><code>return player.receiveDamage(weapon.useWeapon());</code></pre>
  977.  
  978.  
  979.  
  980. <p>I was calling <code>weapon.useWeapon()</code> — but <code>weapon</code> was still <code>null</code>! That was the root of the <strong>NullPointerException</strong>.</p>
  981.  
  982.  
  983.  
  984. <h3 class="wp-block-heading">What I Did Wrong:</h3>
  985.  
  986.  
  987.  
  988. <p>In my <code>Main.java</code>, I wrote:</p>
  989.  
  990.  
  991.  
  992. <pre class="wp-block-preformatted"><code>Mensch.equip(Mensch.weapon);  // WRONG<br>Ork.equip(Ork.weapon);        // WRONG</code></pre>
  993.  
  994.  
  995.  
  996. <p>But <code>Mensch.weapon</code> and <code>Ork.weapon</code> were never set! I had already created <code>Weapon</code> objects (<code>MenschW</code>, <code>OrkW</code>), but I wasn&#8217;t using them properly.</p>
  997.  
  998.  
  999.  
  1000. <h3 class="wp-block-heading">Fix Error:</h3>
  1001.  
  1002.  
  1003.  
  1004. <p>The solution was simple: pass the <strong>actual weapon objects</strong> to the <code>equip()</code> method:</p>
  1005.  
  1006.  
  1007.  
  1008. <pre class="wp-block-preformatted"><code>Mensch.equip(MenschW);  // CORRECT<br>Ork.equip(OrkW);        // CORRECT</code></pre>
  1009.  
  1010.  
  1011.  
  1012. <p>Once I did that, the error disappeared and my characters could finally attack each other properly!</p>
  1013.  
  1014.  
  1015.  
  1016. <h2 class="wp-block-heading">From Working to Well Written</h2>
  1017.  
  1018.  
  1019.  
  1020. <p>After fixing the issue, I took the chance to clean up my code and apply a few important <strong>Object-Oriented Programming (OOP)</strong> practices:</p>
  1021.  
  1022.  
  1023.  
  1024. <ol class="wp-block-list">
  1025. <li><strong>Encapsulation:</strong> I made all fields <code>private</code> and used setters/getters.</li>
  1026.  
  1027.  
  1028.  
  1029. <li><strong>Null Safety:</strong> I added null checks to prevent runtime errors.</li>
  1030.  
  1031.  
  1032.  
  1033. <li><strong>Readable Logic:</strong> Better method names (<code>isDead()</code> instead of <code>dead()</code>), and clear error messages if weapons are missing or broken.</li>
  1034.  
  1035.  
  1036.  
  1037. <li><strong>Extendability:</strong> My game is now easier to expand i could add critical hits, item durability, or healing in the future!</li>
  1038. </ol>
  1039.  
  1040.  
  1041.  
  1042. <h2 class="wp-block-heading">Final Improve Code:</h2>
  1043.  
  1044.  
  1045.  
  1046. <h3 class="wp-block-heading"> <code>Player.java</code></h3>
  1047.  
  1048.  
  1049.  
  1050. <pre class="wp-block-preformatted"><code>public class Player {<br>    private String name;<br>    private String race;<br>    private int hp;<br>    private int power;<br>    private int armour;<br>    private Weapon weapon;<br><br>    public Player(String name, String race, int hp, int power, int armour) {<br>        this.name = name;<br>        this.race = race;<br>        this.hp = hp;<br>        this.power = power;<br>        this.armour = armour;<br>    }<br><br>    // Getters and Setters<br>    public String getName() { return name; }<br>    public void setName(String name) { this.name = name; }<br><br>    public String getRace() { return race; }<br>    public void setRace(String race) { this.race = race; }<br><br>    public int getHP() { return hp; }<br>    public void setHP(int hp) { this.hp = hp; }<br><br>    public int getPower() { return power; }<br>    public void setPower(int power) { this.power = power; }<br><br>    public int getArmour() { return armour; }<br>    public void setArmour(int armour) { this.armour = armour; }<br><br>    public boolean isDead() {<br>        return hp &lt;= 0;<br>    }<br><br>    public boolean equip(Weapon weapon) {<br>        if (weapon == null) return false;<br>        this.weapon = weapon;<br>        return true;<br>    }<br><br>    public boolean receiveDamage(int damage) {<br>        int effectiveDamage = Math.max(damage - armour, 0);<br>        hp = Math.max(hp - effectiveDamage, 0);<br>        return hp > 0;<br>    }<br><br>    public boolean attack(Player target) {<br>        if (weapon == null) {<br>            System.out.println(name + " has no weapon to attack!");<br>            return false;<br>        }<br>        int damage = weapon.useWeapon();<br>        System.out.println(name + " attacks " + target.getName() + " with " + weapon.getName() + " for " + damage + " damage.");<br>        return target.receiveDamage(damage);<br>    }<br>}<br></code></pre>
  1051.  
  1052.  
  1053.  
  1054. <h3 class="wp-block-heading"> <code>Weapon.java</code></h3>
  1055.  
  1056.  
  1057.  
  1058. <pre class="wp-block-preformatted"><code>import java.util.concurrent.ThreadLocalRandom;<br><br>public class Weapon {<br>    private String name;<br>    private int damage;<br>    private int hp;<br><br>    public Weapon(String name, int damage, int hp) {<br>        this.name = name;<br>        this.damage = damage;<br>        this.hp = hp;<br>    }<br><br>    public String getName() { return name; }<br>    public void setName(String name) { this.name = name; }<br><br>    public int getDamage() { return damage; }<br>    public void setDamage(int damage) { this.damage = damage; }<br><br>    public int getHP() { return hp; }<br>    public void setHP(int hp) { this.hp = hp; }<br><br>    public int useWeapon() {<br>        if (isBroken()) {<br>            System.out.println(name + " is broken!");<br>            return 0;<br>        }<br>        hp -= 5;<br>        return (damage / 2) + ThreadLocalRandom.current().nextInt(1, damage + 1);<br>    }<br><br>    private boolean isBroken() {<br>        return hp &lt;= 0;<br>    }<br>}<br></code></pre>
  1059.  
  1060.  
  1061.  
  1062. <h3 class="wp-block-heading"> <code>Main.java</code></h3>
  1063.  
  1064.  
  1065.  
  1066. <pre class="wp-block-preformatted"><code>public class Main {<br>    public static void main(String[] args) {<br>        Player mensch = new Player("Mensch", "Human", 85, 12, 10);<br>        Player ork = new Player("Shrek", "Ork", 50, 14, 6);<br><br>        Weapon menschW = new Weapon("Mächtiges Schwert", 15, 100);<br>        Weapon orkW = new Weapon("Große Axt", 7, 100);<br><br>        mensch.equip(menschW);<br>        ork.equip(orkW);<br><br>        while (!mensch.isDead() &amp;&amp; !ork.isDead()) {<br>            mensch.attack(ork);<br>            if (ork.isDead()) break;<br><br>            ork.attack(mensch);<br>        }<br><br>        System.out.println("\nKampf vorbei!");<br>        System.out.println("Mensch ist tot: " + mensch.isDead());<br>        System.out.println("Ork ist tot: " + ork.isDead());<br>    }<br>}<br></code></pre>
  1067.  
  1068.  
  1069.  
  1070. <h2 class="wp-block-heading">Final Thoughts</h2>
  1071.  
  1072.  
  1073.  
  1074. <p>I&#8217;m really glad I ran into that <strong>NullPointerException</strong> early on it forced me to slow down, understand Java better, and write more reliable code. These small bugs often teach the most valuable lessons.</p>
  1075.  
  1076.  
  1077.  
  1078. <p>If you&#8217;re working on your first game in Java like I was, don’t be afraid of errors. Use them as signposts that guide you to better code. Now my characters swing swords, lose health, and die like real (virtual) warriors and your game can too.</p>
  1079. ]]></content:encoded>
  1080. <wfw:commentRss>https://fsiblog.io/how-to-fix-the-java-game-crash-error-when-my-human-tried-to-attack-the-orc/feed/</wfw:commentRss>
  1081. <slash:comments>0</slash:comments>
  1082. <post-id xmlns="com-wordpress:feed-additions:1">2973</post-id> </item>
  1083. <item>
  1084. <title>How to Fix Error Google Play Games Authentication in Unity Returning Login</title>
  1085. <link>https://fsiblog.io/how-to-fix-error-google-play-games-authentication-in-unity-returning-login/</link>
  1086. <comments>https://fsiblog.io/how-to-fix-error-google-play-games-authentication-in-unity-returning-login/#respond</comments>
  1087. <dc:creator><![CDATA[Sneed Cody]]></dc:creator>
  1088. <pubDate>Wed, 09 Jul 2025 07:23:52 +0000</pubDate>
  1089. <category><![CDATA[Game]]></category>
  1090. <category><![CDATA[Fix Error Google Play Games Authentication in Unity Returning Login]]></category>
  1091. <category><![CDATA[How to Fix Error Google Play Games Authentication in Unity Returning Login]]></category>
  1092. <guid isPermaLink="false">https://fsiblog.io/?p=2968</guid>
  1093.  
  1094. <description><![CDATA[I recently spent a few very frustrating days trying to integrate Google Play Games Services authentication into my Unity Android project. What should’ve been a quick setup turned into a rabbit hole of trial, error, debugging, and learning. So I’m writing this blog post to share my experience from the initial setup, to getting hit [&#8230;]]]></description>
  1095. <content:encoded><![CDATA[
  1096. <p>I recently spent a few very frustrating days trying to integrate <strong>Google Play Games Services authentication</strong> into my Unity Android project. What should’ve been a quick setup turned into a rabbit hole of trial, error, debugging, and learning. So I’m writing this blog post to share my experience from the <strong>initial setup</strong>, to getting hit with the dreaded <strong>“Login Unsuccessful: Canceled”</strong> error, and finally arriving at a working solution with some added functionality.</p>
  1097.  
  1098.  
  1099.  
  1100. <h2 class="wp-block-heading">My First Attempt</h2>
  1101.  
  1102.  
  1103.  
  1104. <p>I started with the <strong>default authentication code</strong> from Unity’s integration with the Google Play Games plugin. Here’s what it looked like:</p>
  1105.  
  1106.  
  1107.  
  1108. <pre class="wp-block-preformatted"><code>using GooglePlayGames;<br>using GooglePlayGames.BasicApi;<br>using UnityEngine;<br><br>public class GooglePlayGamesExampleScript : MonoBehaviour<br>{<br>    public string Token;<br>    public string Error;<br><br>    void Awake()<br>    {<br>        // Initialize PlayGamesPlatform<br>        PlayGamesPlatform.Activate();<br>        LoginGooglePlayGames();<br>    }<br><br>    public void LoginGooglePlayGames()<br>    {<br>        PlayGamesPlatform.Instance.Authenticate((success) =><br>        {<br>            if (success == SignInStatus.Success)<br>            {<br>                Debug.Log("Login with Google Play games successful.");<br><br>                PlayGamesPlatform.Instance.RequestServerSideAccess(true, code =><br>                {<br>                    Debug.Log("Authorization code: " + code);<br>                    Token = code;<br>                });<br>            }<br>            else<br>            {<br>                Error = "Failed to retrieve Google play games authorization code";<br>                Debug.Log("Login Unsuccessful" + success);<br>            }<br>        });<br>    }<br>}</code></pre>
  1109.  
  1110.  
  1111.  
  1112. <p>At first glance, it looked clean. I expected this to “just work.” But when I ran it on my Android device, I got:</p>
  1113.  
  1114.  
  1115.  
  1116. <pre class="wp-block-preformatted"><code>Login Unsuccessful: Canceled<br>[Play Games Plugin] ERROR: Returning an error code.</code></pre>
  1117.  
  1118.  
  1119.  
  1120. <h2 class="wp-block-heading">Login Unsuccessful Cancel Error</h2>
  1121.  
  1122.  
  1123.  
  1124. <p>I had no idea why it was being <strong>canceled</strong>, not failed. So I started digging into all possible causes. Here&#8217;s what I found:</p>
  1125.  
  1126.  
  1127.  
  1128. <h3 class="wp-block-heading">Common Issues That Can Trigger This Error</h3>
  1129.  
  1130.  
  1131.  
  1132. <ul class="wp-block-list">
  1133. <li><strong>OAuth Client ID mismatch</strong>: I had used the wrong SHA1 or keystore during setup. After rechecking, I realized I needed to regenerate the OAuth credentials based on my release keystore.</li>
  1134.  
  1135.  
  1136.  
  1137. <li><strong>Not listed as a test user</strong>: If your Google account isn’t added as a tester in <strong>Google Play Console > Play Games Services > Configuration > Testers</strong>, you will hit a wall.</li>
  1138.  
  1139.  
  1140.  
  1141. <li><strong>Sideloading instead of internal testing</strong>: I was installing my APK via ADB, which skips the proper handshake with Play Store. The fix? Upload it to <strong>Internal Testing</strong> and install it from there.</li>
  1142.  
  1143.  
  1144.  
  1145. <li><strong>Not signed into Google Play Games on the device</strong>: You have to make sure the device is signed in to the <strong>Google Play Games app</strong> with the test account.</li>
  1146.  
  1147.  
  1148.  
  1149. <li><strong>Outdated or misconfigured plugin</strong>: I updated to the latest Google Play Games plugin and re-imported the <code>google-services.json</code> and <code>resources</code> files just to be safe.</li>
  1150. </ul>
  1151.  
  1152.  
  1153.  
  1154. <h2 class="wp-block-heading">Final Working Version</h2>
  1155.  
  1156.  
  1157.  
  1158. <p>After resolving the setup issues, I wanted to make the script more robust and interactive. So I added <strong>a UI-based approach</strong> for debugging and retrying login attempts. Here’s the final version I ended up using:</p>
  1159.  
  1160.  
  1161.  
  1162. <pre class="wp-block-preformatted">Edit<code>using GooglePlayGames;<br>using GooglePlayGames.BasicApi;<br>using UnityEngine;<br>using UnityEngine.UI;<br><br>public class GooglePlayGamesExampleScript : MonoBehaviour<br>{<br>    public Text statusText;  // Assign this in Unity UI<br>    public Button signInButton;<br><br>    public string Token;<br>    public string Error;<br><br>    private void Start()<br>    {<br>        ConfigurePlayGames();<br>        signInButton.onClick.AddListener(LoginGooglePlayGames);<br>    }<br><br>    private void ConfigurePlayGames()<br>    {<br>        PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()<br>            .RequestServerAuthCode(false)<br>            .RequestEmail()<br>            .Build();<br><br>        PlayGamesPlatform.InitializeInstance(config);<br>        PlayGamesPlatform.DebugLogEnabled = true; // Extra logging<br>        PlayGamesPlatform.Activate();<br><br>        statusText.text = "Play Games Configured. Click Sign In.";<br>    }<br><br>    public void LoginGooglePlayGames()<br>    {<br>        statusText.text = "Attempting to sign in...";<br>        PlayGamesPlatform.Instance.Authenticate(SignInInteractivity.CanPromptAlways, (status) =><br>        {<br>            if (status == SignInStatus.Success)<br>            {<br>                statusText.text = "Sign-in successful!";<br>                Debug.Log("Login successful.");<br><br>                PlayGamesPlatform.Instance.RequestServerSideAccess(true, code =><br>                {<br>                    Token = code;<br>                    Debug.Log("Authorization code: " + code);<br>                });<br>            }<br>            else<br>            {<br>                statusText.text = $"Sign-in failed: {status}";<br>                Error = "Google Play Games Auth failed: " + status;<br>                Debug.LogWarning("Login Unsuccessful: " + status);<br>            }<br>        });<br>    }<br>}</code></pre>
  1163.  
  1164.  
  1165.  
  1166. <h2 class="wp-block-heading">Unity Setup Steps</h2>
  1167.  
  1168.  
  1169.  
  1170. <p>To make this work inside Unity:</p>
  1171.  
  1172.  
  1173.  
  1174. <ol class="wp-block-list">
  1175. <li><strong>Add a Canvas</strong> with:
  1176. <ul class="wp-block-list">
  1177. <li>A <code>Text</code> element (assign to <code>statusText</code>)</li>
  1178.  
  1179.  
  1180.  
  1181. <li>A <code>Button</code> (assign to <code>signInButton</code> and label it &#8220;Sign In&#8221;)</li>
  1182. </ul>
  1183. </li>
  1184.  
  1185.  
  1186.  
  1187. <li><strong>Upload the app to Internal Testing</strong> and install via the Play Store link.</li>
  1188.  
  1189.  
  1190.  
  1191. <li><strong>Use the correct SHA1 fingerprint</strong> and OAuth Client ID.</li>
  1192.  
  1193.  
  1194.  
  1195. <li><strong>Ensure your Google Play Games plugin is up to date</strong> and linked to your Unity project correctly.</li>
  1196. </ol>
  1197.  
  1198.  
  1199.  
  1200. <h2 class="wp-block-heading">Bonus Debugging Tips</h2>
  1201.  
  1202.  
  1203.  
  1204. <ul class="wp-block-list">
  1205. <li>Enable extra logging with:</li>
  1206. </ul>
  1207.  
  1208.  
  1209.  
  1210. <pre class="wp-block-preformatted"><code>PlayGamesPlatform.DebugLogEnabled = true;</code></pre>
  1211.  
  1212.  
  1213.  
  1214. <ul class="wp-block-list">
  1215. <li>Use <strong>Logcat</strong> to inspect runtime output:</li>
  1216. </ul>
  1217.  
  1218.  
  1219.  
  1220. <pre class="wp-block-preformatted"><code>adb logcat -s Unity ActivityManager PackageManager dalvikvm DEBUG</code></pre>
  1221.  
  1222.  
  1223.  
  1224. <ul class="wp-block-list">
  1225. <li>Avoid emulators authentication often fails on them due to missing Google Play Services features.</li>
  1226. </ul>
  1227.  
  1228.  
  1229.  
  1230. <h2 class="wp-block-heading">Final Thought</h2>
  1231.  
  1232.  
  1233.  
  1234. <p>After spending almost four days stuck with <strong>Google Play Games login errors</strong>, I finally cracked the code both figuratively and literally. The problem wasn’t in the Unity code alone but in how everything around it was configured: SHA keys, test accounts, plugin versions, and install methods. If you&#8217;re getting “Login Unsuccessful: Canceled,” don’t just stare at your script start double-checking your <strong>Google Play Console</strong>, <strong>OAuth settings</strong>, and <strong>test environment</strong>.</p>
  1235. ]]></content:encoded>
  1236. <wfw:commentRss>https://fsiblog.io/how-to-fix-error-google-play-games-authentication-in-unity-returning-login/feed/</wfw:commentRss>
  1237. <slash:comments>0</slash:comments>
  1238. <post-id xmlns="com-wordpress:feed-additions:1">2968</post-id> </item>
  1239. <item>
  1240. <title>How to Make a Sign Up Form Using React JS &#038; Tailwind CSS</title>
  1241. <link>https://fsiblog.io/how-to-make-a-sign-up-form-using-react-js-tailwind-css/</link>
  1242. <comments>https://fsiblog.io/how-to-make-a-sign-up-form-using-react-js-tailwind-css/#respond</comments>
  1243. <dc:creator><![CDATA[Asim Sikka]]></dc:creator>
  1244. <pubDate>Wed, 09 Jul 2025 06:59:07 +0000</pubDate>
  1245. <category><![CDATA[React JS]]></category>
  1246. <category><![CDATA[Make a Sign Up Form Using React JS & Tailwind CSS]]></category>
  1247. <guid isPermaLink="false">https://fsiblog.io/?p=2965</guid>
  1248.  
  1249. <description><![CDATA[let me walk you through this project I recently crafted for a client sleek and user friendly sign-up page built with React JS and Tailwind CSS. Overall Layout I began with a full-screen container to center the form both vertically and horizontally. It looks like this: &#60;div className="min-h-screen flex items-center justify-center bg-gray-200"> Main Container Next, [&#8230;]]]></description>
  1250. <content:encoded><![CDATA[
  1251. <p>let me walk you through this project I recently crafted for a client sleek and user friendly sign-up page built with React JS and Tailwind CSS.</p>
  1252.  
  1253.  
  1254.  
  1255. <h2 class="wp-block-heading">Overall Layout</h2>
  1256.  
  1257.  
  1258.  
  1259. <p>I began with a full-screen container to center the form both vertically and horizontally. It looks like this:</p>
  1260.  
  1261.  
  1262.  
  1263. <pre class="wp-block-preformatted"><code>&lt;div className="min-h-screen flex items-center justify-center bg-gray-200"></code></pre>
  1264.  
  1265.  
  1266.  
  1267. <ul class="wp-block-list">
  1268. <li><code>min-h-screen</code> ensures the component always takes up the entire viewport height.</li>
  1269.  
  1270.  
  1271.  
  1272. <li><code>flex</code>, <code>items-center</code>, and <code>justify-center</code> align the content perfectly at the center.</li>
  1273.  
  1274.  
  1275.  
  1276. <li>The light gray background (<code>bg-gray-200</code>) adds a gentle contrast to the white form box.</li>
  1277. </ul>
  1278.  
  1279.  
  1280.  
  1281. <h2 class="wp-block-heading">Main Container</h2>
  1282.  
  1283.  
  1284.  
  1285. <p>Next, I created a container to house both the form and the right-side illustration:</p>
  1286.  
  1287.  
  1288.  
  1289. <pre class="wp-block-preformatted"><code>&lt;div className="flex w-[900px] shadow-2xl rounded-2xl overflow-hidden"></code></pre>
  1290.  
  1291.  
  1292.  
  1293. <ul class="wp-block-list">
  1294. <li><code>w-[900px]</code>: Fixed width for desktop layout.</li>
  1295.  
  1296.  
  1297.  
  1298. <li><code>flex</code>: Splits the container into two equal parts.</li>
  1299.  
  1300.  
  1301.  
  1302. <li><code>shadow-2xl</code> and <code>rounded-2xl</code>: Adds modern, soft-rounded corners and depth.</li>
  1303. </ul>
  1304.  
  1305.  
  1306.  
  1307. <h2 class="wp-block-heading">Left Panel – The Form</h2>
  1308.  
  1309.  
  1310.  
  1311. <h3 class="wp-block-heading">Branding and Title</h3>
  1312.  
  1313.  
  1314.  
  1315. <p>I used the brand name <em>dotworker</em> and a welcoming header:</p>
  1316.  
  1317.  
  1318.  
  1319. <pre class="wp-block-preformatted"><code>&lt;div className="text-blue-600 font-bold text-xl mb-6">dotworker&lt;/div><br>&lt;h2 className="text-2xl font-semibold mb-6">Create your Account&lt;/h2></code></pre>
  1320.  
  1321.  
  1322.  
  1323. <h3 class="wp-block-heading">Social Login Button</h3>
  1324.  
  1325.  
  1326.  
  1327. <p>To make the sign-up process quicker, I added placeholder social buttons (ideal for future integration with Firebase/Auth0):</p>
  1328.  
  1329.  
  1330.  
  1331. <pre class="wp-block-preformatted"><code>&lt;button>Google&lt;/button><br>&lt;button>Facebook&lt;/button></code></pre>
  1332.  
  1333.  
  1334.  
  1335. <p>Each is styled with borders and icons for easy recognition.</p>
  1336.  
  1337.  
  1338.  
  1339. <h3 class="wp-block-heading">The Email &amp; Password Form</h3>
  1340.  
  1341.  
  1342.  
  1343. <p>This form is clean, straightforward, and ready to go:</p>
  1344.  
  1345.  
  1346.  
  1347. <pre class="wp-block-preformatted"><code>&lt;form><br>  &lt;input type="email" /><br>  &lt;input type="password" /><br>  ...<br>&lt;/form></code></pre>
  1348.  
  1349.  
  1350.  
  1351. <p>I included:</p>
  1352.  
  1353.  
  1354.  
  1355. <ul class="wp-block-list">
  1356. <li><strong>Email and password inputs</strong></li>
  1357.  
  1358.  
  1359.  
  1360. <li><strong>&#8220;Remember me&#8221; checkbox</strong></li>
  1361.  
  1362.  
  1363.  
  1364. <li><strong>&#8220;Forget password?&#8221; link</strong></li>
  1365.  
  1366.  
  1367.  
  1368. <li>A prominent <strong>“Create”</strong> button</li>
  1369. </ul>
  1370.  
  1371.  
  1372.  
  1373. <h2 class="wp-block-heading">Right Panel</h2>
  1374.  
  1375.  
  1376.  
  1377. <p>The right section uses a <strong>blue background</strong> and features brand icons and a visual dashboard mock:</p>
  1378.  
  1379.  
  1380.  
  1381. <pre class="wp-block-preformatted"><code>&lt;div className="w-1/2 bg-blue-600 text-white ..."></code></pre>
  1382.  
  1383.  
  1384.  
  1385. <ul class="wp-block-list">
  1386. <li>Slack and Google icons sit near the dashboard illustration.</li>
  1387.  
  1388.  
  1389.  
  1390. <li>This reinforces the idea of app integrations.</li>
  1391.  
  1392.  
  1393.  
  1394. <li>A headline and caption clarify the product’s value: <em>&#8220;Connect with every application.&#8221;</em></li>
  1395. </ul>
  1396.  
  1397.  
  1398.  
  1399. <h2 class="wp-block-heading">Let Add Real Functionality</h2>
  1400.  
  1401.  
  1402.  
  1403. <p>I wanted the form to do more than just look good it had to work. So I added:</p>
  1404.  
  1405.  
  1406.  
  1407. <h3 class="wp-block-heading">React State Handling</h3>
  1408.  
  1409.  
  1410.  
  1411. <pre class="wp-block-preformatted"><code>const [email, setEmail] = useState("");<br>const [password, setPassword] = useState("");<br>const [remember, setRemember] = useState(false);<br>const [showPassword, setShowPassword] = useState(false);<br>const [error, setError] = useState("");</code></pre>
  1412.  
  1413.  
  1414.  
  1415. <p>I used React JS <code>useState</code> to control form input, visibility, and error messaging.</p>
  1416.  
  1417.  
  1418.  
  1419. <h3 class="wp-block-heading">Password Visibility Toggle</h3>
  1420.  
  1421.  
  1422.  
  1423. <p>I added a simple feature that toggles password visibility a small UX upgrade that users love:</p>
  1424.  
  1425.  
  1426.  
  1427. <pre class="wp-block-preformatted"><code>type={showPassword ? "text" : "password"}</code></pre>
  1428.  
  1429.  
  1430.  
  1431. <h3 class="wp-block-heading">Validation and Feedback</h3>
  1432.  
  1433.  
  1434.  
  1435. <p>In the <code>handleSubmit</code> function, I checked if fields were empty and displayed error messages dynamically:</p>
  1436.  
  1437.  
  1438.  
  1439. <pre class="wp-block-preformatted"><code>if (!email || !password) {<br>  setError("Please enter both email and password.");<br>  return;<br>}</code></pre>
  1440.  
  1441.  
  1442.  
  1443. <p>On successful submit, I simply displayed an alert for now, but in production this could route to an API or Firebase.</p>
  1444.  
  1445.  
  1446.  
  1447. <h2 class="wp-block-heading">Final Thoughts</h2>
  1448.  
  1449.  
  1450.  
  1451. <p>This project started as a UI challenge, but I wanted it to go beyond pretty visuals. I gave it purpose. I added interactivity and validation so the client could see the product <strong>in action</strong> not just in pixels, but in functionality.</p>
  1452.  
  1453.  
  1454.  
  1455. <p>What made this exciting was how quickly I could bring it to life with <strong>Tailwind CSS and React</strong>. The ability to manage UI state, build custom components, and create polished UI all in one component is what makes React such a powerful tool.</p>
  1456. ]]></content:encoded>
  1457. <wfw:commentRss>https://fsiblog.io/how-to-make-a-sign-up-form-using-react-js-tailwind-css/feed/</wfw:commentRss>
  1458. <slash:comments>0</slash:comments>
  1459. <post-id xmlns="com-wordpress:feed-additions:1">2965</post-id> </item>
  1460. <item>
  1461. <title>How to Fix a Game Error in a Nested Array with JavaScript</title>
  1462. <link>https://fsiblog.io/how-to-fix-a-game-error-in-a-nested-array-with-javascript/</link>
  1463. <comments>https://fsiblog.io/how-to-fix-a-game-error-in-a-nested-array-with-javascript/#respond</comments>
  1464. <dc:creator><![CDATA[Sneed Cody]]></dc:creator>
  1465. <pubDate>Tue, 08 Jul 2025 06:47:08 +0000</pubDate>
  1466. <category><![CDATA[Game]]></category>
  1467. <category><![CDATA[JavaScript]]></category>
  1468. <category><![CDATA[Fix a Game Error in a Nested Array with JavaScript]]></category>
  1469. <category><![CDATA[How to Fix a Game Error in a Nested Array with JavaScript]]></category>
  1470. <guid isPermaLink="false">https://fsiblog.io/?p=2959</guid>
  1471.  
  1472. <description><![CDATA[Uncaught TypeError Cannot read property &#8216;x&#8217; of undefined, if you&#8217;ve seen this error while working with nested arrays in JavaScript, you&#8217;re not alone. I ran into this same issue while trying to create a simple game with bouncing circles using the &#60;canvas> element. It was frustrating at first, but once I understood the problem, the [&#8230;]]]></description>
  1473. <content:encoded><![CDATA[
  1474. <p><strong>Uncaught TypeError Cannot read property &#8216;x&#8217; of undefined</strong>, if you&#8217;ve seen this error while working with nested arrays in JavaScript, you&#8217;re not alone. I ran into this same issue while trying to create a simple game with bouncing circles using the <code>&lt;canvas></code> element. It was frustrating at first, but once I understood the problem, the fix was actually quite straightforward.</p>
  1475.  
  1476.  
  1477.  
  1478. <h2 class="wp-block-heading">The Problem</h2>
  1479.  
  1480.  
  1481.  
  1482. <p>In my original code, I tried to draw several animated circles on a canvas. Each circle was stored inside a nested array called <code>circles</code>. But when I ran the project, I got this error:</p>
  1483.  
  1484.  
  1485.  
  1486. <pre class="wp-block-preformatted"><code>Uncaught TypeError: Cannot read property 'x' of undefined</code></pre>
  1487.  
  1488.  
  1489.  
  1490. <p>And it pointed to this line:</p>
  1491.  
  1492.  
  1493.  
  1494. <pre class="wp-block-preformatted"><code>ctx.arc(circles[i].x, circles[i].y, circles[i].r, 0, Math.PI * 2, false);</code></pre>
  1495.  
  1496.  
  1497.  
  1498. <p>This really puzzled me. I had defined the array properly. So what was going on?</p>
  1499.  
  1500.  
  1501.  
  1502. <h2 class="wp-block-heading">Why This Happen</h2>
  1503.  
  1504.  
  1505.  
  1506. <p>After some debugging, I realized the problem was with how I was using the <code>for</code> loop and variable <code>i</code>.</p>
  1507.  
  1508.  
  1509.  
  1510. <pre class="wp-block-preformatted"><code>for (var i = 0; i &lt; circles.length; i++) {<br>    // All logic and drawing functions declared here<br>    setTimeout(draw, 10); // &lt;- here's the trap<br>}</code></pre>
  1511.  
  1512.  
  1513.  
  1514. <p>The issue is that I wrapped everything including function definitions and <code>setTimeout(draw, 10)</code> <strong>inside</strong> a <code>for</code> loop and assumed <code>i</code> would still be valid when the <code>draw()</code> function was called.</p>
  1515.  
  1516.  
  1517.  
  1518. <p>But by the time <code>setTimeout(draw, 10)</code> ran, the loop had already completed, and <code>i</code> was <strong>out of bounds</strong> (equal to <code>circles.length</code>). So when the draw function tried to access <code>circles[i]</code>, it was undefined hence the error.</p>
  1519.  
  1520.  
  1521.  
  1522. <h2 class="wp-block-heading">Loop Dynamically Inside the Draw Function</h2>
  1523.  
  1524.  
  1525.  
  1526. <p>What I needed to do was restructure the code:</p>
  1527.  
  1528.  
  1529.  
  1530. <ul class="wp-block-list">
  1531. <li>Move <strong>all animation and drawing</strong> inside the <code>draw()</code> function.</li>
  1532.  
  1533.  
  1534.  
  1535. <li>Let <code>draw()</code> loop through the <code>circles</code> array <strong>every frame</strong>.</li>
  1536.  
  1537.  
  1538.  
  1539. <li>Handle each circle&#8217;s movement and drawing independently.</li>
  1540. </ul>
  1541.  
  1542.  
  1543.  
  1544. <h2 class="wp-block-heading">The Final, Working Code</h2>
  1545.  
  1546.  
  1547.  
  1548. <pre class="wp-block-preformatted"><code>&lt;!DOCTYPE html><br>&lt;html><br>&lt;head><br>    &lt;title>Canvas Game: Bouncing Circles&lt;/title><br>    &lt;style><br>        body {<br>            margin: 0;<br>            overflow: hidden;<br>        }<br>    &lt;/style><br>    &lt;script type="text/javascript"><br>        // Define your circles<br>        const circles = [<br>            {x: 200, y: 150, r: 40, direction: 1, speedX: 1, speedY: 2, color: "yellow"},<br>            {x: 100, y: 100, r: 30, direction: 2, speedX: 2, speedY: 1, color: "red"},<br>            {x: 300, y: 200, r: 20, direction: 3, speedX: 1.5, speedY: 1.5, color: "blue"}<br>        ];<br><br>        function moveCircle(circle) {<br>            // Move based on direction<br>            switch (circle.direction) {<br>                case 1: circle.x += circle.speedX; circle.y += circle.speedY; break;<br>                case 2: circle.x += circle.speedX; circle.y -= circle.speedY; break;<br>                case 3: circle.x -= circle.speedX; circle.y -= circle.speedY; break;<br>                case 4: circle.x -= circle.speedX; circle.y += circle.speedY; break;<br>            }<br><br>            // Bounce off edges<br>            if (circle.y > 300 - circle.r &amp;&amp; circle.direction === 1) {<br>                circle.direction = 2;<br>            } else if (circle.x > 400 - circle.r &amp;&amp; circle.direction === 2) {<br>                circle.direction = 3;<br>            } else if (circle.y &lt;= circle.r &amp;&amp; circle.direction === 3) {<br>                circle.direction = 4;<br>            } else if (circle.x &lt;= circle.r &amp;&amp; circle.direction === 4) {<br>                circle.direction = 1;<br>            } else if (circle.y &lt;= circle.r &amp;&amp; circle.direction === 2) {<br>                circle.direction = 1;<br>            } else if (circle.x >= 400 - circle.r &amp;&amp; circle.direction === 1) {<br>                circle.direction = 4;<br>            } else if (circle.y >= 300 - circle.r &amp;&amp; circle.direction === 4) {<br>                circle.direction = 3;<br>            } else if (circle.x &lt;= circle.r &amp;&amp; circle.direction === 3) {<br>                circle.direction = 2;<br>            }<br>        }<br><br>        function draw() {<br>            const canvas = document.getElementById("canvas");<br>            const ctx = canvas.getContext("2d");<br><br>            // Clear canvas<br>            ctx.fillStyle = "black";<br>            ctx.fillRect(0, 0, canvas.width, canvas.height);<br><br>            // Move and draw each circle<br>            for (let i = 0; i &lt; circles.length; i++) {<br>                const circle = circles[i];<br>                moveCircle(circle);<br>                ctx.fillStyle = circle.color;<br>                ctx.beginPath();<br>                ctx.arc(circle.x, circle.y, circle.r, 0, Math.PI * 2);<br>                ctx.fill();<br>            }<br><br>            requestAnimationFrame(draw); // Smooth animation<br>        }<br><br>        window.onload = draw;<br>    &lt;/script><br>&lt;/head><br>&lt;body><br>    &lt;canvas id="canvas" width="400" height="300">&lt;/canvas><br>&lt;/body><br>&lt;/html><br></code></pre>
  1549.  
  1550.  
  1551.  
  1552. <h2 class="wp-block-heading">Improvement I Made</h2>
  1553.  
  1554.  
  1555.  
  1556. <p>To go beyond just fixing the bug, I decided to improve the whole project:</p>
  1557.  
  1558.  
  1559.  
  1560. <ul class="wp-block-list">
  1561. <li><strong>Used <code>requestAnimationFrame()</code></strong> instead of <code>setTimeout()</code> for smoother animations and better performance.</li>
  1562.  
  1563.  
  1564.  
  1565. <li><strong>Allowed multiple circles</strong> to animate at once, each with its own speed, direction, and color.</li>
  1566.  
  1567.  
  1568.  
  1569. <li><strong>Organized the movement logic</strong> into its own function <code>moveCircle()</code> to keep the code clean and readable.</li>
  1570.  
  1571.  
  1572.  
  1573. <li><strong>Added random colors</strong> to easily tell circles apart makes debugging easier too!</li>
  1574. </ul>
  1575.  
  1576.  
  1577.  
  1578. <h2 class="wp-block-heading">Ideas for More Practice</h2>
  1579.  
  1580.  
  1581.  
  1582. <p>Once I got this working, I started thinking of ways to build on it:</p>
  1583.  
  1584.  
  1585.  
  1586. <ul class="wp-block-list">
  1587. <li><strong>Click to add a new circle</strong> — let users interact with the canvas.</li>
  1588.  
  1589.  
  1590.  
  1591. <li><strong>Randomize properties</strong> like color, radius, and speed for each circle.</li>
  1592.  
  1593.  
  1594.  
  1595. <li><strong>Add collisions between circles</strong> — a great way to practice physics and hit detection.</li>
  1596.  
  1597.  
  1598.  
  1599. <li><strong>Pause/resume the game</strong> using keyboard input.</li>
  1600.  
  1601.  
  1602.  
  1603. <li><strong>Level up</strong> by adding targets, scoring, and lives — turning it into an actual game.</li>
  1604. </ul>
  1605.  
  1606.  
  1607.  
  1608. <p>Let me know if you want me to help with any of these ideas I’d be happy to break those down in future posts!</p>
  1609.  
  1610.  
  1611.  
  1612. <h2 class="wp-block-heading">Final Thought</h2>
  1613.  
  1614.  
  1615.  
  1616. <p>This experience was a great reminder that <strong>understanding variable scope and timing in JavaScript is essential</strong>, especially when dealing with asynchronous operations like <code>setTimeout()</code> or animations. What seemed like a bug in my data (<code>circles[i]</code>) was actually a problem with <strong>how and when</strong> that data was accessed.</p>
  1617. ]]></content:encoded>
  1618. <wfw:commentRss>https://fsiblog.io/how-to-fix-a-game-error-in-a-nested-array-with-javascript/feed/</wfw:commentRss>
  1619. <slash:comments>0</slash:comments>
  1620. <post-id xmlns="com-wordpress:feed-additions:1">2959</post-id> </item>
  1621. <item>
  1622. <title>How to Fix My Android Game Layout Resource After Publishing to the Play Store</title>
  1623. <link>https://fsiblog.io/how-to-fix-my-android-game-layout-resource-after-publishing-to-the-play-store/</link>
  1624. <comments>https://fsiblog.io/how-to-fix-my-android-game-layout-resource-after-publishing-to-the-play-store/#respond</comments>
  1625. <dc:creator><![CDATA[Sneed Cody]]></dc:creator>
  1626. <pubDate>Tue, 08 Jul 2025 06:27:09 +0000</pubDate>
  1627. <category><![CDATA[Android Game]]></category>
  1628. <category><![CDATA[Fix My Android Game Layout Resource After Publishing to the Play Store]]></category>
  1629. <category><![CDATA[My Android Game Layout Resource After Publishing to the Play Store]]></category>
  1630. <guid isPermaLink="false">https://fsiblog.io/?p=2955</guid>
  1631.  
  1632. <description><![CDATA[I want to share a bug I ran into recently while developing my Android game. The game worked perfectly on my test devices, but when I published it to the Google Play Store, I started getting crash reports from users specifically from Samsung Galaxy S6 Edge and Note 5 devices. The Crash After releasing the [&#8230;]]]></description>
  1633. <content:encoded><![CDATA[
  1634. <p>I want to share a bug I ran into recently while developing my Android game. The game worked perfectly on my test devices, but when I published it to the Google Play Store, I started getting crash reports from users specifically from Samsung Galaxy S6 Edge and Note 5 devices.</p>
  1635.  
  1636.  
  1637.  
  1638. <h2 class="wp-block-heading">The Crash</h2>
  1639.  
  1640.  
  1641.  
  1642. <p>After releasing the app, I checked the <strong>Play Console</strong> and found this scary-looking stack trace:</p>
  1643.  
  1644.  
  1645.  
  1646. <pre class="wp-block-preformatted"><code>Caused by: android.content.res.Resources$NotFoundException: <br>  at android.content.res.ResourcesImpl.getValue<br>  ...<br>  at mypackagename.GameActivity.onCreate (GameActivity.java:193)</code></pre>
  1647.  
  1648.  
  1649.  
  1650. <p>The line causing the crash was this:</p>
  1651.  
  1652.  
  1653.  
  1654. <pre class="wp-block-preformatted"><code>setContentView(R.layout.activity_game_5x);</code></pre>
  1655.  
  1656.  
  1657.  
  1658. <p>Weird, because the file <code>activity_game_5x.xml</code> was sitting right there in my <code>res/layout/</code> folder. Or so I thought&#8230;</p>
  1659.  
  1660.  
  1661.  
  1662. <h2 class="wp-block-heading">My Layout Switching Code</h2>
  1663.  
  1664.  
  1665.  
  1666. <p>In my game, I was switching layouts depending on screen size. Here’s the block of code I wrote:</p>
  1667.  
  1668.  
  1669.  
  1670. <pre class="wp-block-preformatted"><code>if (sWidth > 480 &amp;&amp; screenInches >= 4 &amp;&amp; screenInches &lt;= 5) {<br>    setContentView(R.layout.activity_game_4x);<br>} else if (screenInches >= 5 &amp;&amp; screenInches &lt;= 6.5) {<br>    setContentView(R.layout.activity_game_5x); // Line 193<br>} else if (screenInches > 6.5 &amp;&amp; screenInches &lt; 9) {<br>    setContentView(R.layout.activity_game_7x);<br>} else {<br>    setContentView(R.layout.activity_game);<br>}<br></code></pre>
  1671.  
  1672.  
  1673.  
  1674. <p>This worked fine during testing. But clearly, something wasn’t right when the app hit real-world devices.</p>
  1675.  
  1676.  
  1677.  
  1678. <h2 class="wp-block-heading">What Went Wrong?</h2>
  1679.  
  1680.  
  1681.  
  1682. <p>After researching and experimenting, I figured out a few <strong>possible causes</strong> for this error:</p>
  1683.  
  1684.  
  1685.  
  1686. <h3 class="wp-block-heading"><strong>Layout Qualifier</strong></h3>
  1687.  
  1688.  
  1689.  
  1690. <p>Maybe <code>activity_game_5x.xml</code> was placed inside a folder like <code>layout-sw600dp/</code> or <code>layout-large/</code>, so devices that didn&#8217;t match those screen configurations couldn&#8217;t find it.</p>
  1691.  
  1692.  
  1693.  
  1694. <h3 class="wp-block-heading"><strong>File Name</strong></h3>
  1695.  
  1696.  
  1697.  
  1698. <p>Even a <strong>minor typo</strong> in the filename or an <strong>XML error</strong> inside the layout file could cause the resource to be excluded from the build.</p>
  1699.  
  1700.  
  1701.  
  1702. <h3 class="wp-block-heading"><strong>ProGuard or Build Settings</strong></h3>
  1703.  
  1704.  
  1705.  
  1706. <p>If you&#8217;re using ProGuard or app bundles with APK splits, there&#8217;s a chance some layouts aren&#8217;t included in certain device configurations.</p>
  1707.  
  1708.  
  1709.  
  1710. <h2 class="wp-block-heading">The Fix Defensive Coding</h2>
  1711.  
  1712.  
  1713.  
  1714. <p>To solve this and make sure the app <strong>never crashes</strong> because of a missing layout, I wrapped the whole logic in a try-catch block:</p>
  1715.  
  1716.  
  1717.  
  1718. <pre class="wp-block-preformatted"><code>try {<br>    if (sWidth > 480 &amp;&amp; screenInches >= 4 &amp;&amp; screenInches &lt;= 5) {<br>        setContentView(R.layout.activity_game_4x);<br>    } else if (screenInches >= 5 &amp;&amp; screenInches &lt;= 6.5) {<br>        setContentView(R.layout.activity_game_5x);<br>    } else if (screenInches > 6.5 &amp;&amp; screenInches &lt; 9) {<br>        setContentView(R.layout.activity_game_7x);<br>    } else {<br>        setContentView(R.layout.activity_game);<br>    }<br>} catch (Resources.NotFoundException e) {<br>    e.printStackTrace(); // For debug purposes<br>    setContentView(R.layout.activity_game); // Fallback to default<br>}</code></pre>
  1719.  
  1720.  
  1721.  
  1722. <p>This way, if <strong>any</strong> of the layouts fail to load, the app won’t crash — it just uses the default layout.</p>
  1723.  
  1724.  
  1725.  
  1726. <h2 class="wp-block-heading">User Feedback + Logging</h2>
  1727.  
  1728.  
  1729.  
  1730. <p>To take it one step further, I created a helper method that includes <strong>logging</strong> and a <strong>Toast message</strong> for users (and me):</p>
  1731.  
  1732.  
  1733.  
  1734. <pre class="wp-block-preformatted"><code>private void loadGameLayout(float screenInches, int sWidth) {<br>    try {<br>        if (sWidth > 480 &amp;&amp; screenInches >= 4 &amp;&amp; screenInches &lt;= 5) {<br>            setContentView(R.layout.activity_game_4x);<br>        } else if (screenInches >= 5 &amp;&amp; screenInches &lt;= 6.5) {<br>            setContentView(R.layout.activity_game_5x);<br>        } else if (screenInches > 6.5 &amp;&amp; screenInches &lt; 9) {<br>            setContentView(R.layout.activity_game_7x);<br>        } else {<br>            setContentView(R.layout.activity_game);<br>        }<br>    } catch (Resources.NotFoundException e) {<br>        Log.e("GameActivity", "Layout not found, using default", e);<br>        Toast.makeText(this, "Error loading layout, using default.", Toast.LENGTH_SHORT).show();<br>        setContentView(R.layout.activity_game);<br>    }<br>}</code></pre>
  1735.  
  1736.  
  1737.  
  1738. <p>Then in my <code>onCreate()</code> method, I just call:</p>
  1739.  
  1740.  
  1741.  
  1742. <pre class="wp-block-preformatted"><code>@Override<br>protected void onCreate(Bundle savedInstanceState) {<br>    super.onCreate(savedInstanceState);<br><br>    float screenInches = calculateScreenInches();<br>    int screenWidth = getResources().getDisplayMetrics().widthPixels;<br><br>    loadGameLayout(screenInches, screenWidth);<br>}</code></pre>
  1743.  
  1744.  
  1745.  
  1746. <h2 class="wp-block-heading">Pro Tips I Learn</h2>
  1747.  
  1748.  
  1749.  
  1750. <ul class="wp-block-list">
  1751. <li>Always <strong>validate all XML layouts</strong> before release.</li>
  1752.  
  1753.  
  1754.  
  1755. <li>Avoid placing layouts only in <code>layout-sw*</code> or other resource-qualified folders unless absolutely necessary.</li>
  1756.  
  1757.  
  1758.  
  1759. <li>Use a <strong>default fallback</strong> layout like <code>activity_game.xml</code> that always exists.</li>
  1760.  
  1761.  
  1762.  
  1763. <li>Add <strong>runtime checks</strong> to verify a layout exists using <code>getResources().getIdentifier(...)</code>.</li>
  1764. </ul>
  1765.  
  1766.  
  1767.  
  1768. <h2 class="wp-block-heading">Final Thought</h2>
  1769.  
  1770.  
  1771.  
  1772. <p>This bug was a great reminder that just because your app works on your test devices doesn&#8217;t mean it’ll work on <em>every</em> device. The Android ecosystem is incredibly diverse, and it&#8217;s worth writing your code to fail gracefully especially with things like dynamic layouts.</p>
  1773.  
  1774.  
  1775.  
  1776. <p>I hope this helped anyone else facing mysterious <code>Resources$NotFoundException</code> crashes. Defensive programming saved me a lot of headache and bad reviews.</p>
  1777. ]]></content:encoded>
  1778. <wfw:commentRss>https://fsiblog.io/how-to-fix-my-android-game-layout-resource-after-publishing-to-the-play-store/feed/</wfw:commentRss>
  1779. <slash:comments>0</slash:comments>
  1780. <post-id xmlns="com-wordpress:feed-additions:1">2955</post-id> </item>
  1781. </channel>
  1782. </rss>
  1783.  

If you would like to create a banner that links to this page (i.e. this validation result), do the following:

  1. Download the "valid RSS" banner.

  2. Upload the image to your own server. (This step is important. Please do not link directly to the image on this server.)

  3. Add this HTML to your page (change the image src attribute if necessary):

If you would like to create a text link instead, here is the URL you can use:

http://www.feedvalidator.org/check.cgi?url=https%3A//fsiblog.io/feed/

Copyright © 2002-9 Sam Ruby, Mark Pilgrim, Joseph Walton, and Phil Ringnalda