我创建了一个用于条形码扫描的活动。 onCreate
看起来像这样:
public class GradeScreenScanner extends AppCompatActivity implements ZXingScannerView.ResultHandler {
public static final int REQUEST_CAMERA = 1;
protected ZXingScannerView scannerView;
protected FirebaseFirestore db;
protected String scanResult;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
scannerView = new ZXingScannerView(this);
setContentView(scannerView);
db = FirebaseFirestore.getInstance();
}
}
一旦得到结果,我便想像这样启动一个新片段:
android.app.FragmentManager fragmentManager = getFragmentManager();
ScreenFragment screenFragment = new ScreenFragment();
screenFragment.db = db;
screenFragment.serialNumberScanned = serialNumberScanned;
fragmentManager.beginTransaction()
.addToBackStack("screen")
.replace(R.id.content_frame, screenFragment)
.commit();
但是我收到以下不确定的错误信息:
java.lang.IllegalArgumentException: No view found for id 0x7f08005a (uk.wefix:id/content_frame) for fragment ScreenFragment{6262536 #1 id=0x7f08005a}
以防万一,onCreate的片段如下所示:
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
myView = inflater.inflate(R.layout.grade_screens_layout, container, false);
return myView;
}
帮助表示赞赏。
@Override
public void setContentView(View view) {
getDelegate().setContentView(view);
}
答案 0 :(得分:1)
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/content_frame"/>
在活动视图中的xml中丢失了。我的错误,很容易发现Umair
答案 1 :(得分:0)
是,通常当您没有找到id或nullPointer的视图时,我建议您检查:
1-android:id="@+id/
2- findViewById
3-在java类中的变量声明
在大多数情况下,它可以工作;)
祝你好运。