Ошибка компилятора cs0117

I am trying to call a load_words() method from Words class in the Main() method and it's giving me this error: Error CS0117 'Words' does not contain a definition for 'load_words' How do I call...

I am trying to call a load_words() method from Words class in the Main() method and it’s giving me this error:

Error CS0117 ‘Words’ does not contain a definition for ‘load_words’

How do I call this function?

Scott Hannen's user avatar

Scott Hannen

26.6k3 gold badges45 silver badges59 bronze badges

asked Nov 4, 2018 at 12:45

Anonymous_'s user avatar

3

-If you are using it in different namespace and trying to use the other namespace’s dll then it wont refer this method.

-You may need to rebuild the project

-if not try create class with namespace name might resolve your problem

namespace.Words words = new namespace.Words(); 
words.load_words();

answered Nov 4, 2018 at 13:04

Omar Hamdan's user avatar

Omar HamdanOmar Hamdan

1722 silver badges12 bronze badges

0

The compiler isn’t telling you that it can’t find the class, Words. It’s telling you that it can’t find the method.

Sometimes the method exists but you can’t call it. For example, maybe it’s not public. But if that were the case you would get a different error message.

So the most likely cause is a typo where you’re calling the method. Verify you’ve got the name of the method exactly correct. It’s case-sensitive. If you haven’t exactly matched the name of the method then the method you’re calling actually doesn’t exist, which is why the compiler says the class doesn’t contain that method.

Another possibility is that you’ve got two classes named Words. One is in the same namespace as your Main method and the other isn’t. If the one with a load_words method is in another namespace, then the compiler is looking at the class that doesn’t have that method.

answered Nov 4, 2018 at 13:18

Scott Hannen's user avatar

Scott HannenScott Hannen

26.6k3 gold badges45 silver badges59 bronze badges

I am trying to call a load_words() method from Words class in the Main() method and it’s giving me this error:

Error CS0117 ‘Words’ does not contain a definition for ‘load_words’

How do I call this function?

Scott Hannen's user avatar

Scott Hannen

26.6k3 gold badges45 silver badges59 bronze badges

asked Nov 4, 2018 at 12:45

Anonymous_'s user avatar

3

-If you are using it in different namespace and trying to use the other namespace’s dll then it wont refer this method.

-You may need to rebuild the project

-if not try create class with namespace name might resolve your problem

namespace.Words words = new namespace.Words(); 
words.load_words();

answered Nov 4, 2018 at 13:04

Omar Hamdan's user avatar

Omar HamdanOmar Hamdan

1722 silver badges12 bronze badges

0

The compiler isn’t telling you that it can’t find the class, Words. It’s telling you that it can’t find the method.

Sometimes the method exists but you can’t call it. For example, maybe it’s not public. But if that were the case you would get a different error message.

So the most likely cause is a typo where you’re calling the method. Verify you’ve got the name of the method exactly correct. It’s case-sensitive. If you haven’t exactly matched the name of the method then the method you’re calling actually doesn’t exist, which is why the compiler says the class doesn’t contain that method.

Another possibility is that you’ve got two classes named Words. One is in the same namespace as your Main method and the other isn’t. If the one with a load_words method is in another namespace, then the compiler is looking at the class that doesn’t have that method.

answered Nov 4, 2018 at 13:18

Scott Hannen's user avatar

Scott HannenScott Hannen

26.6k3 gold badges45 silver badges59 bronze badges

Содержание

  1. Как исправить ошибки CS0117 и CS0122?
  2. Ошибка CS0117 в Unity.
  3. Ошибка CS0117 в Unity.

Как исправить ошибки CS0117 и CS0122?

По туториалу собираю Tower Defence на Unity для себя и на моменте создания скрипта для башен получаю ошибки CS0117 и CS0122.
Туториал супер наглядный, там просто пишется код и дополнительно объясняется что к чему.
По итогу его написания у человека все работает, у меня ошибки.
Дословно выглядят они так:

1) AssetsScriptsTower.cs(26,41): error CS0117: ‘Enemies’ does not contain a definition for ‘enemies’

2) AssetsScriptsTower.cs(51,21): error CS0122: ‘Enemy.takeDamage(float)’ is inaccessible due to its protection level

  • Вопрос задан 13 мая 2022
  • 166 просмотров

Простой 1 комментарий

1 — у тебя в классе Enemies нет члена enemies. Возможно его нет совсем, а возможно у тебя опечатка.
2 — у тебя в классе Enemy есть метод takeDamage, но он не публичный

PS: На будущее:
— отмечай комментарием, на какой именно строке сработала ошибка
— не забывай заворачивать код в тег — это сильно упростит чтение для тех, кто попробует решить твой вопрос
— перед тем как задавать вопрос — попробуй загуглить в чём суть ошибки, и попробуй сам решить (CS0117, CS0122)
— перед тем как начинать писать на юнити, лучше всё-таки хоть самые основы C# изучить. Тут как в математике — без понимания простых вещей, ты гарантированно не сможешь понять сложные вещи.

Источник

Ошибка CS0117 в Unity.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class движение : MonoBehaviour
<
public float speed;
public float jumpForce;
public float moveInput;

public Joystick joystick;

private Rigidbody2D rb;

private bool facingRight = true;

private bool isGrounded;
public Transform feetPos;
public float checkRadius;
public LayerMask whatIsGround;

private void Start()
<
rb = GetComponent ();
>

private void FixedUpdate()
<
moveInput = joystick.Horizontal;
rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
if(facingRight == false && moveInput > 0)
<
Flip();
>
else if(facingRight == true && moveInput = .5f)
<
rb.velocity = Vector2.up * jumpForce;
>
>

void OnCollisionEnter2D(Collision2D shit)
<
if (shit.gameObject.tag == «враг»)
<
ReloadFuckingLevel ();
>
>

void ReloadFuckingLevel()
<
Application.LoadLevel (Application.loadLevel); //здесь ошибка
>

void Flip()
<
facingRight = !facingRight;
Vector3 Scaler = transform.localScale;
Scaler.x *= -1;
transform.localScale = Scaler;
>
>

cs(63,44): error CS0117: ‘Application’ does not contain a definition for ‘loadLevel’ это целиком ошибка. Помогите пожалуйста.

Источник

Ошибка CS0117 в Unity.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class движение : MonoBehaviour
<
public float speed;
public float jumpForce;
public float moveInput;

public Joystick joystick;

private Rigidbody2D rb;

private bool facingRight = true;

private bool isGrounded;
public Transform feetPos;
public float checkRadius;
public LayerMask whatIsGround;

private void Start()
<
rb = GetComponent ();
>

private void FixedUpdate()
<
moveInput = joystick.Horizontal;
rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
if(facingRight == false && moveInput > 0)
<
Flip();
>
else if(facingRight == true && moveInput = .5f)
<
rb.velocity = Vector2.up * jumpForce;
>
>

void OnCollisionEnter2D(Collision2D shit)
<
if (shit.gameObject.tag == «враг»)
<
ReloadFuckingLevel ();
>
>

void ReloadFuckingLevel()
<
Application.LoadLevel (Application.loadLevel); //здесь ошибка
>

void Flip()
<
facingRight = !facingRight;
Vector3 Scaler = transform.localScale;
Scaler.x *= -1;
transform.localScale = Scaler;
>
>

cs(63,44): error CS0117: ‘Application’ does not contain a definition for ‘loadLevel’ это целиком ошибка. Помогите пожалуйста.

Источник

I use Visual Studio 2015 with Xamarin.
I’m naming my project «Phoneword»
I see this code such as tutorial/example on Xamarin’s site.

The same error for TranslateButton and CallButton members.

MainActivity.cs

using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace Phoneword
{
[Activity(Label = "Phoneword", MainLauncher = true)]
public class MainActivity : Activity
{
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        // Set our view from the "main" layout resource
        SetContentView(Resource.Layout.Main);

        // Our code will go here
        // Get our UI controls from the loaded layout:
        EditText phoneNumberText = (EditText)FindViewById(Resource.Id.PhoneNumberText);
        Button translateButton = FindViewById<Button>(Resource.Id.TranslateButton);
        Button callButton = FindViewById<Button>(Resource.Id.CallButton);

        // Disable the "Call" button
        callButton.Enabled = false;

        // Add code to translate number
        string translatedNumber = string.Empty;

        translateButton.Click += (object sender, EventArgs e) =>
        {
            // Translate user's alphanumeric phone number to numeric
            translatedNumber = Core.PhonewordTranslator.ToNumber(phoneNumberText.Text);
            if (String.IsNullOrWhiteSpace(translatedNumber))
            {
                callButton.Text = "Call";
                callButton.Enabled = false;
            }
            else
            {
                callButton.Text = "Call " + translatedNumber;
                callButton.Enabled = true;
            }
        };

        callButton.Click += (object sender, EventArgs e) =>
        {
            // On "Call" button click, try to dial phone number.
            var callDialog = new AlertDialog.Builder(this);
            callDialog.SetMessage("Call " + translatedNumber + "?");
            callDialog.SetNeutralButton("Call", delegate {
                // Create intent to dial phone
                var callIntent = new Intent(Intent.ActionCall);
                callIntent.SetData(Android.Net.Uri.Parse("tel:" + translatedNumber));
                StartActivity(callIntent);
            });
            callDialog.SetNegativeButton("Cancel", delegate { });

            // Show the alert dialog to the user and wait for response.
            callDialog.Show();
        };
    }

}
}

Resource/Layout/Main.axml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView
        android:text="Enter a Phoneword"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/textView1" />
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/PhoneNumberText"
        android:text="1-855-XAMARIN" />
    <Button
        android:text="Translate"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/TranslateButton" />
    <Button
        android:text="Call"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/CallButton" />
</LinearLayout>

I’m beginner in Android development, if you need other information i’ll try to add more detail.
Please help me

asked Jun 29, 2016 at 14:57

Greta's user avatar

GretaGreta

1111 gold badge1 silver badge10 bronze badges

2

I solved my problem!
From Tools/Android SDK Manager I uninstalled:

  • Android SDK Build-tools 24
  • Android N (API 24)

and I installed:

  • Android 6.0 (API 23)
  • Android SDK Build-tools 23.0.3
  • Android SDK Build-tools 23.0.2

After I closed VS and I restarted it… In the Solution Explorer I selected «Clean Solution» and after I selected «Rebuild Solution».

answered Jun 30, 2016 at 12:53

Greta's user avatar

GretaGreta

1111 gold badge1 silver badge10 bronze badges

This kind of thing happens so often in Visual Studio, and wastes so much time.

Try…

Exclude from Project, then Add Existing Item

Works more often than not, much easier to at least try before some of the suggestions above

answered Nov 13, 2018 at 15:00

telecetera's user avatar

The issue for me was that I changed the Namespace from the default that was created, after I had been working in the project for a bit.

answered Mar 24, 2017 at 1:41

Eldon Elledge's user avatar

1

This can also be caused if you have a values XML file that doesn’t have a build action of AndroidResource (sometimes VS will create it as a TransformFile)

answered Sep 28, 2016 at 8:02

Adam Baxter's user avatar

Adam BaxterAdam Baxter

1,76721 silver badges40 bronze badges

1

I have the same error, but my solution itself would still compile.

It’s still annoying though to have the error list littered with false errors.

Try this:

  • delete the .vs folder

  • clean solution and then re-open studio,

With these steps I no longer received the false errors. I would recommend trying this for anyone who has a similar situation.

answered May 17, 2018 at 13:46

StefanoM5's user avatar

StefanoM5StefanoM5

1,3271 gold badge25 silver badges34 bronze badges

I faced the same problem following the tutorial Remote Notification with Firebase Cloud Messaging, I one step I had to replace de «activity_main.axml» with a code that introduced the resource

android:id="@+id/msgText"

The application did run fine, but compiler showed the error «resource.id does not contain a definition for msgText», in method MainActivity.OnCreate which invokes it this way:

this.msgText = FindViewById<TextView>(Resource.Id.msgText);

After I closed VS and I restarted it… In the Solution Explorer I selected «Clean >Solution» and after I selected «Rebuild Solution».

worked for me. BTW, I’m running VS2019

answered May 24, 2019 at 23:26

Lupa's user avatar

LupaLupa

5468 silver badges21 bronze badges

I know this goes back to 2014, this issue is all over the web and still an issue in 2019. Nothing would fix it for me from all the websites, could never get FindViewById to see the Button’s name even though it’s in the auto generated proxy class.

Now this seems to be working, I used the dynamic ID of the button control instead of it’s name, .i.e. Button dsdsd = FindViewById(2131230730); So far so good.

Edit: Confirmed this works for me, firing my delegate function.

Edit: Yet another update, after adding another UI control, sequentially after the button, the button name is now showing up, (in intelisense). I don’t have to use the ID now. The new control is not showing up though. Even with complete rebuild and closing and re-opening the project/IDE. BTW using Xamarin Android native, not forms.

answered Oct 1, 2019 at 18:12

K C's user avatar

Sometimes such error happens when your layout xml file has errors (which haven’t been spotted yet). For example, if you have attribute duplicate or unclosed quotes (could happen when you change value).

So the element which contains an error and all the following elements will become ‘invisible’ in your project.

Just try checking for errors once more. When errors are gone — elements become ‘visible’ automatically!

answered Dec 11, 2019 at 9:37

Alexander Gorg's user avatar

it worked for me after restarting visual studio

answered Apr 14, 2020 at 6:02

bomee boome's user avatar

0

How about you go to the xml file related to this activity file and add these three things I have provided below if they are not already there in your xml file.

  xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"

You have to place the after this <?xml version="1.0" encoding="utf-8"?> and inside the relative or linear layout that is for example like this

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
</RelativeLayout>

answered Mar 3, 2022 at 14:08

user18364822's user avatar

Понравилась статья? Поделить с друзьями:
  • Ошибка компиляции файла adobe premiere
  • Ошибка компилятора c3646
  • Ошибка компиляции статус выхода 1
  • Ошибка компилятора c2679
  • Ошибка компиляции при вычислении выражения или выполнении фрагмента кода 1с