我有一个简单的asp:menu-item
使用Web.sitemap
来获取菜单项。页面将回发但无法获取与所单击项目关联的页面。我会提到导航条码在主页文件中。
<div>
<asp:SiteMapDataSource ID="SiteMapDataSource1" ShowStartingNode="false" runat="server" />
<asp:Menu ID="Menu1" Orientation="horizontal" runat="server" BackColor="#a0a080" DataSourceID="SiteMapDataSource1"
DynamicHorizontalOffset="2" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#a00000"
StaticSubMenuIndent="10px" Style="z-index: 2; left: 390px; position: absolute;
top: 281px" Height="20px" Width="311px">
<StaticSelectedStyle BackColor="#a0a080" />
<StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<DynamicHoverStyle BackColor="#a0a080" ForeColor="White" />
<DynamicMenuStyle BackColor="#a0a080" />
<DynamicSelectedStyle BackColor="#a0a080" />
<DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<DataBindings>
<asp:MenuItemBinding DataMember="SiteMapNode" EnabledField="Title" TextField="Title" />
</DataBindings>
<StaticHoverStyle BackColor="#666666" ForeColor="White" />
</asp:Menu>
</div>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="" title="" description="">
<siteMapNode title="Home" description="Zombie (be)Warehouse" url="index.aspx" />
<siteMapNode title="Armor" description="Anti-Zombie Armor" url="Armor.aspx" />
<siteMapNode title="Weapons" description="Anti-Zombie Weapons" url="Weapons.aspx" />
<siteMapNode title="Manuals" description="Survival Manuals" url="Manuals.aspx" />
<siteMapNode title="Sustenance" description="Prepared food for survival" url="Sustenance.aspx" />
<siteMapNode title="Contacts" description="Contact Us" url="Contacts.aspx" />
<siteMapNode title="About" description="About Zombie (be)Warehouse" url="About.aspx" />
</siteMapNode>
</siteMap>
更新
问题出现在菜单项的DataBindings
部分。注意这一行:
<asp:MenuItemBinding DataMember="SiteMapNode" EnabledField="Title" Text="Title" />
Text="Title"
从Web.sitemap
的文本字段设置菜单显示的文本。我注意到MenuItemBinding
项目有一个名为NavigateUrlField
的字段。
因此,要解决此问题,您只需更改/添加到asp:MenuItemBinding
<asp:MenuItemBinding DataMember="SiteMapNode" NavigateUrlField="url" EnabledField="Title" TextField="Title" />
答案 0 :(得分:0)
您需要像这样E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.app.myapp, PID: 15400
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
at com.example.app.myapp.fragments.myFragment.setInfo(myFragment.java:53)
at com.example.app.myapp.MainActivity.onOptionsItemSelected(MainActivity.java:195)
at android.app.Activity.onMenuItemSelected(Activity.java:3543)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:407)
at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:195)
at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:108)
at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:108)
at android.support.v7.app.ToolbarActionBar$2.onMenuItemClick(ToolbarActionBar.java:63)
at android.support.v7.widget.Toolbar$1.onMenuItemClick(Toolbar.java:203)
at android.support.v7.widget.ActionMenuView$MenuBuilderCallback.onMenuItemSelected(ActionMenuView.java:780)
at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:822)
at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:171)
at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:973)
at android.support.v7.view.menu.MenuPopup.onItemClick(MenuPopup.java:127)
at android.widget.AdapterView.performItemClick(AdapterView.java:318)
at android.widget.AbsListView.performItemClick(AbsListView.java:1159)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3136)
at android.widget.AbsListView$3.run(AbsListView.java:4052)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
那样将NavigateUrlField
字段添加到MenuItemBinding