I'm trying to use a ListView
within Main.xml
and a ListViewRow
(separate to this) however after running the application i receieve a >
System.NullReferenceException error message
I'm sure i ran this before and it worked.
I have tried several solutions from other posts and other sources however nothing is working.
I have made sure that the listview
exists in the xml and that the ID is correct also.
Thanks for your help everyone
07-17 15:57:16.656 D/Mono ( 4823): AOT: image '/storage/emulated/0/Android/data/theProject.theProject/files/.override/inspector-temp/Xamarin.Interactive.Android.dll.so' not found: dlopen failed: library "/data/app/theProject.theProject-1/lib/x86_64/libaot-Xamarin.Interactive.Android.dll.so" not found 07-17 15:57:16.657 D/Mono ( 4823): AOT: image '/usr/local/lib/mono/aot-cache/amd64/Xamarin.Interactive.Android.dll.so' not found: dlopen failed: library "/data/app/theProject.theProject-1/lib/x86_64/libaot-Xamarin.Interactive.Android.dll.so" not found 07-17 15:57:16.657 D/Mono ( 4823): Assembly Loader loaded assembly from location: '/storage/emulated/0/Android/data/theProject.theProject/files/.override/inspector-temp/Xamarin.Interactive.Android.dll'. 07-17 15:57:16.657 D/Mono ( 4823): Config attempting to parse: '/storage/emulated/0/Android/data/theProject.theProject/files/.override/inspector-temp/Xamarin.Interactive.Android.dll.config'. 07-17 15:57:16.657 D/Mono ( 4823): Config attempting to parse: '/usr/local/etc/mono/assemblies/Xamarin.Interactive.Android/Xamarin.Interactive.Android.config'. InspectorDebugSession(30): StateChange: EntryPointBreakpointHit -> BreakdanceInvoking Loaded assembly: /storage/emulated/0/Android/data/theProject.theProject/files/.override/inspector-temp/Xamarin.Interactive.dll [External] Loaded assembly: /storage/emulated/0/Android/data/theProject.theProject/files/.override/inspector-temp/Xamarin.Interactive.Android.dll [External] 07-17 15:57:16.683 D/Mono ( 4823): Assembly Ref addref Xamarin.Interactive.Android[0x7ff1cb07b100] -> mscorlib[0x7ff1e0ccf580]: 12 07-17 15:57:16.707 D/Mono ( 4823): Assembly Ref addref Xamarin.Interactive.Android[0x7ff1cb07b100] -> Xamarin.Interactive[0x7ff1cb0fdf80]: 2 07-17 15:57:16.719 D/Mono ( 4823): Assembly Ref addref Xamarin.Interactive.Android[0x7ff1cb07b100] -> Mono.Android[0x7ff1cb7c9200]: 2 07-17 15:57:16.945 D/Mono ( 4823): DllImport searching in: '__Internal' ('(null)'). 07-17 15:57:16.945 D/Mono ( 4823): Searching for 'java_interop_jnienv_register_natives'. 07-17 15:57:16.945 D/Mono ( 4823): Probing 'java_interop_jnienv_register_natives'. 07-17 15:57:16.945 D/Mono ( 4823): Found as 'java_interop_jnienv_register_natives'. 07-17 15:57:16.958 D/Mono ( 4823): DllImport searching in: '__Internal' ('(null)'). 07-17 15:57:16.958 D/Mono ( 4823): Searching for 'java_interop_jnienv_call_nonvirtual_void_method_a'. 07-17 15:57:16.958 D/Mono ( 4823): Probing 'java_interop_jnienv_call_nonvirtual_void_method_a'. 07-17 15:57:16.958 D/Mono ( 4823): Found as 'java_interop_jnienv_call_nonvirtual_void_method_a'. 07-17 15:57:16.963 D/Mono ( 4823): DllImport searching in: '__Internal' ('(null)'). 07-17 15:57:16.964 D/Mono ( 4823): Searching for '_monodroid_gc_wait_for_bridge_processing'. 07-17 15:57:16.964 D/Mono ( 4823): Probing '_monodroid_gc_wait_for_bridge_processing'. 07-17 15:57:16.964 D/Mono ( 4823): Found as '_monodroid_gc_wait_for_bridge_processing'. 07-17 15:57:16.974 D/Mono ( 4823): DllImport searching in: '__Internal' ('(null)'). 07-17 15:57:16.974 D/Mono ( 4823): Searching for 'java_interop_jnienv_is_same_object'. 07-17 15:57:16.974 D/Mono ( 4823): Probing 'java_interop_jnienv_is_same_object'. 07-17 15:57:16.974 D/Mono ( 4823): Found as 'java_interop_jnienv_is_same_object'. 07-17 15:57:16.980 D/Mono ( 4823): DllImport searching in: '__Internal' ('(null)'). 07-17 15:57:16.980 D/Mono ( 4823): Searching for 'java_interop_jnienv_new_string'. 07-17 15:57:16.980 D/Mono ( 4823): Probing 'java_interop_jnienv_new_string'. 07-17 15:57:16.980 D/Mono ( 4823): Found as 'java_interop_jnienv_new_string'. 07-17 15:57:16.986 D/Mono ( 4823): DllImport searching in: '__Internal' ('(null)'). 07-17 15:57:16.986 D/Mono ( 4823): Searching for 'java_interop_jnienv_get_static_field_id'. 07-17 15:57:16.986 D/Mono ( 4823): Probing 'java_interop_jnienv_get_static_field_id'. 07-17 15:57:16.986 D/Mono ( 4823): Found as 'java_interop_jnienv_get_static_field_id'. 07-17 15:57:16.990 D/Mono ( 4823): DllImport searching in: '__Internal' ('(null)'). 07-17 15:57:16.990 D/Mono ( 4823): Searching for 'java_interop_jnienv_get_static_object_field'. 07-17 15:57:16.990 D/Mono ( 4823): Probing 'java_interop_jnienv_get_static_object_field'. 07-17 15:57:16.990 D/Mono ( 4823): Found as 'java_interop_jnienv_get_static_object_field'. Thread started: #3 InspectorDebugSession(30): HandleTargetEvent: ThreadStarted InspectorDebugSession(30): StateChange: BreakdanceInvoking -> BreakdanceStarted 07-17 15:57:17.121 D/Mono ( 4823): DllImport searching in: '__Internal' ('(null)'). 07-17 15:57:17.121 D/Mono ( 4823): Searching for 'java_interop_jnienv_call_static_void_method_a'. 07-17 15:57:17.121 D/Mono ( 4823): Probing 'java_interop_jnienv_call_static_void_method_a'. 07-17 15:57:17.121 D/Mono ( 4823): Found as 'java_interop_jnienv_call_static_void_method_a'. 07-17 15:57:17.125 D/Mono ( 4823): Assembly Ref addref theProject[0x7ff1cb7c9100] -> Mono.Android[0x7ff1cb7c9200]: 3 07-17 15:57:17.200 D/Mono ( 4823): DllImport searching in: '__Internal' ('(null)'). 07-17 15:57:17.200 D/Mono ( 4823): Searching for 'java_interop_jnienv_get_array_length'. 07-17 15:57:17.200 D/Mono ( 4823): Probing 'java_interop_jnienv_get_array_length'. 07-17 15:57:17.200 D/Mono ( 4823): Found as 'java_interop_jnienv_get_array_length'. Loaded assembly: MonoDroidConstructors [External] 07-17 15:57:17.305 D/Mono ( 4823): Assembly Ref addref theProject[0x7ff1cb7c9100] -> mscorlib[0x7ff1e0ccf580]: 13 07-17 15:57:17.412 D/Mono ( 4823): DllImport attempting to load: '__Internal'. 07-17 15:57:17.413 D/Mono ( 4823): DllImport loaded library '(null)'. 07-17 15:57:17.413 D/Mono ( 4823): DllImport searching in: '__Internal' ('(null)'). 07-17 15:57:17.413 D/Mono ( 4823): Searching for 'monodroid_get_system_property'. 07-17 15:57:17.413 D/Mono ( 4823): Probing 'monodroid_get_system_property'. 07-17 15:57:17.413 D/Mono ( 4823): Found as 'monodroid_get_system_property'. 07-17 15:57:17.413 D/Mono ( 4823): DllImport searching in: '__Internal' ('(null)'). 07-17 15:57:17.413 D/Mono ( 4823): Searching for 'monodroid_free'. 07-17 15:57:17.413 D/Mono ( 4823): Probing 'monodroid_free'. 07-17 15:57:17.413 D/Mono ( 4823): Found as 'monodroid_free'. 07-17 15:57:17.442 D/Mono ( 4823): DllImport searching in: '__Internal' ('(null)'). 07-17 15:57:17.442 D/Mono ( 4823): Searching for 'java_interop_jnienv_call_nonvirtual_object_method_a'. 07-17 15:57:17.442 D/Mono ( 4823): Probing 'java_interop_jnienv_call_nonvirtual_object_method_a'. 07-17 15:57:17.442 D/Mono ( 4823): Found as 'java_interop_jnienv_call_nonvirtual_object_method_a'. InspectorDebugSession(30): HandleTargetEvent: UnhandledException Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
MainActivity code:
enter code here
using Android.App;
using Android.Widget;
using Android.OS;
using System.Collections.Generic;
using System;
namespace theProject
{
[Activity(Label = "theProject", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
private List<SomeItem> items = new List<SomeItem>();
private ListView listView;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
ListView listView = FindViewById<ListView>(Resource.Id.listView);
items.Add(new SomeItem { Name = "item1"});
items.Add(new SomeItem { Name = "anotherItem"});
MyListViewAdapter myListViewAdapter = new MyListViewAdapter(this, items);
listView.Adapter = myListViewAdapter;
}
}
}
MyListViewAdapter class code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
namespace theProject
{
class MyListViewAdapter: BaseAdapter<SomeItem>
{
private Context context;
private List<SomeItem> items;
public MyListViewAdapter(Context theContext, List<SomeItem> theItems)
{
context = theContext;
items = theItems;
}
public override SomeItem this[int position]
{
get
{
return items[position];
}
}
public override int Count
{
get
{
return items.Count;
}
}
public override long GetItemId(int position)
{
return position;
}
public override View GetView(int position, View convertView, ViewGroup parent)
{
View currentRow = convertView;
if (currentRow == null)
{
currentRow = LayoutInflater.From(context).Inflate(Resource.Layout.ListviewRow, parent, false);
}
ImageView itemImageView = currentRow.FindViewById<ImageView>(Resource.Id.itemImage);
itemImageView = items[position].Image;
TextView itemNameTxtView = currentRow.FindViewById<TextView>(Resource.Id.itemName);
itemNametxtView.Text = items[position].Name;
return currentRow;
}
}
}