Hi everyone, I really do not understand this error " None type object is not suscriptable" - kivy

None type object suscriptable. I really don't understand where is my mistake

Related

Angular 2 dependency injection error on NgFor in dynamically created component

I've dynamically created an Angular 2 component using DynamicComponentLoader.loadAsRoot(), and am trying to give it a useful template (involving NgFor), but this is somehow yielding me a 'DI exception' dependency injection error.
I had already injected NgFor itself though, so specifically now it gave me a No provider for IterableDiffers! (NgFor -> IterableDiffers). So I injected that, which got me to a No provider for Array! (NgFor -> IterableDiffers -> Array). At this point I got stumped; Array is a base type rather than something part of Angular, and somehow trying to similarly inject it did not work (error: Array is a generic; must specificy some sub-type). I'm confused but I'd be surprised if basic types suddenly required injection.
I made a Plunker to recreate my issue here. Interestingly on Plunker the DI exception turned out as No provider for e! (e -> e) instead. Not sure why the difference, but the principle issue would seem similar... though e gives me even less useful info to go by than Array. :(
How might I prevent such exceptions here?

Accessing an explicit conversion operator from F#

I am getting the following error when reading date values out of postgresql using npgsql:
This expression was expected to have type
DateTime
but here has type
NpgsqlTypes.NpgsqlDate
Now the npgsql docs refer to an explicit operator being defined:
[C#]
public static explicit operator DateTime(
NpgsqlDate date
);
but I can't figure out how to access this from F#.
There are several kludgy, longhand ways of achieving what I need, but I am disappointed and frustrated that I was unable to find a way of accessing the inbuilt cast.
I tried the old Convert.ToDateTime(...), but even that doesn't work.
Anybody got a clue? Thx.
The explicit conversion operator can be accessed by calling the op_Explicit (I had the casing wrong in the earlier comment; I had not tried it myself then) function on the type:
let date = NpgsqlDate.op_Explicit npgsqlDate
I have also found various places (like in Yan Cui's blog here) that define an F# operator like !> for (all!) explicit conversions for convenience, so you can just say
let date = !> npgsqlDate
I think that is a pretty neat way.

F# Options... do they really prevent Null Reference Exceptions

I am reading the book "Professional F# 2.0" The author shows the following code
let a string : option = None
if a.IsNone then
System.Console.WriteLine("a is none")
else
System.Console.WriteLine("a is some");;
then says
"this makes the use of Option vastly superior to the use of null and goes a long way towards removing a significant source of exceptions thrown at runtime"
ok. so I write
System.Console.WriteLine(a.GetType());;
And I get
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Object.GetType()
at .$FSI_0008.main#()
Stopped due to error
And I am like 'un!!!"
How is really doing a
if a.isSome then
do bla bla
any different from
if a != null then
do bla bla
So I don't see how is the programmer being saved from NullPointers
PS: NullPointerException has caused me lot of grief in the past.
The F# compiler does not prevent you from NullReferenceException completely. When you work with types defined in .NET, then you can still get null value, because there is no way F# could prevent that.
However, when you work with types declared in F#, then the compiler does not allow creating null values of that type, and so it avoids NullReferenceException in that case. For example, the following code does not compile:
type Person(name:string) =
member x.Name = name
// 'Person' is a type declared in F#, so the argument cannot be 'null' in safe code
let printName (person:Person) =
printfn "%s" person.Name
// Compiler error here - 'null' is not a valid value of 'Pereson' type
printName null
When you use option<Person> as an argument, then you have to explicitly check for None and Some cases. This is best done using match, which checks that you're not missing any of the cases. For example:
let printName (person:option<Person>) =
match person with
// You get a warning here, saying that you're not handling the 'None' case!
| Some person -> printfn "%s" person.Name
The warning tells you that you should add case handling None. You can still compile the code, but you will not get NullReferenceException when working with F# types if you do not ignore warnings.
See also this great, related StackOverflow post.
To add to the answer by Tomas, a major benefit of Option type lies in the higher order functions that it supports, that give you more brevity and safety. You might find my blog post on the topic useful.

Delphi Win32 Programming/Access Violation problems

I wasn't entirely sure how to name this, so apologies in advance.
You see, I'm trying to teach myself Win32/DirectX programming, utilizing Delphi (my language of choice) using this site - http://rastertek.com/tutindex.html
Of course, the site being all in C++, I have to port it to Delphi. It seemed simple enough, at first. I'm on the second tutorial for DirectX 11 - setting up the framework and getting the initial window to show up.
Now for my actual problem. I was getting Access Violation errors. So I found and started to use MadExcept to try and find out what was going on. So it tells me the lines, but I'm clueless as to how to solve the issues at hand.
I have everything set up to mimic as well as I can the original source code. The only real difference being that in the instances where a pointer to a class for a variable, such as the case with m_input, m_grahics, and system, I made a type for those. So I have the TSystemClass, TInputClass, TGraphicsClass, and then I have PSystemClass, etc. that = ^TSystemClass, etc. I figured that this would make things a bit simpler and more neater. On a side note, I assume it should be said, but I for the construction of the copy constructors made the initial classes inherit from TPersistent so I could use it's Assign procedure.
So, back to the Access Violation errors. So first, the problem was in the main program with system being of type PSystemClass. So for a reason unknown to me, when I tried to use system.create, it was at that very instant, creating the access violation. I then realized however that I wasn't assigning system the system.create. So I tried this, and it said that, and rightfully so I suppose, at compile time an error that the two were incompatible since system.create is of type TSystemClass, and system is of PSystemClass. So I tried typecasting it, and that worked. but once again, still getting the dreaded access violations.
So then I had an odd idea, maybe I should call the regular constructor right from the TSystemClass itself. And I tried, needed to typecast again. So I did. And it worked! No longer an access violation error there! Now... New problem! Or rather in this case "problems". There's 3 things now listed in the call stack in MadExcept. The first one:
m_hinstance := GetModuleHandle(nil);
It's saying that this is causing an access violation error. Though why is this, exactly? From what I understand and have read, if GetModuleHandle is set to null/nil, it should retrieve the handle for the file that called it, right? And from what the documentation says, that should be executable.
However note: I'm not sure if the fact that I have the main program, the systemclass stuff, the inputclass stuff, and the graphicsclass stuff, all in different program/unit files to mimic the nature of the original source code. So is this possibly what's causing it? And if so how would I fix it? By putting all of the code from the unit files into the main program file? Though that, in my own personal opinion, would be quite messy and unintuitive.
The next one baffles me even more.
InitializeWindows(ScreenWidth, ScreenHeight);
I'm not dealing with anything other then a function to register the window class and set things up for the window and all here. So I'm not quite sure what the problem here is since it only deals with 2 parameters and they're defined and all already before it's called. So I'm not quite sure what the problem here is at all and what exactly is causing the access violation.
and then finally the final one is in the main program:
return := system.initialize;
Return is what I used in all instances of the result variable of the original source code, as result is of course a built in variable of all functions.
I suppose if system is never able to properly do what it's meant to do then something could/should happen here. Likewise, because I used TSystemClass.Create (typecasted to PSystemClass) earlier to create system would that do anything here? And is it possibly linked to the other two because they're not able to do their own thing properly?
And on a final note; there is one last thing actually on the call stack in MadExcept.
It says Kernel32.dll in the module section, but aside from the main thread, it lists nothing else. (If this information is needed I'll gladly put it up).
Thanks in advance to anyone who's read this far and I hope to find some help on this problem so I may further my studies.
You're instantiating your classes all wrong. Here's an example from TSystemClass.Initialize:
m_Input := PInputClass(m_Input.create);
That's a variable you declared as a PInputClass.
Earlier, in TSystemClass.Create, you initialized that variable:
m_Input := nil;
So, since you have a null reference, it should be clear that you can't call any methods on it. In particular, you cannot call Create on it. Instead, call Create on the class you want to instantiate: TInputClass.Create.
That constructor returns a value of the type you constructed, a TInputClass. It doesn't return a PInputClass, so your type-cast is wrong. As Cosmin's comment explains, Delphi object variables are already pointers. It's exceedingly rare to have to declare a pointer type based on Delphi classes. The correct code is this:
m_Input := TInputClass.Create;
After that line, you check whether m_Input is null. You never have to do that in Delphi; a constructor either returns a valid object, or it doesn't return at all. If there's a problem constructing an object, the constructor throws an exception and the assignment statement never executes. (The original C++ code does it wrong, too. The new operator hasn't returned a null pointer on failure for over a decade, long before anyone was in a position to start writing a DirectX 11 tutorial.)
You should first of all try to get rid of the TPersistent inheritance. If you want to pass an object to a library its interface should be exactly the same as the original that is used in C++. By inheriting from TPersistent you take a whole lot of load into your class that might be not needed or might even be the reason of your problems.
Additionally it would help if you posted the exact output of the exceptions. Or even the CallStack. That might help tracing down the error.

generic was used with wrong number of arguments error?

Does anyone know what on earth this is? i can't get it to go away.
•model {"The generic type 'System.Web.Mvc.ViewUserControl`1' was used with the wrong number of generic arguments in assembly 'System.Web.Mvc...
it happens when i call a newly constructed model that i pass to a partial view, and try using/calling some methods of it in the view.
this is my userControl declaration:
<%# Control Language="VB" Inherits="System.Web.Mvc.ViewUserControl(Of FP.AddFavAction)" %>
edit:
i see it in vs2010, but the code still runs yet it shows this error on breakpoint, yet it still runs and function as requested, but i still worry and want to know if i am doing something fundamentally wrong. googling this really returns almost nothing, but another question like mine that has gone totally unanswered!! there's got to be someone that knows whats going on, not one answer in the whole world. and have serched for the error message generically, removing the ViewUserControl`1 part, and of course teh assembly name!! wow!! –
I am not familiar with 'System.Web.Mvc.ViewUserControl', however, I had a similar error when I attempted to pass a String Property to an unitialized DBCommand.CommandText. Perhaps your ViewUserControl is uninitialized.
The error code:
"+ StringProperty {"The generic type
'GenericClass1' was used with the
wrong number of generic arguments in
assembly 'WindowsApplication1,
Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null'.":"GenericClass1"}
String
The original code:
Using da As DbDataAdapter = DBFactory.CreateDataAdapter
da.InsertCommand.CommandText = InsertCommand
da.InsertCommand.Connection = conn
da.Update(Me)
End Using
The fix:
Using da As DbDataAdapter = DBFactory.CreateDataAdapter
da.InsertCommand = DBFactory.CreateCommand
da.InsertCommand.CommandText = InsertCommand
da.InsertCommand.Connection = conn
da.Update(Me)
da.InsertCommand.Dispose()
End Using
This might not be the exact problem, but the error code was very similar so I thought I'd share the solution to whomever comes across this thread. The Class I was working in was a Generic Class and thus the generic runtime error.

Resources