机器人 - 错误 - 抛出:IllegalArgumentException:窗口之后加入窗式不能改变抛出、机器人、窗口、错误

2023-09-06 04:16:27 作者:第二炮半价

我调试Android应用程序(这是不幸的是别人写的)。该应用程序有一个醒目的活动而使用意向的过渡效果持续1秒钟,然后到一个登陆页面的活动。该应用程序正在运行,直到我注意到targetSDKVersion没有在清单文件中设置。我将它设置为18,然后当我运行应用程序在模拟器中,应用程序崩溃,我看到的logcat以下错误:

  6月十号日至24日:14:26.840:E / AndroidRuntime(2457):致命异常:主要
6月10号至24号:14:26.840:E / AndroidRuntime(2457):java.lang.IllegalArgumentException:如果窗口被加入后窗口类型不能改变。
6月10号至24日:14:26.840:E / AndroidRuntime(2457):在android.os.Parcel.readException(Parcel.java:1435)
6月10号至24日:14:26.840:E / AndroidRuntime(2457):在android.os.Parcel.readException(Parcel.java:1385)
6月10号至24日:14:26.840:E / AndroidRuntime(2457):在android.view.IWindowSession $存根$ Proxy.relayout(IWindowSession.java:835)
6月10号至24日:14:26.840:E / AndroidRuntime(2457):在android.view.ViewRootImpl.relayoutWindow(ViewRootImpl.java:5034)
6月10号至24日:14:26.840:E / AndroidRuntime(2457):在android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1399)
6月10号至24日:14:26.840:E / AndroidRuntime(2457):在android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
6月10号至24日:14:26.840:E / AndroidRuntime(2457):在android.view.ViewRootImpl $ TraversalRunnable.run(ViewRootImpl.java:5481)
6月10号至24日:14:26.840:E / AndroidRuntime(2457):在android.view.Choreographer $ CallbackRecord.run(Choreographer.java:749)
6月10号至24日:14:26.840:E / AndroidRuntime(2457):在android.view.Choreographer.doCallbacks(Choreographer.java:562)
6月10号至24日:14:26.840:E / AndroidRuntime(2457):在android.view.Choreographer.doFrame(Choreographer.java:532)
6月10号至24日:14:26.840:E / AndroidRuntime(2457):在android.view.Choreographer $ FrameDisplayEventReceiver.run(Choreographer.java:735)
6月10号至24日:14:26.840:E / AndroidRuntime(2457):在android.os.Handler.handleCallback(Handler.java:730)
6月10号至24日:14:26.840:E / AndroidRuntime(2457):在android.os.Handler.dispatchMessage(Handler.java:92)
6月10号至24日:14:26.840:E / AndroidRuntime(2457):在android.os.Looper.loop(Looper.java:137)
6月10号至24日:14:26.840:E / AndroidRuntime(2457):在android.app.ActivityThread.main(ActivityThread.java:5103)
6月10号至24日:14:26.840:E / AndroidRuntime(2457):在java.lang.reflect.Method.invokeNative(本机方法)
6月10号至24日:14:26.840:E / AndroidRuntime(2457):在java.lang.reflect.Method.invoke(Method.java:525)
6月10号至24日:14:26.840:E / AndroidRuntime(2457):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:737)
6月10号至24日:14:26.840:E / AndroidRuntime(2457):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
6月10号至24日:14:26.840:E / AndroidRuntime(2457):在dalvik.system.NativeStart.main(本机方法)
 

应用程序崩溃显示启动画面后,立即登陆活动页面加载之前。下面块显示相关的code块从飞溅的活动。

开机活动

 私人螺纹mSplashThread;
@覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.splash);
    最后SplashScreenActivity闪屏=这一点;
        mSplashThread =新的Thread(){

@覆盖
        公共无效的run(){
        尝试 {
            同步(本){
                //等待时间或退出触摸特定时期
                等(1000);
            }
        }
        赶上(InterruptedException的前){
        }

        完();

        //运行下一个活动
        意向意图=新的意图();
        intent.setClass(闪屏,LandingPageActivity.class);
        startActivity(意向);
        }
    };
    mSplashThread.start();
    }

@覆盖
公共布尔的onTouchEvent(MotionEvent EVT)
{
    如果(evt.getAction()== MotionEvent.ACTION_DOWN)
    {
    尝试{
        同步(mSplashThread){
            mSplashThread.notifyAll();
            }
    }
    赶上(抛出:IllegalArgumentException E){
        Log.v(就是这样,e.getCause()的getMessage());
    }
}
返回true;
}
 

现在在我所有的研究,调试这个问题,我发现,建议检查以下code片,但我没有像这样在我的应用程序什么:

  @覆盖
    公共无效onAttachedToWindow()
    {
        。this.getWindow()的setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
        super.onAttachedToWindow();
    }
 
机器人引路 昆山制造 迈向 昆山智造

解决方案

此问题已得到解决。确实有onAttachedToWindow的空基类之一的发生。它的工作移除覆盖后。正如我在原来的职位提到的,我曾经碰到过这种解决方案在另一篇文章。这是一个对帖子。

在我的情况下,然而,这code不在任何面向用户的活动。这是一个空白父活动而我的目标网页继承。希望有人可以节省几个小时,这个帖子之后。

I am debugging an android app (which was unfortunately written by someone else). The app has a splash activity which lasts for 1 second and then the transitions to a landing page activity using an intent. The app was running fine until I noticed that the targetSDKVersion was not set in the manifest file. I set it to 18. And then when I run the app in the emulator, the app crashes and I see the following error in logcat:

10-24 06:14:26.840: E/AndroidRuntime(2457): FATAL EXCEPTION: main
10-24 06:14:26.840: E/AndroidRuntime(2457): java.lang.IllegalArgumentException: Window type can not be changed after the window is added.
10-24 06:14:26.840: E/AndroidRuntime(2457):     at android.os.Parcel.readException(Parcel.java:1435)
10-24 06:14:26.840: E/AndroidRuntime(2457):     at android.os.Parcel.readException(Parcel.java:1385)
10-24 06:14:26.840: E/AndroidRuntime(2457):     at android.view.IWindowSession$Stub$Proxy.relayout(IWindowSession.java:835)
10-24 06:14:26.840: E/AndroidRuntime(2457):     at android.view.ViewRootImpl.relayoutWindow(ViewRootImpl.java:5034)
10-24 06:14:26.840: E/AndroidRuntime(2457):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1399)
10-24 06:14:26.840: E/AndroidRuntime(2457):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
10-24 06:14:26.840: E/AndroidRuntime(2457):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
10-24 06:14:26.840: E/AndroidRuntime(2457):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
10-24 06:14:26.840: E/AndroidRuntime(2457):     at android.view.Choreographer.doCallbacks(Choreographer.java:562)
10-24 06:14:26.840: E/AndroidRuntime(2457):     at android.view.Choreographer.doFrame(Choreographer.java:532)
10-24 06:14:26.840: E/AndroidRuntime(2457):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
10-24 06:14:26.840: E/AndroidRuntime(2457):     at android.os.Handler.handleCallback(Handler.java:730)
10-24 06:14:26.840: E/AndroidRuntime(2457):     at android.os.Handler.dispatchMessage(Handler.java:92)
10-24 06:14:26.840: E/AndroidRuntime(2457):     at android.os.Looper.loop(Looper.java:137)
10-24 06:14:26.840: E/AndroidRuntime(2457):     at android.app.ActivityThread.main(ActivityThread.java:5103)
10-24 06:14:26.840: E/AndroidRuntime(2457):     at java.lang.reflect.Method.invokeNative(Native Method)
10-24 06:14:26.840: E/AndroidRuntime(2457):     at java.lang.reflect.Method.invoke(Method.java:525)
10-24 06:14:26.840: E/AndroidRuntime(2457):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
10-24 06:14:26.840: E/AndroidRuntime(2457):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-24 06:14:26.840: E/AndroidRuntime(2457):     at dalvik.system.NativeStart.main(Native Method)

The app crashes immediately after showing the splash screen and before the landing page activity is loaded. The following blocks show relevant code blocks from the splash activity.

Splash Activity

private Thread mSplashThread;    
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
    final SplashScreenActivity sPlashScreen = this;   
        mSplashThread =  new Thread(){

@Override
        public void run(){
        try {
            synchronized(this){
                // Wait given period of time or exit on touch
                wait(1000);
            }
        }
        catch(InterruptedException ex){                    
        }

        finish();

        // Run next activity
        Intent intent = new Intent();
        intent.setClass(sPlashScreen, LandingPageActivity.class);
        startActivity(intent);                 
        }
    };
    mSplashThread.start();        
    }

@Override
public boolean onTouchEvent(MotionEvent evt)
{
    if(evt.getAction() == MotionEvent.ACTION_DOWN)
    {
    try{
        synchronized(mSplashThread){
            mSplashThread.notifyAll();
            }
    }
    catch (IllegalArgumentException e){
        Log.v("This is it", e.getCause().getMessage());
    }
}
return true;
}

Now in all my research to debug this issue I found suggestions to check for following code piece but I don't have anything like this in my app:

@Override
    public void onAttachedToWindow()
    {  
        this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
        super.onAttachedToWindow();  
    }

解决方案

The issue is resolved. There was indeed an occurrence of "onAttachedToWindow" in one of the empty base classes. It worked after removing that override. As I mentioned in my original post, I had come across this solution in another post. Here is a reference to that post.

In my case however this code wasn't in any of the user-facing activities. It was in a blank parent activity which my landing page was inheriting. Hope someone saves a few hours after this post.