我已经在Xamarin中实现了一个项目。在模拟器和设备上运行它,它表明不幸的是,App已停止。
我是xamarin的新手,我对这个问题毫无头绪。 我已经解决了所有的错误和警告,但它只显示了这一点。
自定义spinner.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();
}
}
}
}
}
主要活动
[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();
}
}
}
清单文件
<?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>
请保存我的日子并帮我在设备上运行它。
谢谢
答案 0 :(得分:0)
您收到 NullPointerException
#Python 3.4
list=[]
list_of_list=[]
list.append("Test")
list.append("This")
list_of_list.append(list)
list=[]
print(list_of_list)
print(type(list_of_list))
print(len(list_of_list))
for element in list_of_list:
if(element[0]=="Test"):
print("[OK]")
if(element[0]=="NO"):
print("[OK]Condition is not verified")
else:
print("[OK]Why the condition is verified??")#<--------------------------
[['Test', 'This']]
<class 'list'>
1
[OK]
[OK]Why the condition is verified??
说[['Test', 'This']]
<class 'list'>
1
[OK]
客观 null
答案 1 :(得分:0)
在你的问题中没有背景细节或没有你的实际代码我可以建议你:
修改您的.csproj
。如果<AndroidUseLatestPlatformSdk>True</AndroidUseLatestPlatformSdk>
在文件中,请尝试将其设置为False
,如<AndroidUseLatestPlatformSdk>False</AndroidUseLatestPlatformSdk>
。清理所有内容并重建,重新安装应用程序。
转到AndroidManifest.xml
并将“安装位置”设置为internalOnly
。
尝试降级Target Framework
。
P.S:以上是3个不同的建议,而不是同一建议的3个不同步骤。 上述建议通常有效,但您没有在问题中提及太多细节。