Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/301.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应用程序已停止_C#_Android_Xamarin_Spinner - Fatal编程技术网

C# Xamarin应用程序已停止

C# Xamarin应用程序已停止,c#,android,xamarin,spinner,C#,Android,Xamarin,Spinner,我已经在Xamarin中实现了一个项目。在emulator和设备上运行它时,它表明不幸的是,应用程序已经停止 我是xamarin的新手,我对这个问题一无所知。 我已经解决了所有的错误和警告,但它只是这样显示 我的设备catlog如下所示: 自定义微调器.cs namespace App1.Assets.Ccode.Cspinner { class CustomSpinner : BaseAdapter { private Context c;

我已经在Xamarin中实现了一个项目。在emulator和设备上运行它时,它表明不幸的是,应用程序已经停止

我是xamarin的新手,我对这个问题一无所知。 我已经解决了所有的错误和警告,但它只是这样显示

我的设备catlog如下所示:

自定义微调器.cs

namespace App1.Assets.Ccode.Cspinner
{


    class CustomSpinner : BaseAdapter
    {
        private Context c;
        private JavaList<CountryName> countries;
        private LayoutInflater inflater;

        public CustomSpinner(Context c, JavaList<CountryName> countries)
        {
            this.c = c;
            this.countries = countries;
        }

        public override Java.Lang.Object GetItem(int position)
        {
            return countries.Get(position);
        }

        public override long GetItemId(int position)
        {
            return position;
        }

        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            if (inflater == null)
            {
                inflater = (LayoutInflater)c.GetSystemService(Context.LayoutInflaterService);
            }

            if (convertView == null)
            {
                convertView = inflater.Inflate(Resource.Layout.country_list, parent, false);
            }

            TextView nameTxt = convertView.FindViewById<TextView>(Resource.Id.nameTxt);
            ImageView img = convertView.FindViewById<ImageView>(Resource.Id.India);

            //BIND
            nameTxt.Text = countries[position].Name;
            img.SetImageResource(countries[position].Image);


            return convertView;
        }

        public override int Count
        {
            get
            {
                return countries.Size();
            }
        }

    }
  }
  }
名称空间App1.Assets.Ccode.Cspinner
{
类CustomSpinner:BaseAdapter
{
私有上下文c;
私营国家;
私人充气机;
公共CustomSpinner(上下文c、JavaList国家/地区)
{
这个.c=c;
这个国家=国家;
}
public override Java.Lang.Object GetItem(int位置)
{
返回国家。获取(位置);
}
公共覆盖长GetItemId(int位置)
{
返回位置;
}
公共覆盖视图GetView(int位置、视图转换视图、视图组父视图)
{
如果(充气器==null)
{
充气器=(LayoutInflater)c.GetSystemService(Context.LayoutInflaterService);
}
if(convertView==null)
{
convertView=充气机。充气(Resource.Layout.country\u列表,父项,false);
}
TextView nameTxt=convertView.FindViewById(Resource.Id.nameTxt);
ImageView img=convertView.findviewbyd(Resource.Id.India);
//束缚
nameTxt.Text=国家[职位].Name;
img.SetImageResource(国家[位置].Image);
返回视图;
}
公共覆盖整数计数
{
得到
{
返回国。大小();
}
}
}
}
}
主要活动

[Activity(Label = "App1", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
    private Spinner sp;
    private CustomSpinner adapter;
    private JavaList<CountryName> countries;

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

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

        sp = FindViewById<Spinner>(Resource.Id.country);
        countries = CountriesList.GetCountrys();
        adapter = new CustomSpinner(this, countries);

        sp.Adapter = (ISpinnerAdapter)adapter;
        sp.ItemSelected += sp_ItemSelected;
    }

    void sp_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e)
    {
        Toast.MakeText(this, countries[e.Position].Name, ToastLength.Short).Show();
    }
}
}
[活动(Label=“App1”,MainLauncher=true,Icon=“@drawable/Icon”)]
公共课活动:活动
{
私人纺纱机;
专用微调器适配器;
私营国家;
创建时受保护的覆盖无效(捆绑包)
{
base.OnCreate(bundle);
//从“主”布局资源设置视图
SetContentView(Resource.Layout.Main);
sp=FindViewById(Resource.Id.country);
countries=CountriesList.getcountries();
适配器=新的CustomSpinner(此,国家/地区);
sp.适配器=(ISpinnerAdapter)适配器;
sp.ItemSelected+=sp_ItemSelected;
}
void sp_ItemSelected(对象发送方,AdapterView.ItemSelectedEventArgs e)
{
Toast.MakeText(这是countries[e.Position].Name,ToastLength.Short.Show();
}
}
}
清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="App1.App1" android:versionCode="1" android:versionName="1.0"
android:installLocation="auto">
<uses-sdk android:minSdkVersion="16" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:label="App1"></application>
</manifest>

请保存我的一天,并帮助我在设备上运行它


谢谢

您收到了一个空点异常

file.getAbsolutePath();
错误
表示
文件
对象为null

这就是确切的错误:-

如果您的问题中没有多少背景细节,或者没有您的实际代码,我可以向您提出以下建议:

  • 编辑您的
    .csproj
    。如果文件中的
    True
    ,请尝试将其设置为
    False
    类似
    False
    。清理所有内容并重建,重新安装应用程序

  • 转到
    AndroidManifest.xml
    并将“安装位置”设置为
    internalOnly

  • 尝试降级
    目标框架

  • 注:以上是3个单独的不同建议,而不是同一建议的3个不同步骤。
    上述建议通常有效,但您仍然没有提到问题中的许多细节。

    没有代码,我如何帮助亲爱的。试图在其上使用getAbsolutePath()的文件对象为null。因此,请检查文件为何未初始化目标框架是什么?@Mohammed Dastagir您仍然没有更新与
    文件相关的任何内容。