当内部类的方法退出时,类的实例会被破坏?

时间:2015-07-31 11:49:18

标签: java

我将使用Xposed Bridge API在我的Android手机上自定义状态栏。 挂钩方法运作良好,但存在问题。

public class WPSModule implements IXposedHookLoadPackage {
    final int ICON_SIZE = 100;

    FrameLayout FlStatusBar;
    ...

    void HideWidget(FrameLayout FlLayout, String Name)
    {
        int ViewId = FlLayout.getResources().getIdentifier(Name, "id", "com.android.systemui");
        if(ViewId == 0)
        {
            XposedBridge.log("Failed to find resource " + Name + " on systemui package.");
            return;
        }
        View v = FlLayout.findViewById(ViewId);
        if(v == null)
        {
            XposedBridge.log("v == null with resource " + Name + " on systemui package.");
            return;
        }
        v.setVisibility(View.INVISIBLE);
    }

    public static TextView TvText = null;

    public void handleLoadPackage(final LoadPackageParam LppParam) throws Throwable {
        if (!LppParam.packageName.equals("com.android.systemui"))
            return;
        XposedBridge.log("WPS: SystemUI package found.");

        //Hook
        findAndHookMethod("com.android.systemui.statusbar.phone.PhoneStatusBarView", LppParam.classLoader, "onFinishInflate", new XC_MethodHook() {
            @Override
            protected void beforeHookedMethod(MethodHookParam MhpParam) throws Throwable {
                // this will be called before the clock was updated by the original method
            }

            @Override
            protected void afterHookedMethod(MethodHookParam MhpParam) throws Throwable {
                FlStatusBar = (FrameLayout) MhpParam.thisObject;
            }
        });
        ....
    }
}

当我尝试像这样使用FlStatusBar时:

HideWidget(FlStatusBar, "notification_lights_out");

它不起作用。在Xposed的日志......

07-31 20:22:09.962 E/Xposed (18737): java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.widget.FrameLayout.getResources()' on a null object reference.

使用FlStatusBar的其他内容也不起作用..(例如FlStatusBar.toString()给我NullPointerException

0 个答案:

没有答案