I have a class that inherits from Java.IO.FileInputStream. It looks something like this:
public class DeviceInputStream : FileInputStream
{
private FileDescriptor descriptor = null;
private byte currentValue;
public DeviceInputStream(FileDescriptor fd) : base(fd)
{
descriptor = fd;
}
public DeviceInputStream(File file) : base(file){}
public DeviceInputStream(string fileName):base(fileName){}
public override int Read()
{
int byteRead = base.Read();
currentValue = (byte) byteRead;
return byteRead;
}
public byte CurrentValue
{
get { return currentValue; }
}
}
However, when I compile this I get the following error:
unreported exception FileNotFoundException; must be caught or declared to be thrown
super (p0);
DeviceInputStream.java:20
Any ideas as to what might be causing this problem? Thanks.
-Shaun
It seems this is an issue with Xamarin Monodroid and has been filed as a bug to extend the ExportAttribute to constructors. Details are from here:
http://forums.xamarin.com/discussion/500/inheriting-from-fileinputstream
At build time, Android Callable Wrappers (ACWs) are generated for each Java.Lang.Object subclass, which includes our DeviceInputStream type:
Since ACWs are Java code, they need to be valid Java code. Unfortunately, in this circumstance they’re not, because the super(p0) invocation in e.g. the DeviceInputStream(String) constructor is FileInputStream(String), which throws a FileNotFoundException.
Since the DeviceInputStream(String) constructor invokes a method which may thrown an exception, DeviceInputStream(String) must either contain a throws clause or have a try/catch block around the super(p0) statement. Neither happens, hence the compiler error.
Unfortunately, there is no workaround at this time; there isn’t a way to add a throws to the ACW on constructor bodies, and there is no other way to customize the ACW’s constructor, so you’re stuck. 🙁
Support to extend ExportAttribute so that this could work has been filed at bug 8754.