Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed Help Exception at Public Game1() in MonoGame on OSX
    primarykey
    data
    text
    <p>So I'm trying to create this program that works perfect in Visual Studio 2012 at School.</p> <p>But when I'm at home it's giving me this Thrown Exception error at <code>Public Game1()</code>.</p> <p>Hopefully someone can help me out with this so that way i can actually run my program and finish it.</p> <p>The Call Stack is:</p> <blockquote> <p>System.NullReferenceException: Object reference not set to an instance of an object at Microsoft.Xna.Framework.OpenTKGameWindow.Initialize () [0x00000] in :0 at Microsoft.Xna.Framework.OpenTKGameWindow..ctor () [0x00000] in :0 at Microsoft.Xna.Framework.OpenTKGamePlatform..ctor (Microsoft.Xna.Framework.Game game) [0x00000] in :0 at Microsoft.Xna.Framework.GamePlatform.Create (Microsoft.Xna.Framework.Game game) [0x00000] in :0 at Microsoft.Xna.Framework.Game..ctor () [0x00000] in :0 at MonoGameTest.Game1..ctor () [0x00023] in /Users/sebnabt/Projects/MonoGameTest/MonoGameTest/Game1.cs:38 at MonoGameTest.Program.Main () [0x00001] in /Users/sebnabt/Projects/MonoGameTest/MonoGameTest/Program.cs:19</p> </blockquote> <p>And my code:</p> <pre><code>&lt;!-- language: lang-cs --&gt; region Using Statements using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Storage; using Microsoft.Xna.Framework.Input; endregion namespace MonoGameTest { /// &lt;summary&gt; /// This is the main type for your game /// &lt;/summary&gt; public class Game1 : Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; // Maps user keys to display colors Dictionary&lt;Keys, Color&gt; key_to_color = new Dictionary&lt;Keys, Color&gt;(); // these are the colors guessed by the user, so far. List&lt;Color&gt;[] player_colors = new List&lt;Color&gt;[10]; // these are the keys that correspond to a dot color List&lt;Keys&gt; color_letters = new List&lt;Keys&gt;(); Texture2D dot_picture; KeyboardState old_keyboard_state; int row; public Game1() : base() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; base.Initialize (); } /// &lt;summary&gt; /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// &lt;/summary&gt; /// /// // screen constants const int SCREEN_WIDTH = 640; const int SCREEN_HEIGHT = 480; protected override void Initialize() { row = 0; // back buffer graphics.PreferredBackBufferHeight = SCREEN_HEIGHT; graphics.PreferredBackBufferWidth = SCREEN_WIDTH; graphics.PreferMultiSampling = false; graphics.ApplyChanges(); base.Initialize(); // initialize the color dictionary key_to_color.Add(Keys.R, Color.Red); key_to_color.Add(Keys.G, Color.Green); key_to_color.Add(Keys.B, Color.Blue); key_to_color.Add(Keys.Y, Color.Yellow); color_letters = new List&lt;Keys&gt;(); foreach (Keys letter in key_to_color.Keys) { color_letters.Add(letter); } } /// &lt;summary&gt; /// LoadContent will be called once per game and is the place to load /// all of your content. /// &lt;/summary&gt; protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // load our textures dot_picture = Content.Load&lt;Texture2D&gt;(@"media\ball"); } /// &lt;summary&gt; /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// &lt;/summary&gt; /// &lt;param name="gameTime"&gt;Provides a snapshot of timing values.&lt;/param&gt; protected override void Update(GameTime gameTime) { // get keyboard state once per frame KeyboardState keyState = Keyboard.GetState(); // exit the game? if (keyState.IsKeyDown(Keys.Escape)) { this.Exit(); } // erase list of player colors? else if (keyState.IsKeyDown(Keys.Space)) { player_colors[this.row].Clear(); } // player pressed a color key? else { foreach (Keys letter in color_letters) { if (key_was_released(letter, keyState)) { add_color(letter); } if (this.player_colors [row].Count () &gt;= 4) { this.row = this.row + 1; } } } old_keyboard_state = keyState; base.Update(gameTime); } protected override void UnloadContent() { } bool key_was_released(Keys key, KeyboardState new_state) { return old_keyboard_state.IsKeyDown(key) &amp;&amp; new_state. IsKeyUp (key); } void add_color(Keys key) { Color color = key_to_color[key]; if (player_colors[this.row].Count() &lt; 4) { player_colors[this.row].Add(color); } } /// &lt;summary&gt; /// This is called when the game should draw itself. /// &lt;/summary&gt; /// &lt;param name="gameTime"&gt;Provides a snapshot of timing values.&lt;/param&gt; protected override void Draw(GameTime gameTime) { graphics.GraphicsDevice.Clear (Color.CornflowerBlue); // draw typical sprites spriteBatch.Begin (); draw_player_colors (spriteBatch); spriteBatch.End (); base.Draw (gameTime); } protected void draw_player_colors(SpriteBatch batch) { for (int current_row = 0; current_row &lt; 10; current_row++) { for (int column = 0; column &lt; player_colors[current_row].Count(); column++) { int x = 100 + column * 70; int y = 100 + column * 70; Vector2 loc = new Vector2 (x, y); Color c = player_colors[current_row].ElementAt (column); batch.Draw (dot_picture, loc, c); } } } } } </code></pre> <p>Newest Error:</p> <p>It looks as though I have gotten it to slightly work however I'm now getting an error in the Basic Template on: <code>logoTexture = Content.Load&lt;Texture2D&gt;("logo");</code></p> <p>The error will be below</p> <blockquote> <p>Microsoft.Xna.Framework.Content.ContentLoadException: Could not load logo asset as a non- content file! ---> System.Exception: The directory was not found. ---> System.Exception: Could not find a part of the path "/Users/sebnabt/Projects/BSMac/BSMac/bin/Debug/BSMac.app/Contents/Resources/Content/logo.xnb". at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) [0x001c6] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin-no-pcl/build-root/mono-3.2.0/mcs/class/corlib/System.IO/FileStream.cs:266 at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share) [0x00000] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin-no-pcl/build-root/mono-3.2.0/mcs/class/corlib/System.IO/FileStream.cs:132 at at (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare)<br> at System.IO.File.OpenRead (System.String path) [0x00000] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin-no-pcl/build-root/mono-3.2.0/mcs/class/corlib/System.IO/File.cs:341 at Microsoft.Xna.Framework.TitleContainer.OpenStream (System.String name) [0x00000] in :0 at Microsoft.Xna.Framework.Content.ContentManager.OpenStream (System.String assetName) [0x00000] in :0 --- End of inner exception stack trace --- at Microsoft.Xna.Framework.Content.ContentManager.OpenStream (System.String assetName) [0x00000] in :0 at Microsoft.Xna.Framework.Content.ContentManager.ReadAsset[Texture2D] (System.String assetName, System.Action<code>1 recordDisposableObject) [0x00000] in &lt;filename unknown&gt;:0 --- End of inner exception stack trace --- at at Microsoft.Xna.Framework.Content.ContentManager.ReadAsset&lt;Microsoft.Xna.Framework.Graphics.Texture2D&gt; (string,System.Action</code>1) &lt;0x0076b> at at Microsoft.Xna.Framework.Content.ContentManager.Load (string) &lt;0x0020b> at BSMac.Game1.LoadContent () [0x00023] in /Users/sebnabt/Projects/BSMac/BSMac/Game1.cs:70 at at Microsoft.Xna.Framework.Game.Initialize () at BSMac.Game1.Initialize () [0x00002] in /Users/sebnabt/Projects/BSMac/BSMac/Game1.cs:57 at at Microsoft.Xna.Framework.Game.DoInitialize () <br> at at Microsoft.Xna.Framework.Game.Run (Microsoft.Xna.Framework.GameRunBehavior) at at Microsoft.Xna.Framework.Game.Run () at BSMac.AppDelegate.FinishedLaunching (MonoMac.Foundation.NSObject) [0x00012] in /Users/sebnabt/Projects/BSMac/BSMac/Main.cs:34 at at (wrapper dynamic-method) object.[BSMac.AppDelegate.Void FinishedLaunching(MonoMac.Foundation.NSObject)] (MonoMac.Foundation.NSObject,MonoMac.ObjCRuntime.Selector,MonoMac.Foundation.NSObject) at at (wrapper native-to-managed) object.[BSMac.AppDelegate.Void FinishedLaunching(MonoMac.Foundation.NSObject)] (MonoMac.Foundation.NSObject,MonoMac.ObjCRuntime.Selector,MonoMac.Foundation.NSObject) at at (wrapper managed-to-native) MonoMac.AppKit.NSApplication.NSApplicationMain (int,string[]) &lt;0x00003> at at MonoMac.AppKit.NSApplication.Main (string[]) at BSMac.Program.Main (string[]) [0x0001d] in /Users/sebnabt/Projects/BSMac/BSMac/Main.cs:20 at</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload