Error:

Inconsistent accessibility: field type 'drag_and_lock_grid.Puzzlepiece[]' is less accessible than field 'drag_and_lock_grid.Game1.pieces'


What does this means?
How to solve this error?

Recommended Answers

All 9 Replies

Show the code where you are getting this error and I will try to help.

The line states the error:
public static Puzzlepiece[] pieces;

And this is my Puzzlepiece class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace drag_and_lock_grid
{
    class Puzzlepiece
    {
        public int id;
        public Vector2 position;
        public Vector2 previousPosition;
        public Boolean dragging;
        public Vector2 correctPosition;
        public Texture2D texture;
        public Boolean disabled = false;

        public Texture2D plu;
        public Vector2 lightUpPostion;
        public int delay = 3;
        public int delayTimer = 0;
        public int frame = 1;
        public Boolean descending = false;

        public Boolean stopAnimation;
        

        public Puzzlepiece(int id, Vector2 position, Texture2D texture, Vector2 correctPosition)
        {
            this.id = id;
            this.position = position;
            this.texture = texture;
            this.correctPosition = correctPosition;


            lightUpPostion = new Vector2(correctPosition.X - 5, correctPosition.Y - 5);
        }

        public void Draw()
        {
            Game1.spriteBatch.Draw(texture, position, Color.White);

            if (disabled)
            {

                if (!stopAnimation)
                {
                    plu = Game1.content.Load<Texture2D>("images/pieceslightup/plu_" + frame);
                    Game1.spriteBatch.Draw(plu, lightUpPostion, Color.White);
                    delayTimer++;

                    if (delayTimer > delay)
                    {
                        if (frame < 3)
                        {
                            if (!descending)
                            {
                                frame++;
                                delayTimer = 0;
                            }
                        }
                        else
                            descending = true;

                        if (descending)
                        {
                            frame--;
                            delayTimer = 0;
                        }

                        if (frame == 0)
                        {
                            stopAnimation = true;
                        }
                    }

                }
            }

        }

        public void Update()
        {

        }

        public void touchDown(float x, float y)
        {
            //Game1.spriteBatch.GraphicsDevice.Clear(Color.White);
        }
        public void touchMove(float x, float y)
        {
            //if(!dragging)
            //{
            //    dragging = true;
            //    previousPosition.X = x;
            //    previousPosition.Y = y;
            //}
            if (!disabled)
            {
                if (isWithinPuzzle(x, y))
                {
                    position.X = x - (texture.Width / 2);
                    position.Y = y - (texture.Height / 2);
                }
            }

        }
        public void touchUp(float x, float y)
        {
            if (isWithinPuzzle(x, y))
            {
                if (isWithinCorrectPosition(x, y))
                {
                    position.X = correctPosition.X;
                    position.Y = correctPosition.Y;
                    disabled = true;
                    addPoint();
                }
            }
            //dragging = false;
            //position.X = previousPosition.X;
            //position.Y = previousPosition.Y;
        }

        public Boolean isWithinPuzzle(float x, float y)
        {
            if (x > position.X && x < position.X + texture.Width && y > position.Y && y < position.Y + texture.Height)
            {
                return true;
            }
            return false;
        }

        public Boolean isWithinCorrectPosition(float x, float y)
        {
            if (x > correctPosition.X && x < correctPosition.X + texture.Width && y > correctPosition.Y && y < correctPosition.Y + texture.Height)
            {
                return true;
            }
            return false;
        }

        public void addPoint()
        {
            if (!pointAdded)
            {
                Game1.noc++;
                pointAdded = true;
            }

        }


    }
}
commented: Code Tags Please =/ (Also the error is pretty self-explanatory a quick google would have given you the answer) +0

I'm using XNA and C #

Your declaration for Puzzlepiece is private (this is the implicit default for classes).

Yet you are using it for a public variable here: public static Puzzlepiece[] pieces; A private class can not be used for public variables or methods; either as a return type or parameter.

Either make the Puzzlepiece class public or make the variable pieces private (or protected if it is in a class).

This is the updated version.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace drag_and_lock_grid
{
    class Puzzlepiece
    {
        private int id;
        private Vector2 position;
        private Vector2 previousPosition;
        private Boolean dragging;
        private Vector2 correctPosition;
        private Texture2D texture;
        private Boolean disabled = false;

        private Texture2D plu;
        private Vector2 lightUpPostion;
        private int delay = 3;
        private int delayTimer = 0;
        private int frame = 1;
        private Boolean descending = false;

        private Boolean stopAnimation;
        

        public Puzzlepiece(int id, Vector2 position, Texture2D texture, Vector2 correctPosition)
        {
            this.id = id;
            this.position = position;
            this.texture = texture;
            this.correctPosition = correctPosition;


            lightUpPostion = new Vector2(correctPosition.X - 5, correctPosition.Y - 5);
        }

        public void Draw()
        {
            Game1.spriteBatch.Draw(texture, position, Color.White);

            if (disabled)
            {

                if (!stopAnimation)
                {
                    plu = Game1.content.Load<Texture2D>("images/pieceslightup/plu_" + frame);
                    Game1.spriteBatch.Draw(plu, lightUpPostion, Color.White);
                    delayTimer++;

                    if (delayTimer > delay)
                    {
                        if (frame < 3)
                        {
                            if (!descending)
                            {
                                frame++;
                                delayTimer = 0;
                            }
                        }
                        else
                            descending = true;

                        if (descending)
                        {
                            frame--;
                            delayTimer = 0;
                        }

                        if (frame == 0)
                        {
                            stopAnimation = true;
                        }
                    }

                }
            }

        }

        public void Update()
        {

        }

        public void touchDown(float x, float y)
        {
            //Game1.spriteBatch.GraphicsDevice.Clear(Color.White);
        }
        public void touchMove(float x, float y)
        {
            //if(!dragging)
            //{
            //    dragging = true;
            //    previousPosition.X = x;
            //    previousPosition.Y = y;
            //}
            if (!disabled)
            {
                if (isWithinPuzzle(x, y))
                {
                    position.X = x - (texture.Width / 2);
                    position.Y = y - (texture.Height / 2);
                }
            }

        }
        public void touchUp(float x, float y)
        {
            if (isWithinPuzzle(x, y))
            {
                if (isWithinCorrectPosition(x, y))
                {
                    position.X = correctPosition.X;
                    position.Y = correctPosition.Y;
                    disabled = true;
                    addPoint();
                }
            }
            //dragging = false;
            //position.X = previousPosition.X;
            //position.Y = previousPosition.Y;
        }

        public Boolean isWithinPuzzle(float x, float y)
        {
            if (x > position.X && x < position.X + texture.Width && y > position.Y && y < position.Y + texture.Height)
            {
                return true;
            }
            return false;
        }

        public Boolean isWithinCorrectPosition(float x, float y)
        {
            if (x > correctPosition.X && x < correctPosition.X + texture.Width && y > correctPosition.Y && y < correctPosition.Y + texture.Height)
            {
                return true;
            }
            return false;
        }

        public void addPoint()
        {
            if (!pointAdded)
            {
                Game1.noc++;
                pointAdded = true;
            }

        }


    }
}

and its still the same error.

i change
public static Puzzlepiece[] pieces;
to
public Puzzlepiece[] pieces;

Make the class public. By default it is private, which is what you have.

namespace drag_and_lock_grid
{
Public class Puzzlepiece
{

But as other posted said you are trying to use a private class in this situation, which is to restrictive.

Make the class public. By default it is private, which is what you have.

namespace drag_and_lock_grid
{
Public class Puzzlepiece
{

But as other posted said you are trying to use a private class in this situation, which is to restrictive


So what you mean is to just leave it as
class Puzzlepiece
??

Sorry. i think i better create a new thread and ask the question again :)
As it is quite confusing :)

If you make the class public

public class Puzzlepiece
{
...
}

You should then be able to keep the variable declation as it is (was).

public static Puzzlepiece[] pieces;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.