Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I'm so fed up, I don't know what's going wrong here. I've got a DLGAnalysis object with a constructor with one parameter, and I'm calling the constructor from a Unit Test class.
Here's the DLGAnalysis Object:
class DLGAnalysis
{
public DLGAnalysis(string DLG)
{
_DLG = DLG;
_namespaceAnalyses = new List<NamespaceAnalysis>();
}
}
There's more to that class but it doesn't affect the problem. Here's the unit test segment:
[TestClass]
public class DLGAnalysisTests
{
// Blue line here
private DLGAnalysis dlgAnalysis;
private const string TestDLGName = "TestDLGName";
[TestInitialize]
public void TestSetup()
{
// Error here
dlgAnalysis = new DLGAnalysis(TestDLGName);
}
}
The blue line under "DLGAnalysis" says:
'AnalysisXMLParser.DLGAnalysis' is inaccessible due to its protection level
And the red line under new DLGAnalysis(TestDLGName) says:
'AnalysisXMLParser.DLGAnalysis' does not contain a constructor that takes 1 arguments
The DLGAnalysis object clearly has a public constructor with 1 argument. I have no idea what is going on here. What's the problem? Should I just delete the file and start over?
You forgot to set the protection level of your class
public class DLGAnalysis // <== public
{
Not setting a protection level defaults that class to internal.
As your unit test project is probably in a different assembly, it can't access internal classes.
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
so I have been following this tutorial to create a leaderboard system. Link below
https://www.youtube.com/watch?v=x0Wy7jQ7EFU&t=207s&ab_channel=EEDev
but I had problem on this following script
public class ScoreData : MonoBehaviour
{
public List<Score> scores;
public ScoreData()
{
scores = new List<Score>();
}
}
the console said
"You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all
UnityEngine.MonoBehaviour:.ctor ()"
the tutorial had no problem running but mine has. Hope to have some insight on the matter.
you need to remove : MonoBehaviour from the class Score
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I have been using Visual Studio Code for my C# code; however, it does not seem to realise that I have got a curly bracket '}' at the end of the constructor for my 'opponent' class. Please help me find a way to make it realise that I have done it correctly as far as I can tell!
Here is the class:
public class opponent
{
public int hp = 20;
public int PDmg = 3;
public int KDmg = 3;
public void Opponent(int lv = 1)
{ # red line error marker here
public int level = lv;
}
}
And here is the error message:
} expected [miscellaneousFiles.csproj]
Please help!
I have tried changing the name and capitalisation of the method name but it has not worked so the case-sensitivity of C# is not the problem. I have also tried removing the word 'void' and it did not work either.
double click on the error and it will take you to the place you have missed the brace maybe its not this code where you have got the error
From this line
public int level = lv;
remove public and its gonna work
C# is case-sensitive language, so Opponent and opponent are not the same ;)
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I am trying to call a method (BeginCommand) from another class. The method is using an interface(IAudioRecorder) and has a parameter (recorder). My class is RecorderViewModel.
public void BeginCommand(IAudioRecorder recorder)
{
beginRecordingCommand = new RelayCommand(BeginRecording, () => recorder.RecordingState == RecordingState.Stopped || recorder.RecordingState == RecordingState.Monitoring);
}
Over in my other class here is how I'm trying to call it:
var audiorecorder = new AudioRecorder();
var recordviewmodel = new RecorderViewModel(audiorecorder);
recordviewmodel.BeginCommand();
If I remove the interface and parameter (IAudioRecorder recorder) from the BeginCommand method it will work, but how do I call it with the interface/parameter. It's telling me there is no argument given that corresponds to the required parameter... I'm not sure what parameters to use.
It's hard to tell (with your description) what's going on here, however I suspect you may just be able to do the following:
recordviewmodel.BeginCommand(audiorecorder);
Assuming audiorecorder implements the IAudioRecorder Interface.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
Every time I'd put in static it would keep replacing it with ContextStaticAttribute.
I need 10 rep to post images, but here's the link: http://i.imgur.com/jBOOF3s.png)
I also do not want to have to press the right arrow to put in a local variable!
I just figured out how you did this by typing static inside a method.
Variables in a method cannot be static, only class level elements can.
Simply declare those variables inside the class, not a method.
Example:
namespace ConsoleApplication2
{
class Program
{
static string username; // Correct
private static void Main()
{
static // Incorrect
}
}
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a solution created in C#. i have a piece of code in it base.\u002Ector();. When i try to build the application from Visual Studio I am getting the Following error.
Unexpected character '\u002E'
Remove \u002E and you're done!
002E is a full stop or just a dot ('.').
Your code must look like:
base.ctor();
It could happen because of transmitting a program source through different websites/programs with unsupported or broken encoding.
Moreover, ctor is a shortcut for constructor. Make sure you call constructor of base class correctly.
public class Animal
{
public Animal()
{
}
}
public class Cat : Animal
{
// next line will be converted to
// base.ctor() by compiler
public class Cat() : base()
{
}
}
Try to remove base.ctor(); in order to make your class work. I think it should work because your base class has no parameters in constructor.