Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从Xamarin android资源中的strings.xml正确访问字符串资源?_C#_Android_Xamarin_Android Resources - Fatal编程技术网

C# 如何从Xamarin android资源中的strings.xml正确访问字符串资源?

C# 如何从Xamarin android资源中的strings.xml正确访问字符串资源?,c#,android,xamarin,android-resources,C#,Android,Xamarin,Android Resources,我无法从资源文件中获取字符串,也找不到有效的解决方案。我与官员和政府官员一起工作过。 这是一个xamarin表单项目,我希望应用程序以德语/英语显示。ios部分已经工作了 到目前为止,我所拥有的: 以下文件夹结构中的我的语言文件: 资源>值>字符串.xml 资源>值de>Strings.xml Strings.xml: <?xml version="1.0" encoding="utf-8"?> <resources> <

我无法从资源文件中获取字符串,也找不到有效的解决方案。我与官员和政府官员一起工作过。 这是一个xamarin表单项目,我希望应用程序以德语/英语显示。ios部分已经工作了

到目前为止,我所拥有的:

以下文件夹结构中的我的语言文件:

资源>值>字符串.xml

资源>值de>Strings.xml

Strings.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <string name="barcodescanner_toptext">QR-Code Scanner</string>
  <string name="barcodescanner_bottomtext">Please scan QR-Code.</string>
  <string name="barcodescanner_cancelbuttontext">Cancel</string>
  <string name="barcodescanner_flashbuttontext">Flash</string>
  <string name="barcodescanner_errortext">Scan canceled</string>
</resources>
在Scanner.cs文件中,我像教程中那样进行调用:

BarcodeScanner.TopText = Resources.System.GetText(Resource.String.barcodescanner_toptext);
我必须使用。系统。因为资源上没有直接的GetText。如果我按。在Resource.String之后,我将获得所有要选择的resourcestrings。但如果我在android上运行该应用程序,我会得到以下错误:

获取资源号0x7f070040的值时没有已知的包

System.TypeInitializationException:“xyz.ViewModels.MainViewModel”的类型初始值设定项引发异常。-->System.Reflection.TargetInvocationException:调用的目标已引发异常。-->Android.Content.Res.Resources+NotFoundException:字符串资源ID 0x7f070040

到目前为止我所做的:

清理并重建解决方案 已删除obj和bin文件夹 重新启动包括我的电脑在内的所有 从智能手机上卸载应用程序 我不知道下一步该怎么办? 谢谢你的帮助

编辑:
如果它有用,Visual Studio将在此部件Resource.String.barcodescanner\u toptext上显示以下消息:不明确引用:int barcodescanner\u toptext在类字符串中int barcodescanner\u toptext在类字符串匹配中

您尝试过反射吗?如下所示:var resourceValue=stringtypeofResource.String.GetFieldbarcodescanner\u toptext.GetValuenull@Diegrafaelsouza我尝试了没有字符串转换的代码示例,因为我得到了一个转换异常。结果我得到了resourceValue:2131165248
BarcodeScanner.TopText = Resources.System.GetText(Resource.String.barcodescanner_toptext);