- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试使用 Xamarin 和 Visual Studio 创建一个 Android 应用程序。在使用 SetSupportActionBar 函数时突然出现一个奇怪的错误。
这是我的 XML 代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark" />
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
.
.
.
</RelativeLayout>
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#818181"
android:dividerHeight="1dp"
android:background="#E3F2FD" />
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
这是我的 C# 文件代码:
using System;
using System.Collections.Generic;
using System.Linq;
using Android.App;
using Android.OS;
using Android.Widget;
using SupportToolBar = Android.Support.V7.Widget.Toolbar;
using Android.Support.V7.App;
using Android.Support.V4.Widget;
using Android.Locations;
using System.Net;
namespace IBuy
{
[Activity(Label = "Main Screen", Theme = "@style/MyTheme")]
public class MainScreen : ActionBarActivity, ILocationListener
{
private SupportToolBar mToolbar;
private MyActionBarDrawerToggle mDrawerToggle;
private DrawerLayout mDrawerLayout;
private ListView mLeftDrawer;
private int userID, storeID, permission;
private LocationManager locationManager;
private string deviceID = Build.Serial;
private double currentX = 0, currentY = 0;
private bool sent = false;
private ProgressBar pBar;
private TextView txt;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.MainScreen);
Title = GetString(Resource.String.main_screen);
try
{
mToolbar = FindViewById<SupportToolBar>(Resource.Id.toolbar);
mDrawerLayout = FindViewById<DrawerLayout>(Resource.Id.drawer_layout);
mLeftDrawer = FindViewById<ListView>(Resource.Id.left_drawer);
SetSupportActionBar(mToolbar);
}
catch (Exception ex)
{
Console.WriteLine("@@@@@@@@@@@@@@@@@@@");
Console.WriteLine(ex.Message);
Console.WriteLine(ex.InnerException);
Console.WriteLine(ex.Data);
Console.WriteLine(ex.Source);
Console.WriteLine(ex.StackTrace);
Console.WriteLine(ex.ToString());
Console.WriteLine("#################");
}
mDrawerToggle = new MyActionBarDrawerToggle(this, mDrawerLayout, Resource.String.openDrawer, Resource.String.closeDrawer);
mDrawerLayout.SetDrawerListener(mDrawerToggle);
SupportActionBar.SetHomeButtonEnabled(true);
SupportActionBar.SetDisplayShowTitleEnabled(true);
mDrawerToggle.SyncState();
.
.
.
}
}
}
奇怪的是应用程序在执行此命令时崩溃:SetSupportActionBar(mToolbar);
这是我得到的异常:
Exception of type 'Java.Lang.IllegalStateException' was thrown.
09-26 12:09:03.399 I/mono-stdout(13640): Exception of type 'Java.Lang.IllegalStateException' was thrown.
System.Collections.Generic.Dictionary`2[System.Object,System.Object]
09-26 12:09:05.849 I/mono-stdout(13640): System.Collections.Generic.Dictionary`2[System.Object,System.Object]
mscorlib
09-26 12:09:07.468 I/mono-stdout(13640): mscorlib
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in /Users/builder/data/lanes/1978/f98871a9/source/mono/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:61
09-26 12:09:09.037 I/mono-stdout(13640): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in /Users/builder/data/lanes/1978/f98871a9/source/mono/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:61
09-26 12:09:09.038 I/mono-stdout(13640): at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (IntPtr jobject, IntPtr jclass, IntPtr jmethod, Android.Runtime.JValue* parms) [0x00084] in /Users/builder/data/lanes/1978/f98871a9/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:1029
at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (IntPtr jobject, IntPtr jclass, IntPtr jmethod, Android.Runtime.JValue* parms) [0x00084] in /Users/builder/data/lanes/1978/f98871a9/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:1029
at Android.Support.V7.App.AppCompatActivity.SetSupportActionBar (Android.Support.V7.Widget.Toolbar toolbar) [0x00091] in <filename unknown>:0
at IBuy.MainScreen.OnCreate (Android.OS.Bundle bundle) [0x0005b] in C:\Users\איציק\Source\Workspaces\iBuy\IBuy\IBuy\Screens\MainScreen.cs:42
--- End of managed exception stack trace ---
java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
at android.support.v7.app.AppCompatDelegateImplV7.setSupportActionBar(AppCompatDelegateImplV7.java:193)
at android.support.v7.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:96)
at md5f6ea2975de2355cb6a
09-26 12:09:09.038 I/mono-stdout(13640): at Android.Support.V7.App.AppCompatActivity.SetSupportActionBar (Android.Support.V7.Widget.Toolbar toolbar) [0x00091] in <filename unknown>:0
09-26 12:09:09.038 I/mono-stdout(13640): at IBuy.MainScreen.OnCreate (Android.OS.Bundle bundle) [0x0005b] in C:\Users\איציק\Source\Workspaces\iBuy\IBuy\IBuy\Screens\MainScreen.cs:42
574b5b4ea31e7d.MainScreen.n_onCreate(Native Method)
at md5f6ea2975de2355cb6a574b5b4ea31e7d.MainScreen.onCreate(MainScreen.java:36)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2309)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2418)
at android.app.ActivityThread.access$900(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5289)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
09-26 12:09:09.038 I/mono-stdout(13640): --- End of managed exception stack trace ---
09-26 12:09:09.038 I/mono-stdout(13640): java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
09-26 12:09:09.039 I/mono-stdout(13640): at android.support.v7.app.AppCompatDelegateImplV7.setSupportActionBar(AppCompatDelegateImplV7.java:193)
09-26 12:09:09.039 I/mono-stdout(13640): at android.support.v7.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:96)
09-26 12:09:09.039 I/mono-stdout(13640): at md5f6ea2975de2355cb6a574b5b4ea31e7d.MainScreen.n_onCreate(Native Method)
09-26 12:09:09.039 I/mono-stdout(13640): at md5f6ea2975de2355cb6a574b5b4ea31e7d.MainScreen.onCreate(MainScreen.java:36)
09-26 12:09:09.040 I/mono-stdout(13640): at android.app.Activity.performCreate(Activity.java:5990)
09-26 12:09:09.040 I/mono-stdout(13640): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
09-26 12:09:09.040 I/mono-stdout(13640): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2309)
09-26 12:09:09.041 I/mono-stdout(13640): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2418)
09-26 12:09:09.041 I/mono-stdout(13640): at android.app.ActivityThread.access$900(ActivityThread.java:154)
09-26 12:09:09.042 I/mono-stdout(13640): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
09-26 12:09:09.042 I/mono-stdout(13640): at android.os.Handler.dispatchMessage(Handler.java:102)
09-26 12:09:09.042 I/mono-stdout(13640): at android.os.Looper.loop(Looper.java:135)
09-26 12:09:09.042 I/mono-stdout(13640): at android.app.ActivityThread.main(ActivityThread.java:5289)
09-26 12:09:09.042 I/mono-stdout(13640): at java.lang.reflect.Method.invoke(Native Method)
09-26 12:09:09.042 I/mono-stdout(13640): at java.lang.reflect.Method.invoke(Method.java:372)
09-26 12:09:09.042 I/mono-stdout(13640): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
09-26 12:09:09.042 I/mono-stdout(13640): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
09-26 12:09:10.509 I/mono-stdout(13640): Java.Lang.IllegalStateException: Exception of type 'Java.Lang.IllegalStateException' was thrown.
Java.Lang.IllegalStateException: Exception of type 'Java.Lang.IllegalStateException' was thrown.
09-26 12:09:10.515 I/mono-stdout(13640): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in /Users/builder/data/lanes/1978/f98871a9/source/mono/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:61
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in /Users/builder/data/lanes/1978/f98871a9/source/mono/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:61
09-26 12:09:10.517 I/mono-stdout(13640): at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (IntPtr jobject, IntPtr jclass, IntPtr jmethod, Android.Runtime.JValue* parms) [0x00084] in /Users/builder/data/lanes/1978/f98871a9/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:1029
at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (IntPtr jobject, IntPtr jclass, IntPtr jmethod, Android.Runtime.JValue* parms) [0x00084] in /Users/builder/data/lanes/1978/f98871a9/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:1029
at Android.Support.V7.App.AppCompatActivity.SetSupportActionBar (Android.Support.V7.Widget.Toolbar toolbar) [0x00091] in <filename unknown>:0
09-26 12:09:10.518 I/mono-stdout(13640): at Android.Support.V7.App.AppCompatActivity.SetSupportActionBar (Android.Support.V7.Widget.Toolbar toolbar) [0x00091] in <filename unknown>:0
at IBuy.MainScreen.OnCreate (Android.OS.Bundle bundle) [0x0005b] in C:\Users\איציק\Source\Workspaces\iBuy\IBuy\IBuy\Screens\MainScreen.cs:42
--- End of managed exception stack trace ---
09-26 12:09:10.520 I/mono-stdout(13640): at IBuy.MainScreen.OnCreate (Android.OS.Bundle bundle) [0x0005b] in C:\Users\איציק\Source\Workspaces\iBuy\IBuy\IBuy\Screens\MainScreen.cs:42
java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
at android.support.v7.app.AppCompatDelegateImplV7.setSupportActionBar(AppCompatDelegateImplV7.java:193)
at android.support.v7.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:96)
at md5f6ea2975de2355cb6a574b5b4ea31e7d.MainScreen.n_onCreate(Native Method)
at md5f6ea2975de2355cb6a574b5b4ea31e7d.MainScreen.onCreate(MainScreen.java:36)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2309)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2418)
09-26 12:09:10.520 I/mono-stdout(13640): --- End of managed exception stack trace ---
at android.app.ActivityThread.access$900(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
09-26 12:09:10.523 I/mono-stdout(13640): java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
at android.app.ActivityThread.main(ActivityThread.java:5289)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
09-26 12:09:10.523 I/mono-stdout(13640): at android.support.v7.app.AppCompatDelegateImplV7.setSupportActionBar(AppCompatDelegateImplV7.java:193)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
09-26 12:09:10.524 I/mono-stdout(13640): at android.support.v7.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:96)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
09-26 12:09:10.529 I/mono-stdout(13640): at md5f6ea2975de2355cb6a574b5b4ea31e7d.MainScreen.n_onCreate(Native Method)
09-26 12:09:10.529 I/mono-stdout(13640): at md5f6ea2975de2355cb6a574b5b4ea31e7d.MainScreen.onCreate(MainScreen.java:36)
09-26 12:09:10.530 I/mono-stdout(13640): at android.app.Activity.performCreate(Activity.java:5990)
09-26 12:09:10.531 I/mono-stdout(13640): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
09-26 12:09:10.532 I/mono-stdout(13640): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2309)
09-26 12:09:10.534 I/mono-stdout(13640): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2418)
09-26 12:09:10.535 I/mono-stdout(13640): at android.app.ActivityThread.access$900(ActivityThread.java:154)
09-26 12:09:10.536 I/mono-stdout(13640): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
09-26 12:09:10.537 I/mono-stdout(13640): at android.os.Handler.dispatchMessage(Handler.java:102)
09-26 12:09:10.539 I/mono-stdout(13640): at android.os.Looper.loop(Looper.java:135)
09-26 12:09:10.543 I/mono-stdout(13640): at java.lang.reflect.Method.invoke(Native Method)
09-26 12:09:10.544 I/mono-stdout(13640): at java.lang.reflect.Method.invoke(Method.java:372)
09-26 12:09:10.546 I/mono-stdout(13640): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
09-26 12:09:10.547 I/mono-stdout(13640): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
它之前运行良好,我不记得有任何可能导致它崩溃的更改。
谁能告诉我该怎么做?
提前致谢!
最佳答案
看起来您的主题没有正确配置。
要么在你的主题中使用(参见 related answer )
<item name="windowActionBar">false</item>
或从没有操作栏的主题派生(参见 related answer ),例如:
Theme.AppCompat.Light.NoActionBar
关于c# - SetSupportActionBar 在 Visual Studio 和 Xamarin 中崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32795028/
我经常使用 SSMS 查询数据和构建数据集,我的 IT 部门负责数据库管理。 最近我发现了 Azure Data Studio,我喜欢: 智能感知 源代码控制(例如使用 Git) 来自社区的扩展 SQ
我想根据我使用的 visual studio 版本编译不同的东西,比如 #if VISUAL_STUDIO_VERSION > 2015 eventH?.Invoke(this, EventArgs.
我们的开发团队计划从 visual studio 2005 升级到 visual studio 2010 -- 跳过 visual studio 2008。 大部分项目是VB ASP.NET项目,使用
我的Visual Studio 2015无法构建2010平台工具集。它说: The build tools for Visual Studio 2010 (v100) cannot be found.
我目前正在使用 Visual Studio 2015 来编程 ASP.NET Core 应用程序。我对安装 Visual Studio 2017 有以下疑问: 什么被认为是最佳实践和/或最干净的方法?
尝试从扩展和更新获取 Visual Studio 扩展时,出现以下错误:- 向 visualstudiogallery.msdn.microsoft.com/Services/VStudio/Exte
这个问题在这里已经有了答案: Can Visual Studio Code and VS 2012 be installed on same computer? (1 个回答) 关闭去年。 在安装了
作为标准安装的一部分,Visual Studio Code 带有一个名为“Monokai Dimmed”的颜色主题。 有没有办法将它移植到 Visual Studio 2015?我检查了社区主题( h
我想开始编程 CUDA。 我已经安装了 Visual Studio 2010 Express。 我还安装了 nVidia nSight Visual Studio。 而且我具备所有常见的先决条件(Ne
Visual Studio Community Edition是否可以使用Visual Studio Online帐户上的存储库? 我一直为包含在Online帐户中的Visual Studio Onl
我有一个我一直在开发的应用程序,但在 android studio 上遇到了问题。当我点击“build->run”然后选择我的设备时,应用程序永远不会在我的手机上运行(并且自动出现的android-s
我正在使用Visual Studio2010。我面临的一个问题是,当我创建一个新的Web项目时,Visual Studio将创建该项目,并且不会在解决方案资源管理器中显示其解决方案。 另一件事是,我想
我通读了这里的许多帖子,却找不到一个有效的明确答案。因此,在花了一些时间使它生效之后,我认为应该发布它。 问题:发布配置文件将建立在服务器上,但不会发布。 解: 确保已安装Microsoft Wind
我正在尝试使用Visual Studio 2012构建针对.NET 3.5的C++ CLI应用程序。 通过安装Visual Studio 2008,并指定v90平台工具集,我已经在一台机器上进行了这项
我在 Microsoft Visual Studios 2013 中有一个项目,我想在 Microsoft Visual Studios 2010 中打开它。有什么简单的方法吗?还是我必须在2010年
我想知道,如果我发送一个解决方案文件夹(它是用 visual studio C# 编写的),您可以在 visual studio for mac 中打开解决方案吗? 在visual studio 20
有没有办法在 Visual Studio Code 和 Visual Studio 中设置相同的快捷方式(而不必每次都手动更改它们)? 例如,我在 Visual Studio Code 中经常使用 A
我刚开始了解 Visual Studio Code。我想知道,我可以将 Visual Studio 替换为所有 .NET 开发相关的工作吗? 我可以节省 Visual Studio 许可的成本吗? V
我安装了具有有效许可证(Visual Studio 订阅)的 Visual Studio 2019 企业版(VS 2019 16.1.4),它运行良好。 突然之间,当我尝试打开项目或项目中的任何文件时
我一直在使用 Compass 编译 Windows 环境中的 sass 文件,无论是在命令行上还是使用 Compass-app 来查看目录。 我刚刚开始使用 Visual Studio(专业版 201
我是一名优秀的程序员,十分优秀!