2015-10-26 35 views
2

我从xamarin下载了活动场景过渡示例应用程序,并在Visual Studio 2015中将其打开,并试图通过VS Emulator运行该应用程序。Xamarin Android资源未知标识符资源

我收到错误“未知的标识符:资源”的行108 MainActivity.cs:

view = context.LayoutInflater.Inflate(Resource.Layout.grid_item, viewGroup, false); 

我并没有改变任何代码,我只是改变了记号,以便部署到执行应用程序在Visual Studio模拟器中。我没有收到任何错误,当我在VS中,我没有得到任何生成错误,只有当它被加载我得到这个错误。

有什么,我失踪?

+0

检查'Resources/layout'中是否有'grid_item.xml'文件。你有没有尝试清洁项目? –

+0

查看你的android资源。确保它们设置为AndroidAsset而不是AndroidBundle? –

回答

1

https://stackoverflow.com/a/36409069

有一个长期的调试问题Xamarin.Android与Visual Studio相关的静态类检测值。具体而言,如果您在引用静态类(或具有静态成员的非静态类)的行上设置断点,则Visual Studio可能会将检查值显示为“未知标识符:[ClassName]”。

从我的分析中可以看出,项目中类文件的位置决定了你是否会遇到这个问题。

对我而言,最终结果是,除非Xamarin修复了这个错误,否则所有静态类和具有静态成员的类都应放置在项目的根文件夹中。还有其他的文件放置选项,但某些单元不起作用,并且需要用命名空间完全限定静态类调用 - 即使编译器不需要。

有关完整的详细信息,请参阅下面的代码中的注释。

MainActivity.cs

using System; 
using Android.App; 
using Android.OS; 

namespace App1 { 

[Activity(Label = "Unknown Identifier Test", MainLauncher = true)] 
public class MainActivity : Activity {   

    protected override void OnCreate(Bundle bundle) { 
     base.OnCreate(bundle); 

     Console.WriteLine(MyClass.MyString);   // Unqualified 
     Console.WriteLine(App1.MyClass.MyString);  // Fully Qualified with namespace 

     /* 
     Set a break point on the "Console.WriteLine()" lines above and you'll get the 
     "Unknown identifier: MyClass" error when trying to inspect under specific conditions... 

     File Locations          Unqualified    Fully Qualified 
     ------------------------------------------------- --------------------- -------------------- 
     MainActivity.cs in root, MyClass.cs in sub-folder "Unknown identifier" Inspection Works 
     MainActivity.cs in sub-folder, MyClass.cs in root Inspection Works  Inspection Works 
     Both in root          Inspection Works  Inspection Works 
     Both in different sub-folders      "Unknown identifier" "Unknown identifier" 
     Both in same sub-folder        "Unknown identifier" "Unknown identifier" 
     */ 
    } 
} 
} 

MyClass.cs

namespace App1 { 
public static class MyClass { 
    public static string MyString; 
} 

// The class can also be constructed this way, which results in the same findings: 
//public class MyClass { 
// public static string MyString; 
//}  
} 

在2016年4月3日,我更新了相关Xamarin的Bugzilla票这一信息。希望他们很快得到解决。