【问题标题】:Errors in newly created GTK# project新创建的 GTK# 项目中的错误
【发布时间】:2015-06-29 01:17:23
【问题描述】:

我刚刚在 Ubuntu 14.10 的 32 位机器上安装了 Monodevelop 5.7.0。我创建了一些控制台C# 应用程序进行测试,一切正常。但是当我尝试创建一个GTK# 项目并执行它时,在 Program 和 MainWindow 类中出现以下 3 个错误:

  • the type or namespace name 'Init' does not exist in the namespace 'Application'

  • the type or namespace name 'Run' does not exist in the namespace 'Application'

  • the type or namespace name 'Quit' does not exist in the namespace 'Application'

我一直在尝试添加一些参考并寻找其他解决方案,但没有成功。

这些是应用程序的类:

程序.cs

using System;
using Gtk;

namespace Application
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            Application.Init ();
            MainWindow win = new MainWindow ();
            win.Show ();
            Application.Run ();
        }
    }  
} 

MainWindow.cs

using System;
using Gtk;

public partial class MainWindow: Gtk.Window
{
    public MainWindow () : base (Gtk.WindowType.Toplevel)
    {
        Build ();
    }

    protected void OnDeleteEvent (object sender, DeleteEventArgs a)
    {
        Application.Quit ();
        a.RetVal = true;
    }
}

【问题讨论】:

  • 你能在你的问题中发布代码的相关摘录吗?
  • namespace Application {} 是您的,还是来自 MonoDevelop 在创建项目时生成的样板代码?当您有一个名称与命名空间相同的类时,很多问题就会出现,IDE 不应该这样做。
  • 它是由 MonoDevelop 生成的...
  • 我的 MonoDevelop 版本(Gentoo 上的 3.0.2)使用项目名称作为 MainClass 周围命名空间的基础(在我的测试中是 namespace monogtktest)。我在任何地方都看不到namespace Application。你能指定你正在运行的 MonoDevelop 的版本吗?
  • 哈 :) Gentoo 甚至没有这个不稳定的包,我必须通过一个覆盖。这意味着什么。祝你好运:)

标签: c# monodevelop gtk# ubuntu-14.10


【解决方案1】:

我刚刚修好了。当我错误地创建项目时,我将其命名为“02”,因此在 Program.cs 类中,默认情况下 Monodevelop 将其命名为“Application”而不是项目名称,使错误出现。

您必须更改 Program.cs 类中的命名空间“Application”:

Program.cs

using System;
using Gtk;

namespace two // for example
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            Application.Init ();
            MainWindow win = new MainWindow ();
            win.Show ();
            Application.Run ();
        }
    }  
} 

为避免这种情况,请记住不要在项目名称中只使用数字。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多