null object reference while call other compenet function - apache-flex

I have create the following function in component A(which is productDetailComp)
public function createProductDetailItem(productdetail:Productdetail):void{
productdetailService.createProductdetail(productdetail);
productdetailService.commit();
}
and in the component B, I call the function via
var productdetail:Productdetail = new Productdetail();
productDetailComp.createProductDetailItem(productdetail);
but, why the following error pop up while invoking the createProductDetailItem() function? Need to create a instance for the function or the component productDetailComp??
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at productDetailComp/onEdit()[C:\Users\School\Adobe Flash Builder 4.6\FYPadminSideV3\src\productDetailComp.mxml:80]
at productDetailComp/__button2_click()[C:\Users\School\Adobe Flash Builder 4.6\FYPadminSideV3\src\productDetailComp.mxml:250]

Related

Calling CreateScope() or BeginScope() Manually inside azure function

I am writing an eventhub triggered azure function that receives a list of objects in each event from eventhub. I want to instantiate an object of some type for each object of the list that I receive. If I register that type as scoped by calling builder.Services.AddScoped I will have new instance for each eventhub event(for each function call). I want to control the instance creation. SO I want to have something like bellow inside my function.
using (var scope = builder.Services.BuildServiceProvider().CreateScope())
{
// scope.ServiceProvider.GetService(type)
}
In that way for each object in the list inside each event hub event I can have new Instance of some type.
I found a solution of my problem. Inside Configure method of Startup we can register ServiceProvider like bellow
builder.Services.AddScoped<IEventContext, EventContext>();
builder.Services.AddSingleton<ServiceProvider>(builder.Services.BuildServiceProvider());
Then we can set ServiceProvider as a dependency in the function app class and we can call CreateScope() directly like bellow inside function
using (var scope = this._serviceProvider.CreateScope())
{
var ctx = scope.ServiceProvider.GetService<IEventContext>();
var ctx2 = scope.ServiceProvider.GetService<IEventContext>();
this._logger.LogInformation(ctx.GetHashCode().ToString()); //same
this._logger.LogInformation(ctx2.GetHashCode().ToString()); //same
}

Displayalert and userdialoges not showing in UI (Viewmodel)

In my viewmdodel class, I am calling a function from constructor. Inside of that function I am using Userdialoges and displayalert properties. But both are not showing in UI. Getting exception for both.
Displayalert Exception :
Exception:>System.NullReferenceException: Object reference not set to
an instance of an object.
UserDialogs Exception :
Exception:>System.ArgumentException: In android, you must call
UserDialogs.Init(Activity) from your first activity OR
UserDialogs.Init(App) from your custom application OR provide a
factory function to get the current top activity via
UserDialogs.Init(() => supply top activity)
I have also implemented the pull down to refresh option. When pull down I am calling the same function, but that call is not from the constructor. So when pull down UserDialoges and Displayalert are working.
My code:
UserDialogs.Instance.ShowLoading("Loading");
await Application.Current.MainPage.DisplayAlert("Alert", "No Internet Connection", "Ok");
So how can I activate the userdialoges and displayalert initially when calling the function from constructor?
Solved by comment the function call in constructor and inside of onappearing(), call the same function using the viewmodel class object(added in xaml.cs file not in viewmodel).
protected override async void OnAppearing()
{
dbvm.UserList(); //dbvm is viewmodel class object
}

Removing dynamically created component causes error

I have problem with casting custom event currentTarget to component. When I'm trying to removeElement from its parent container i get error. What's the deal?
TypeError: Error #1034: Type Coercion failed: cannot convert mx.events::FlexEvent#8811c41 to com.modultek.pis.itemmachine.search.events.SortEvent.
private function sortSelection_removeHandler(event:SortEvent):void
{
var sortSelection:SortSelection = event.currentTarget as SortSelection;
this.removeElement(sortSelection);
}
Component will be removed but I get this error.
your problem is not in the var sortSelection:SortSelection = event.currentTarget as SortSelection; line at all.
Read the Error message carefully. It tells you that there is an invalid cast from FlexEvent to SortEvent, which happens on
private function sortSelection_removeHandler(event:SortEvent):void
Change event:SortEvent in the function signature to event:FlexEvent or event:Event
Problem was that I didn't have event declaration on my dispatching class.
[Event(name="remove" , type=".....search.events.SortEvent")]

Error During Print

There are a three public variable
public var objPrintJob:FlexPrintJob;
public var objPrintTemplate:canvas;
Fn1:
objPrintJob = new FlexPrintJob();
if (objPrintJob.start() != true)
{
printCount--;
return;
}
Starting the PrintJob;
Fn2:
Am adding the Object and calling send for the Print
objPrintJob.addObject(objPrintTemplate, FlexPrintJobScaleType.SHOW_ALL);
objPrintJob.send();
During Run
It Throws the Error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at mx.printing::FlexPrintJob/addObject()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\printing\FlexPrintJob.as:252]
at org.dckap.mafcote.views.mediators::WorkAreaMediator/parseXML()[F:\MafcoteMGP\MafcoteMGP\src\org\dckap\mafcote\views\mediators\WorkAreaMediator.as:3243]
at org.dckap.mafcote.views.mediators::WorkAreaMediator/onSaveTemplateWithCredits()[F:\MafcoteMGP\MafcoteMGP\src\org\dckap\mafcote\views\mediators\WorkAreaMediator.as:2896]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UIComponent.as:12266]
at org.dckap.mafcote.views::CreditsShowPanel/okButtonClickHandler()[F:\MafcoteMGP\MafcoteMGP\src\org\dckap\mafcote\views\CreditsShowPanel.mxml:41]
at org.dckap.mafcote.views::CreditsShowPanel/__btnOk_click()[F:\MafcoteMGP\MafcoteMGP\src\org\dckap\mafcote\views\CreditsShowPanel.mxml:159]
Need Help For This..
}
This has to be that your objPrintTemplate object is null. The stack trace in your error shows that it's erroring in FlexPrintJob/addObject(), which means it made it into that method but did not complete executing the method. Since the only parameters you're sending to it are your object reference and a constant value, the object must be null.
After your support I found out my solution.
Thank U all.
The object does not seems to be null.
I did one mistake that is i didn't added the object as a child anywhere else.
so the addObject() in print requires the systemManager.
which will be null if i didn't add as a child.
Thank You for your support

How to assign variable as class in Flash Builder 4 Hero SDK

I am trying to assign a variable to a view navigation as follows:
protected function list_clickHandler(event:MouseEvent):void
{
var name1:String = list.selectedItem.vPage;
var name2:Object = list.selectedItem.vPage.valueOf();
navigator.pushView(list.selectedItem.vPage.valueOf(), list.selectedItem);
}
The variable is supposed to be the view for instance it works fine as follows:
navigator.pushView(IM, list.selectedItem);
As the View is presented as a static and not a variable. When you try to submit it as a variable in any format (String, Object) an error occurs.
Error #1034: Type Coercion failed: cannot convert "IM" to Class.
So if anyone has any ideas on how I can send the (View)Class as a variable or if this is a bug in the SDK
No, this is not a bug in the SDK. You pass in a class, and the viewNavigator will construct it for you. If you want to get the the Class of an instance of an object, you can do it like this:
var viewClass = Class(getDefinitionByName(getQualifiedClassName(IM)));
Then, you can pass viewClass into pushView() where it will create a NEW view for you.

Resources