Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 视图#findViewById在运行时返回null,但在调试器中不返回null_Java_Android - Fatal编程技术网

Java 视图#findViewById在运行时返回null,但在调试器中不返回null

Java 视图#findViewById在运行时返回null,但在调试器中不返回null,java,android,Java,Android,在我的android项目中,我有一个非常奇怪的行为 首先,我创建了一个名为ANumberPicker的自定义视图(在OS版本

在我的android项目中,我有一个非常奇怪的行为

首先,我创建了一个名为ANumberPicker的自定义视图(在OS版本<3.0的Android设备上使用)。下面是类的代码片段:

public class ANumberPicker extends LinearLayout {


    // ...


    @NotNull
    private final NumberPickerButton incrementButton;

    @NotNull
    private final NumberPickerButton decrementButton;

    public ANumberPicker(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);

        setOrientation(VERTICAL);

        // INFLATING LAYOUT
        final LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.number_picker, this, true);

        final InputFilter inputFilter = new NumberPickerInputFilter();
        numberInputFilter = new NumberRangeKeyListener();

        incrementButton = (NumberPickerButton) this.findViewById(R.id.increment);
        incrementButton.setNumberPicker(this);

        decrementButton = (NumberPickerButton) this.findViewById(R.id.decrement);
        decrementButton.setNumberPicker(this);

        // ...
   }

   // ...

}
以下是数字\u picker.xml布局:

<merge xmlns:a="http://schemas.android.com/apk/res/android">

<org.solovyev.android.view.NumberPickerButton
        a:id="@+id/increment"
        a:layout_width="fill_parent"
        a:layout_height="wrap_content"
        a:background="@drawable/timepicker_up_btn"/>

<EditText a:id="@+id/timepicker_input"
          a:layout_width="fill_parent"
          a:layout_height="wrap_content"
          a:gravity="center"
          a:singleLine="true"
          style="?android:attr/textAppearanceLargeInverse"
          a:textColor="@android:color/primary_text_light"
          a:textSize="30sp"
          a:inputType="numberDecimal"
          a:background="@drawable/timepicker_input"/>

<org.solovyev.android.view.NumberPickerButton
        a:id="@+id/decrement"
        a:layout_width="fill_parent"
        a:layout_height="wrap_content"
        a:background="@drawable/timepicker_down_btn"/>
i、 e.incrementButton=null

此外,在Jetbrains IDEA中调试此代码时,我在“Watches”窗口中获得了下一个值(断点设置在带有NPE的源代码行上):

i、 完全相同的代码在调试器中返回NOTNULL。 我想不出来。。。有什么建议吗?问题出在哪里

PS我清理了项目并重建了它(我使用maven)

编辑
我发现了线索:R.id.increment和view有不同的整数标识符(我刚刚在Logcat中记录了它们的id)。但是问题仍然存在-清理项目没有帮助…

解决:Jetbrains IDEA存储在缓存以前构建的R文件中,因此“使缓存无效”修复了问题。

解决:Jetbrains IDEA存储在缓存以前构建的R文件中,因此“使缓存无效”修复了问题

incrementButton.setNumberPicker(this);
(NumberPickerButton) this.findViewById(R.id.increment) = {org.solovyev.android.view.NumberPickerButton@830082344688}
R.id.increment = 2131296256
this.getChildAt(0).getId() = 2131296256
incrementButton = null