- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在开发 Xamarin.Forms 应用。它运行良好,但当用户在打开其他几个应用程序后将其从后台恢复时,它会继续崩溃。我是 Xamarin 的新手,我不确定如何调试此问题。到目前为止,此问题未在 iOS 上发生。
飞溅 Activity .cs:
using System.Threading.Tasks;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Support.V7.App;
using Android.Util;
namespace MyApp.Droid
{
[Activity(Theme = "@style/MyTheme.Splash", MainLauncher = true, NoHistory = true)]
public class SplashActivity : AppCompatActivity
{
static readonly string TAG = "X:" + typeof(SplashActivity).Name;
protected override void OnCreate(Bundle savedInstanceState) // PersistableBundle persistentState
{
base.OnCreate(savedInstanceState); // persistentState
Log.Debug(TAG, "SplashActivity.OnCreate");
}
protected override void OnResume()
{
base.OnResume();
Task startupWork = new Task(() =>
{
Log.Debug(TAG, "Performing some startup work that takes a bit of time.");
Task.Delay(5000); // Simulate a bit of startup work.
Log.Debug(TAG, "Working in the background - important stuff.");
});
startupWork.ContinueWith(t =>
{
Log.Debug(TAG, "Work is finished - start Activity1.");
StartActivity(new Intent(Application.Context, typeof(MainActivity)));
}, TaskScheduler.FromCurrentSynchronizationContext());
startupWork.Start();
}
}
}
主 Activity .cs:
using System;
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using HockeyApp.Android;
using HockeyApp.Android.Metrics;
using Xamarin.Android.Net; // Keep to make TLS 1.2 work
namespace MyApp.Droid
{
[Activity(Label = "EventingVolunteers.Droid", Icon = "@drawable/icon", Theme = "@style/MyTheme", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App());
// HockeyApp
CrashManager.Register(this, Constants.HockeyAppID_Android);
MetricsManager.Register(this, Application, Constants.HockeyAppID_Android);
// Push Notifications
RegisterForGCM();
}
private void RegisterForGCM()
{
string senders = Constants.GoogleConsoleProjectId;
Intent intent = new Intent("com.google.android.c2dm.intent.REGISTER");
intent.SetPackage("com.google.android.gsf");
intent.PutExtra("app", PendingIntent.GetBroadcast(this, 0, new Intent(), 0));
intent.PutExtra("sender", senders);
StartService(intent);
}
protected override void OnPause()
{
base.OnPause();
}
protected override void OnResume()
{
base.OnResume();
}
protected override void OnDestroy()
{
base.OnDestroy();
}
}
}
错误信息:
java.lang.IllegalStateException: Fragment does not have a view
android.support.v4.app.Fragment$1.onFindViewById()Fragment.java:1933
android.support.v4.app.FragmentManagerImpl.moveToState()FragmentManager.java:1057
android.support.v4.app.FragmentManagerImpl.moveToState()FragmentManager.java:1252
android.support.v4.app.FragmentManagerImpl.moveToState()FragmentManager.java:1234
android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated()FragmentManager.java:2046
android.support.v4.app.Fragment.performActivityCreated()Fragment.java:1989
android.support.v4.app.FragmentManagerImpl.moveToState()FragmentManager.java:1092
android.support.v4.app.FragmentManagerImpl.moveToState()FragmentManager.java:1252
android.support.v4.app.FragmentManagerImpl.moveToState()FragmentManager.java:1234
android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated()FragmentManager.java:2046
android.support.v4.app.FragmentController.dispatchActivityCreated()FragmentController.java:174
android.support.v4.app.FragmentActivity.onStart()FragmentActivity.java:598
md5b60ffeb829f638581ab2bb9b1a7f4f3f.FormsAppCompatActivity.n_onStart(Native Method)
md5b60ffeb829f638581ab2bb9b1a7f4f3f.FormsAppCompatActivity.onStart()FormsAppCompatActivity.java:120
android.app.Instrumentation.callActivityOnStart()Instrumentation.java:1260
android.app.Activity.performStart()Activity.java:6261
android.app.ActivityThread.performLaunchActivity()ActivityThread.java:2389
android.app.ActivityThread.handleLaunchActivity()ActivityThread.java:2490
at android.app.ActivityThread.-wrap11(ActivityThread.java)
android.app.ActivityThread$H.handleMessage()ActivityThread.java:1354
android.os.Handler.dispatchMessage()Handler.java:102
android.os.Looper.loop()Looper.java:148
android.app.ActivityThread.main()ActivityThread.java:5456
java.lang.reflect.Method.invoke(Native Method)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run()ZygoteInit.java:728
com.android.internal.os.ZygoteInit.main()ZygoteInit.java:618
Xamarin caused by: Java.Lang.IllegalStateException: Fragment does not have a view
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualVoidMethod(JniObjectReference instance, JniObjectReference type, JniMethodInfo method, JniArgumentValue* args)
Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualVoidMethod(string encodedMember, IJavaPeerable self, JniArgumentValue* parameters)
Android.App.Activity.OnStart()
Xamarin.Forms.Platform.Android.FormsAppCompatActivity.OnStart()
Android.App.Activity.n_OnStart(IntPtr jnienv, IntPtr native__this)
at (wrapper dynamic-method) System.Object:23d8bc20-60cf-4cac-a339-6cc6722e8667 (intptr,intptr)
--- End of managed Java.Lang.IllegalStateException stack trace ---
java.lang.IllegalStateException: Fragment does not have a view
android.support.v4.app.Fragment$1.onFindViewById()Fragment.java:1933
android.support.v4.app.FragmentManagerImpl.moveToState()FragmentManager.java:1057
android.support.v4.app.FragmentManagerImpl.moveToState()FragmentManager.java:1252
android.support.v4.app.FragmentManagerImpl.moveToState()FragmentManager.java:1234
android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated()FragmentManager.java:2046
android.support.v4.app.Fragment.performActivityCreated()Fragment.java:1989
android.support.v4.app.FragmentManagerImpl.moveToState()FragmentManager.java:1092
android.support.v4.app.FragmentManagerImpl.moveToState()FragmentManager.java:1252
android.support.v4.app.FragmentManagerImpl.moveToState()FragmentManager.java:1234
android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated()FragmentManager.java:2046
android.support.v4.app.FragmentController.dispatchActivityCreated()FragmentController.java:174
android.support.v4.app.FragmentActivity.onStart()FragmentActivity.java:598
md5b60ffeb829f638581ab2bb9b1a7f4f3f.FormsAppCompatActivity.n_onStart(Native Method)
md5b60ffeb829f638581ab2bb9b1a7f4f3f.FormsAppCompatActivity.onStart()FormsAppCompatActivity.java:120
android.app.Instrumentation.callActivityOnStart()Instrumentation.java:1260
android.app.Activity.performStart()Activity.java:6261
android.app.ActivityThread.performLaunchActivity()ActivityThread.java:2389
android.app.ActivityThread.handleLaunchActivity()ActivityThread.java:2490
at android.app.ActivityThread.-wrap11(ActivityThread.java)
android.app.ActivityThread$H.handleMessage()ActivityThread.java:1354
android.os.Handler.dispatchMessage()Handler.java:102
android.os.Looper.loop()Looper.java:148
android.app.ActivityThread.main()ActivityThread.java:5456
java.lang.reflect.Method.invoke(Native Method)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run()ZygoteInit.java:728
com.android.internal.os.ZygoteInit.main()ZygoteInit.java:618
--- End of managed Java.Lang.IllegalStateException stack trace ---
java.lang.IllegalStateException: Fragment does not have a view
android.support.v4.app.Fragment$1.onFindViewById()Fragment.java:1933
android.support.v4.app.FragmentManagerImpl.moveToState()FragmentManager.java:1057
android.support.v4.app.FragmentManagerImpl.moveToState()FragmentManager.java:1252
android.support.v4.app.FragmentManagerImpl.moveToState()FragmentManager.java:1234
android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated()FragmentManager.java:2046
android.support.v4.app.Fragment.performActivityCreated()Fragment.java:1989
android.support.v4.app.FragmentManagerImpl.moveToState()FragmentManager.java:1092
android.support.v4.app.FragmentManagerImpl.moveToState()FragmentManager.java:1252
android.support.v4.app.FragmentManagerImpl.moveToState()FragmentManager.java:1234
android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated()FragmentManager.java:2046
android.support.v4.app.FragmentController.dispatchActivityCreated()FragmentController.java:174
android.support.v4.app.FragmentActivity.onStart()FragmentActivity.java:598
md5b60ffeb829f638581ab2bb9b1a7f4f3f.FormsAppCompatActivity.n_onStart(Native Method)
md5b60ffeb829f638581ab2bb9b1a7f4f3f.FormsAppCompatActivity.onStart()FormsAppCompatActivity.java:120
android.app.Instrumentation.callActivityOnStart()Instrumentation.java:1260
android.app.Activity.performStart()Activity.java:6261
android.app.ActivityThread.performLaunchActivity()ActivityThread.java:2389
android.app.ActivityThread.handleLaunchActivity()ActivityThread.java:2490
at android.app.ActivityThread.-wrap11(ActivityThread.java)
android.app.ActivityThread$H.handleMessage()ActivityThread.java:1354
android.os.Handler.dispatchMessage()Handler.java:102
android.os.Looper.loop()Looper.java:148
android.app.ActivityThread.main()ActivityThread.java:5456
java.lang.reflect.Method.invoke(Native Method)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run()ZygoteInit.java:728
com.android.internal.os.ZygoteInit.main()ZygoteInit.java:618
App.xaml.cs:
using System;
using System.Linq;
using Amazon;
using Xamarin.Forms;
namespace MyApp
{
public partial class App : Application
{
public static string AppName { get { return "MyApp"; } }
public static User User { get; set; }
public static UserManager UserManager { get; private set; }
public static VolunteerManager VolunteerManager { get; private set; }
public static SignupManager SignupManager { get; private set; }
static NavigationPage NavPage;
public static bool IsLoggedIn
{
get
{
if (User != null)
return !string.IsNullOrWhiteSpace(User.Email);
else
return false;
}
}
public static Action SuccessfulLoginAction
{
get
{
return new Action(() =>
{
NavPage.Navigation.PopModalAsync();
if (IsLoggedIn)
{
// Update RestService with new token
UserManager = new UserManager(new RestService());
VolunteerManager = new VolunteerManager(new RestService());
SignupManager = new SignupManager(new RestService());
NavPage.Navigation.InsertPageBefore(new VolunteerDashboardPage(), NavPage.Navigation.NavigationStack.First());
NavPage.Navigation.PopToRootAsync();
}
});
}
}
public static Action LogoutAction
{
get
{
return new Action(() =>
{
DependencyService.Get<ICredentialsService>().DeleteCredentials();
App.User = null;
// NavPage.Navigation.PopModalAsync();
NavPage.Navigation.InsertPageBefore(new LoginPage(), NavPage.Navigation.NavigationStack.First());
NavPage.Navigation.PopToRootAsync();
});
}
}
public App()
{
User = new User();
UserManager = new UserManager(new RestService());
VolunteerManager = new VolunteerManager(new RestService());
SignupManager = new SignupManager(new RestService());
// AWS SDK
var loggingConfig = AWSConfigs.LoggingConfig;
loggingConfig.LogMetrics = true;
loggingConfig.LogResponses = ResponseLoggingOption.Always;
loggingConfig.LogMetricsFormat = LogMetricsFormatOption.JSON;
loggingConfig.LogTo = LoggingOptions.SystemDiagnostics;
//AWSConfigs.AWSRegion = "us-east-1";
// Check if login needed
if (DependencyService.Get<ICredentialsService>().DoCredentialsExist())
{
NavPage = new NavigationPage(new VolunteerDashboardPage());
MainPage = NavPage;
// MainPage = new VolunteerDashboardPage();
} else {
NavPage = new NavigationPage(new LoginPage());
MainPage = NavPage;
}
}
protected override void OnStart()
{
// Handle when your app starts
}
protected override void OnSleep()
{
// Handle when your app sleeps
}
protected override void OnResume()
{
// Handle when your app resumes
}
}
}
最佳答案
添加 nuget 包 AndroidX.Fragment 版本“1.2.5.4”对我有用。仅当我选择开发者选项时才能重现 -> 不要保留 Activity
关于android - Xamarin.Forms.Android : java. lang.IllegalStateException: fragment 没有 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39068772/
我有一个坦克射击弹药的游戏。我对这部分代码的目标是检查它们是否与“碰撞”磁贴发生碰撞,如果是,则将其和磁贴移除。 代码如下所示,每 1/60 秒检查一次: Iterator iterator = sh
我尝试使用 JSR-303 注释(类级别)和验证器实现为 play 2.0.1 编写自定义表单验证器。 不幸的是,当我提交表单并且验证失败时,我收到了一个 IllegalStateException,
根据answer of BalusC ,我用过 FacesContext.getCurrentInstance().getExternalContext().redirect(url); 在我的 @P
这个问题已经有答案了: Copy a stream to avoid "stream has already been operated upon or closed" (10 个回答) 已关闭 5
这个问题已经有答案了: Spring: getOutputStream() has already been called for this response (3 个回答) 已关闭 4 年前。 我正
我正在尝试将 Activity 转换为 FragmentActivty 对象,以便获得 FragmentManager 对象 public class Main extends ListActivit
我正在尝试使用可编辑的组合框,通过用户的某些击键从数据库中快速搜索客户端的功能。我想要的是,用户将输入一些字母,如果这些字母与某些客户端匹配,这些客户端将保留在组合框的当前数据模型中。 代码如下。请修
这个问题已经有答案了: You need to use a Theme.AppCompat theme (or descendant) with this activity. Change to Th
我正在使用 Android Studio 和 Genymotion 作为模拟器创建一个应用程序,其中我在 3 个 EditText 中输入数据,当我单击按钮将其存储在 sqlite 数据库中时,它不起
我正在为 Android 构建一个简单的消息应用程序,并且在发送短信时遇到一些问题。我第一次使用 OnlickListener 时,消息被发送并显示在我的 ListView 中。当我在 Activit
我了解到 collect() 和 forEach() 都是流终端操作,在同一个流上调用它们会抛出 非法状态异常。但是,以下代码可以成功编译并按升序打印每个字符串的长度。不会引发任何异常。怎么会这样?
我对 classcastException 和非法状态异常都有点困惑,因为在大多数情况下它们看起来都很相似。 我在这个java代码中遇到了一个问题 class consumer {
我正在尝试这个小计算器程序。当我调用calculateResult()方法时,我想在第二个操作数为零且运算符为除法时显示IllegalStateException错误。但尽管如此,我在calculat
Stacktrace Here 导入java.util.*; 公共(public)类 AccountClient { public static void main(String[] args) {
我正在使用 readEntity() 方法读取 JAVAX 响应,但我收到以下堆栈跟踪: java.lang.IllegalStateException: Entity input stream ha
我是安卓新手。我正在尝试进行简单的登录 Activity ,但当我单击“登录”按钮时出现运行时错误。我认为我没有正确获取数据。我已经检查过,SQLite 中有一个与该 PK 相对应的数据。 日志猫。
我正在创建一个登录页面,工程师可以通过以“engg”开头的用户名登录。问题出在登录页面,当我使用正确的密码提供正确的输入时,它会给出“非法状态异常”。在错误的输入中,它工作正常。就像当我在我的 ora
我正在使用一些现有的 Java 设备驱动程序软件,该软件使用 JavaCOMM 进行串行 I/O。我昨天看到它抛出一个异常,其中有一个 IllegalStateException - 端口从 publ
这个问题不太可能对任何 future 的访客有帮助;它只与一个较小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于全世界的互联网受众。如需帮助使此问题更广泛适用,visit the
我正在使用 Adventnet SNMPAPI 开发 UDP 监听程序。现在我需要将监听数据保存到数据库中。当我这样做时,我遇到了错误。任何人都可以帮忙解决这个问题吗... 这是我的代码。 impor
我是一名优秀的程序员,十分优秀!