"Element was referenced before it was initialized" scope issue

Hi!

I’m having trouble understanding the scope in which InnerClass and Class are supposed to work. Would you kindly explain why the following code…

<SmallBlock>
    <Text Value="Tema" Alignment="CenterLeft"/>
    <Panel Alignment="CenterRight">

        <Circle ux:Class="ColorCircle" Width="38" Height="38" isActive="false" ux:Name="_thisColorCircle" Margin="12,0,0,0" themeState="Color1">
            <bool ux:Property="isActive" />
            <string ux:Property="themeState" />

            <WhileTrue Value="{Property _thisColorCircle.isActive}">
                <Circle Color="{Property _thisColorCircle.Color}">
                    <Stroke Width="3" Color="#FFF" />
                    <DropShadow Angle="0" Spread="0.1" Distance="0" Size="4" Color="#0004" />
                </Circle>
            </WhileTrue>

            <WhileFalse Value="{Property _thisColorCircle.isActive}">
                <Circle Color="{Property _thisColorCircle.Color}"/>
                <Change Target="_thisColorCircle.Opacity" Value="0.5" Duration="0.5" />
            </WhileFalse>

            <Clicked>
                <Set Target="stTheme.Active" Value="{Property _thisColorCircle.themeState}" />
            </Clicked>
        </Circle>

        <StackLayout Orientation="Horizontal" />
        <ColorCircle Color="{Resource oceano00}" ux:Name="btColor1" themeState="Color1"/>
        <ColorCircle Color="{Resource dourado00}" ux:Name="btColor2" themeState="Color2"/>
        <ColorCircle Color="{Resource vermelho00}" ux:Name="btColor3" themeState="Color3"/>
        <ColorCircle Color="{Resource roxo00}" ux:Name="btColor4" themeState="Color4"/>

        <StateGroup ux:Name="stTheme" Active="Color1">
            <State ux:Name="Color1">
                <Change Target="btColor1.isActive" Value="true" />
            </State>
            <State ux:Name="Color2">
                <Change Target="btColor2.isActive" Value="true" />
            </State>
            <State ux:Name="Color3">
                <Change Target="btColor3.isActive" Value="true" />
            </State>
            <State ux:Name="Color4">
                <Change Target="btColor4.isActive" Value="true" />
            </State>
        </StateGroup>

    </Panel>
</SmallBlock>

… gives me this error: TabConfiguracoes.ux(81): E8001: 'stTheme' declared in TabConfiguracoes.ux(91) is a member 'MainView' and cannot be accessed from 'ColorCircle'. To make this work, consider making 'ColorCircle' an ux:InnerClass of 'MainView'. TowardDemo: E0000: Object reference not set to an instance of an object. And when I follow its instructions (moving the block of code to MainView.ux and turning it into an ux:InnerClass) Preview gives me a new error?:

Element 'new_MainView.ColorCircle' was referenced before it was initialized

How should I solve this and why is stTheme not within ColorCircle's reach? They are declared together inside the same Panel.

Hi!

ux:Class creates a completely independent class, that cannot reach anything outside itself. The fact that you declared it inside the panel doesn’t matter. You can move it to a separate file if you want.

However, ux:InnerClass is different. It cares about where it is declared, and can access symbols from that scope. To return the favor, you can only use it in that scope.

As the error message says, you need to change it to ux:InnerClass in order for it to reach symbols in the context it is declared.

To fix your problem, simply change ux:Class="ColorCircle" to ux:InnerClass="ColorCircle"

Hi Anders,

If I do that, the compiler throws me this error:

...\build\Local\Preview14\cache\MainView.g.uno(2328.26): E2009: Call to 'Fuse.Controls.PropertyBinding<Fuse.Triggers.State>(Uno.UX.Property<Fuse.Triggers.State>,Uno.UX.Property<Fuse.Triggers.State>)' has some invalid arguments (TowardDemo_FuseTriggersActionsSet1_FuseTriggersState_Value_Property,TowardDemo_ColorCircle_string_themeState_Property)

I’m not exactly sure what this means but I don’t see anything wrong with my themeState property.

The source and destination data types in a property binding must be identical.

Change:

<string ux:Property="themeState" />

To:

<State ux:Property="themeState" />

Ok, that cleared the .g.uno error, but I still have issues. Preview says:

Element 'new_MainView.ColorCircle' was referenced before it was initialized

Here’s the error from Monitor:

ERROR: Element'new_MainView.ColorCircle' was referenced before it was initialized
    Outracks.Simulator.Runtime.VariableNotBound occured.
       at Outracks.Simulator.Runtime.Environment.GetValue(Variable variable) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno:line 42
       at Outracks.Simulator.Runtime.Environment.GetValue(Variable variable) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno:line 40
       at Outracks.Simulator.Runtime.Environment.GetValue(Variable variable) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno:line 40
       at Outracks.Simulator.Runtime.Environment.GetValue(Variable variable) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno:line 40
       at Outracks.Simulator.Runtime.ScopeClosure.Evaluate(ReadVariable e) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 136
       at Outracks.Simulator.Bytecode.Expression.Match<a href="Func`2 a1, Func`2 a2, Func`2 a3, Func`2 a4, Func`2 a5, Func`2 a6, Func`2 a7, Func`2 a8, Func`2 a9, Func`2 a10, Func`2 a11, Func`2 a12, Func`2 a13, Func`2 a15, Func`2 a16">T</a> in C:\ProgramData\Uno\Packages\Outracks.Simulator.Protocol.Uno\0.0.0\Bytecode\$.uno#1:line 99
       at Outracks.Simulator.Runtime.ScopeClosure.Evaluate(Expression expression) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 131
       at Outracks.Simulator.Runtime.ScopeClosure.Evaluate(CallLambda i) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 163
       at Outracks.Simulator.Bytecode.Expression.Match<a href="Func`2 a1, Func`2 a2, Func`2 a3, Func`2 a4, Func`2 a5, Func`2 a6, Func`2 a7, Func`2 a8, Func`2 a9, Func`2 a10, Func`2 a11, Func`2 a12, Func`2 a13, Func`2 a15, Func`2 a16">T</a> in C:\ProgramData\Uno\Packages\Outracks.Simulator.Protocol.Uno\0.0.0\Bytecode\$.uno#1:line 106
       at Outracks.Simulator.Runtime.ScopeClosure.Evaluate(Expression expression) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 131
       at Outracks.Simulator.Runtime.ScopeClosure.Execute(Lambda lambda, Object[] arguments) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 105
       at Outracks.Simulator.Runtime.LambdaClosure.Func(Object a1) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 341
       at Outracks.Simulator.Runtime.ScopeClosure.Execute(Object lambda, Object[] arguments) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 221
       at Outracks.Simulator.Runtime.ScopeClosure.Evaluate(CallLambda i) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 163
       at Outracks.Simulator.Bytecode.Expression.Match<a href="Func`2 a1, Func`2 a2, Func`2 a3, Func`2 a4, Func`2 a5, Func`2 a6, Func`2 a7, Func`2 a8, Func`2 a9, Func`2 a10, Func`2 a11, Func`2 a12, Func`2 a13, Func`2 a15, Func`2 a16">T</a> in C:\ProgramData\Uno\Packages\Outracks.Simulator.Protocol.Uno\0.0.0\Bytecode\$.uno#1:line 106
       at Outracks.Simulator.Runtime.ScopeClosure.Evaluate(Expression expression) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 131
       at Outracks.Simulator.Runtime.ScopeClosure.Execute(IEnumerable<code>1 statements) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 117
       at Outracks.Simulator.Runtime.ScopeClosure.Execute(Lambda lambda, Object[] arguments) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 107
       at Outracks.Simulator.Runtime.LambdaClosure.Func(Object a1) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 341
       at Outracks.Simulator.Runtime.LambdaClosure.Action(Object a1) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 321
       at Outracks.Simulator.Runtime.ScopeClosure.Execute(Object lambda, Object[] arguments) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 231
       at Outracks.Simulator.Runtime.ScopeClosure.Evaluate(CallLambda i) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 163
       at Outracks.Simulator.Bytecode.Expression.Match<a href="Func&lt;/code&gt;2 a1, Func&lt;code&gt;2 a2, Func&lt;/code&gt;2 a3, Func&lt;code&gt;2 a4, Func&lt;/code&gt;2 a5, Func&lt;code&gt;2 a6, Func&lt;/code&gt;2 a7, Func&lt;code&gt;2 a8, Func&lt;/code&gt;2 a9, Func&lt;code&gt;2 a10, Func&lt;/code&gt;2 a11, Func&lt;code&gt;2 a12, Func&lt;/code&gt;2 a13, Func&lt;code&gt;2 a15, Func&lt;/code&gt;2 a16">T</a> in C:\ProgramData\Uno\Packages\Outracks.Simulator.Protocol.Uno\0.0.0\Bytecode\$.uno#1:line 106
       at Outracks.Simulator.Runtime.ScopeClosure.Evaluate(Expression expression) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 131
       at Outracks.Simulator.Runtime.ScopeClosure.Execute(IEnumerable`1 statements) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 117
       at Outracks.Simulator.Runtime.ScopeClosure.Execute(Lambda lambda, Object[] arguments) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 107
       at Outracks.Simulator.Runtime.VirtualMachine.Execute(IReflection reflection, Lambda lambda, Object[] arguments) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 78
       at Outracks.Simulator.Runtime.VirtualMachine.Execute(Lambda lambda, Object[] arguments) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\Runtime\$.uno#1:line 73
       at Outracks.Simulator.Reifying.OnEnterState() in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\$.uno#1:line 420
       at Outracks.Simulator.Application.SetState(State nextState) in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\$.uno:line 136
       at Outracks.Simulator.Application.OnUpdate() in C:\ProgramData\Uno\Packages\Outracks.Simulator.Client.Uno\0.1.0\$.uno:line 126
       at Fuse.App.Update() in C:\ProgramData\Uno\Packages\Fuse.Desktop\0.26.10\$.uno:line 48

Here’s the full code for this Page: [http://pastebin.com/qQsW2xMB]

Hi!

Looks like you’ve hit a bug in Fuse. Can you provide a full test project please?

You can upload here: https://www.dropbox.com/request/ZgndLtJQm5eGzG9cicGK

Hi Anders, I’ve uploaded a case to the Dropbox link, named “InnerClassError_86fernandolins.zip” (86fernandolins is my Slack nickname).

There are two things you should try:

  1. Run the Preview as it is so you will get this error:
InnerClassError\FirstTab.ux(26): E8001: 'stTheme' declared in FirstTab.ux(36) is a member 'MainView' and cannot be accessed from 'ColorCircle'. To make this work, consider making 'ColorCircle' an ux:InnerClass of 'MainView'.
InnerClassError: E0000: Object reference not set to an instance of an object.

  1. On line 9 of “FirstTab.ux” file, change <Circle ux:Class="ColorCircle" ... to <Circle ux:InnerClass="ColorCircle" ... so you will get this error:
Element 'new_MainView.ColorCircle' was referenced before it was initialized

Same error will show up if you move the whole ColorCircle declaration to MainView.ux and declare it as an ux:Class.

Just tried the code on 0.12 and the same issues as above happen ^

Hi,

I recently update my Fuse version, and now I have this issue when running the app:

“Element ‘pagActividad’ was referenced before it was initialized”

I didn’t have this problem before updating, and the order of pages is important, because it shows movement. Any suggestions?, please.

<PageControl ux:Name="actPage" Active="pagRamas" Interaction="None">
    ...
    <Page ux:Name="pagCalendario">
        <ux:Include File="Calendar.ux" />
        <Calendar/>

        <WhileInactive>
            <Change pagCalendario.IsEnabled="false"/>
            <Change pagCalendario.Visibility="Hidden"/>
        </WhileInactive>

        <WhileActive>
            <Change pagCalendario.IsEnabled="true"/>
            <Change pagCalendario.Visibility="Visible"/>
        </WhileActive>
    </Page>

    <Page ux:Name="pagActividad">
        <DockPanel>
        ...
       </DockPanel>
    </Page>
</PageControl>

<Panel ux:InnerClass="Calendar">
    ...
  <DockPanel Padding="0,2" Margin="0,10" IsEnabled="{valido}">
      <StackPanel>
          <Circle Color="{color}">
              <Text Value="{dia}" Padding="3" TextAlignment="Center" TextColor="{textColor}"/>
          </Circle>

          <Clicked>
              <Callback Handler="{setDay}" />
              <Set Target="actPage.Active" Value="pagActividad" />
          </Clicked>
      </StackPanel>
  </DockPanel>
</Panel>

Hello.

Has this been fixed? I´m still getting the error. Could be me tho…

Hi,

We haven’t seen this issue. If this is still a problem in the latest version, can you please provide a complete test project that reproduces the issue? Thanks.

Hello.

I sent a small example through Fuse´s dropbox. Not sure what’s going on.

If anyone is having trouble with such error I recommend following the new thread -> https://www.fusetools.com/community/forums/howto_discussions/uxproperty_inside_innerclass

And Fuselibs issue -> https://github.com/fusetools/fuselibs-public/issues/481