I'm pretty new to Dart, and I'm used to working with C# (and XNA usually), so Dart is a little different, and I'm not sure why this error is happening.
double left = c.Position.x - (canvasDimensions.x * 0.5);
the Position and canvasDimensions are a type I created, called Vector2, which basically contains 2 numbers, x and y, I am getting the error
NoSuchMethodError : method not found: '-'
Receiver: null
Arguments: [600.0]
on the line shown, since I am not familiar with the language I am not sure why this is happening, please help, thanks!
Here c.Position.x is null. In Dart calling a method (or an operator - in your case) on null leads to a NoSuchMethodError.
Related
I switched to sound null safety and started getting runtime error in a simple assignment, that should never happen with sound null safety:
final widgetOnPressed = widget.onPressed;
Error:
type '(LogData) => void' is not a subtype of type '((LogData?) => void)?'
I can repro it for Flutter versions 2.12.0-4.1.pre and 2.13.0-0.0.pre.505.
PR: https://github.com/flutter/devtools/pull/3971
Failing line: https://github.com/flutter/devtools/blob/9fc560ff2e6749459e2ca6a1dc00bf6fb16ed93b/packages/devtools_app/lib/src/shared/table.dart#L1184
To repro, start DevTools at this PR for macos, connect to an app and click the tab 'Logging'. DevTools will show red screen and error in console.
Is it dart bug or the app bug? If it is the app bug, how can I debug it?
It's a bug in your code.
You didn't say which kind of error you got - a compile-time error or a runtime error. I'm guessing runtime error. (Well, you did say to launch it in the debugger, so that is a good hint too.)
The line final widgetOnPressed = widget.onPressed; looks like it can't possibly fail. After all, the type of the local variable is inferred from the expression assigned to it, and the runtime value of that expression will surely be a subtype of the static type because the type system is sound!
Isn't it? ISN'T IT?
It's not, sorry. Dart 2's type system is mostly sound, even more so with null safety, but class generics is covariant, which can still be unsound. It's fairly hard to hit one of the cases where that unsoundness shows its ugly head, but returning a function where the argument type is the class's type variable is one.
Your state class extends State<TableRow<T?>>, so the widget getter returns a TableRow<T?>. The onPressed of that type has type ItemCallback<T?>?, aka, void Function(T?)?.
You create a _TableRowState<LogData>, with its widget which has static type TableRow<LogData?>, but you somehow manage to pass it a TableRow<LogData> instead. That's fine. Class generics are covariant, so all is apparently fine at compile-time.
Then you do final widgetOnPressed = widget.onPressed;.
The static type of widgetOnPressed is void Function(LogData?) here.
The actual runtime type of onPressed is void Function(LogData) because it's from a TableRow<LogData>.
A void Function(LogData) is-not-a void Function(LogData?) because the former cannot be used in all places where the latter can (in particular, it can't be used in a place where it's called with null).
This assignment is potentially unsound, and actually unsound in this case. The compiler knows this and inserts an extra check to ensure that you don't assign a value to the variable which isn't actually valid. That check triggers and throws the error you see.
How do you avoid that?
Don't create a TableRow<LogData> where a TableRow<LogData?> is required.
Or type the variable as:
final ItemCallback<T>? widgetOnPressed = widget.onPressed;
(no ? on the T).
Or rewrite everything to avoid returning a function with a covariant type parameter (from the class) occurring contra-variantly (as an argument type).
Which solution fits you depends on what you want to be able to do.
i have strange errors got from my flutter pages do some math computation with null value. or i assume it was makes errors happening.
in my case i do computation such as (120 * null) inside stateful widget init section. when i build in release mode. I have debug view which means it read background in my apps and shows:
NoSuchMethodError: The method '_mulFromInteger' was called on null.
Receiver: null
Tried Calling:_mulFromInteger(134)
is multiply operations (*) have method behind of it? or can anyone explain what is _mulFromInteger?
This implementation of int in dart is provided by the class _IntegerImplementation. In this class you can see:
num operator *(num other) => other._mulFromInteger(this);
You can see that the implementation of the operator * calls _mulFromInteger on the argument. That's why you get this error.
I am working on a Java binding for the excellent libvips
Using this function all is fine:
VipsImage *in;
in = vips_image_new_from_file( test.jpg, NULL )
vips_image_write_to_file( in, "out.jpg", NULL )
So mapped in Java:
Pointer vips_image_new_from_file(String filename,String params);
But I have a problem when the parameter like this:
VipsImage *in;
VipsImage *out;
vips_invert( in, &out, NULL )
vips_image_write_to_file( out, "out.jpg", NULL )
I have tried:
int vips_resize(Pointer in, PointerByReference out, Double scale, String params);
Pointer in = vips_image_new_from_file("file.png",null);
PointerByReference ptr1 = new PointerByReference();
vips_invert(in, ptr1, null);
vips_image_write_to_file( ptr1.getValue(), "fileout.png", null);
But doesn't work. The ptr1.getValue() does not contains the expected result.
How can I do it?
Thanks
I'm the libvips maintainer, a Java binding would be great!
But I think you might be taking the wrong approach. I think you are trying a straight wrap of the C API, but that's going to be tricky to do well, since it makes use of a lot of C-isms that don't map well to Java. For example, in C you can write:
VipsImage *image;
if (!(image = vips_image_new_from_file("somefile.jpg",
"shrink", 2,
"autorotate", TRUE,
NULL)))
error ...;
ie. the final NULL marks the end of a varargs name / value list. Here I'm asking the jpeg loader to do a x2 shrink during load, and to apply any Orientation tags it finds in the EXIF.
libvips has a lower-level API based on GObject which is much easier to bind to. There's some discussion and example code in this issue, where someone is making a C# binding using p/invoke.
https://github.com/jcupitt/libvips/issues/558
The code for the C++ and PHP bindings might be a useful reference:
https://github.com/jcupitt/libvips/tree/master/cplusplus
https://github.com/jcupitt/php-vips-ext
That's a PHP binding for the entire library in 1800 lines of C.
I'd be very happy to help if I can. Open an issue on the libvips tracker:
https://github.com/jcupitt/libvips/issues
When I define a spinner in ScalaJS and handle the spin value I am not able to get the new spin value in the event as I would have expected. According to the JQuery UI documentation the second parameter to the spin event is the ui object that contains a value attribute. So I defined a trait:
trait Number extends js.Object {
val value: Int = js.native
}
And then handle my spin event thus:
jQuery("#mySpinner").spinner(js.Dynamic.literal(spin = { (e: HTMLInputElement, ui: Number) =>
log("Change: " + ui.value)
}: js.ThisFunction1[HTMLInputElement, Number, Any]))
But the "value" attribute does not seem to be a member of the ui object as I get the exception below in my log statement. Can someone tell me what I am doing wrong?
uncaught exception: scala.scalajs.runtime.UndefinedBehaviorError: An
undefined behavior was detected: undefined is not an instance of
java.lang.Integer
You say e: HTMLInputElement but it should be e: Event
I suspect the problem is a combination of the previous comments. You are correct that, since you're using ThisFunction, the first element should be an Element of some sort. (Although, is it really an HTMLInputElement? That's a slightly unusual element type to put a spinner on.)
But that Element gets prepended to the function parameters, whereas you've got it replacing one.
In other words, you have
(e: HTMLInputElement, ui: Number)
but it needs to be
(elem: HTMLInputElement, e:Event, ui: Number)
in order to match the expected signature. So in practice, the system is trying to cast the value member of an Event, which of course doesn't exist, to Integer. It finds that value is undefined, tries to cast it to Integer, and boom.
I can't say I'm 100% certain (and IMO that ui parameter is just plain weird to begin with -- I'm a little suspicious of the jQueryUI documentation there), but that's my guess. Try fixing the signature of your call, and see if the error goes away...
I have some confusion debugging some simple app that uses the Web Audio API.
In the developer console I can do something like this:
var ctx = new webkitAudioContext(),
osc = ctx.createOscillator();
osc.connect(ctx.destination);
osc.start(0);
Trying to get this to work with Dart yields the following errors when I try it like this:
AudioContext ctx = new AudioContext();
OscillatorNode osc = ctx.createOscillator();
osc.connect(ctx.destination);
osc.start(0);
//Dart2JS: Uncaught TypeError: Object #<OscillatorNode> has no method 'connect$1'
//DartVM: Class 'OscillatorNode' has no instance method 'connect' with matching
arguments. NoSuchMethodError: incorrect number of arguments passed to method
named connect' Receiver: Instance of 'OscillatorNode'
Stepping through I found that there are two kinds of implementations to the connect method. So I tried to add an extra second param and since I can not really wrap my head around why it needs an int named "output", thinking maybe it is for volume I decided on the value 1 but that yields:
//Dart2JS: Uncaught Error: IndexSizeError: DOM Exception 1 flexsynth.html_bootstrap.dart.js:8698 $.main flexsynth.html_bootstrap.dart.js:8698 $$._IsolateContext.eval$1flexsynth.html_bootstrap.dart.js:565 $.startRootIsolate flexsynth.html_bootstrap.dart.js:7181 (anonymous function)
//DartVM: "Dart_IntegerToInt64 expects argument 'integer' to be non-null."
Here is where I can't figure out what to do, I think the argument is not null, it is 1.
Googling the errors only leads me to the actual Dart source code.
Is there any place that explains how to work with the dart:web_audio? What am I doing wrong?
This is because the underlying implementation seems to require the parameter input, despite it being an optional parameter. This code will work:
AudioContext ctx = new AudioContext();
OscillatorNode osc = ctx.createOscillator();
osc.connect(ctx.destination, 0, 0);
osc.start(0);
This is a known bug, you can star it here: https://code.google.com/p/dart/issues/detail?id=6728