2017-03-09 63 views
1

我是Xamarin中的NewBie。我从Nuget Package Manager和Project安装了Android.Support.V7.App库并成功构建。现在,当我extening AppCompatActivity而不是活动比我得到异常: -使用Android.Support.V7.App.AppCompatActivity时获取ResourceNotFoundException

Android.Content.Res.Resources+NotFoundException: Resource ID #0x7f030015 

我的动态代码如下: -

using Android.App; 
    using Android.Widget; 
    using Android.OS; 
    using Android.Content; 
    using Android.Preferences; 
    using Android.Support.V7.App; 

    namespace ExampleDemo 
    { 
[Activity(Label = "ExampleDemo", Icon = "@drawable/icon")] 
public class MainActivity : AppCompatActivity 
{ 
    protected override void OnCreate(Bundle bundle) 
    { 
     base.OnCreate(bundle); 

     // Set our view from the "main" layout resource 
     SetContentView (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"> 
    <Button 
    android:id="@+id/MyButton" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/Hello" 
    android:layout_marginTop="50dp" 
    android:layout_marginLeft="20dp" 
    android:layout_marginRight="20dp" /> 
    </LinearLayout> 

有人可以告诉我我做错了什么?

在此先感谢。

+0

发生异常的地方在哪里? (当您滚动调试输出时,您应该可以找到更多信息) –

+0

干净的解决方案适用于我的MainActivity。但是,当我使用比它给了我另一个异常: - Android.Views.InflateException:二进制XML文件行#1:二进制XML文件行#1:错误膨胀类android.support。 design.widget.TextInputLayout @Malte – yash

回答

0

你试过清理解决方案? Xamarin可以停留在解析xml的地方。

+0

这适用于我的MainActivity。但是,当我使用 比它给了我另一个异常: - Android.Views.InflateException:二进制XML文件行#1:二进制XML文件行#1:错误膨胀类android.support .design.widget.TextInputLayout @nyconing – yash

+0

解决....我需要从Nuget包管理器外部添加android.suppot.design,它工作正常.... – yash

相关问题