我收到错误java.lang.IllegalArgumentException:找不到ID为0x7f0a012c的视图

时间:2019-07-05 22:13:16

标签: java android-studio nullpointerexception android-viewpager android-tablayout

我正在尝试创建一个对话框,其中包含带有片段的选项卡。 Dialog(locationViewDialog)在主要活动的onCreate方法中是无效的,在这里我调用将适配器附加到viewPager的方法setUpViewPager。当我调用对话框应用程序的show方法时,我在标题上写的日志崩溃了。

function signIn() {
    myMSALObj.loginPopup(requestObj).then(function (loginResponse) {
        //Successful login
        showWelcomeMessage();
        //Call MS Graph using the token in the response
        acquireTokenPopupAndCallMSGraph();
    }).catch(function (error) {
        //Please check the console for errors
        console.log(error);
    });
}

setUpViewPager方法:

    public class MainActivity extends AppCompatActivity {

    private Dialog logOutDialog;
    private Dialog settingsDialog;
    private Dialog addItemDialog;
    private Dialog locationViewDialog;
    private ImageButton btnExit;
    private Fragment settingsFragment = null;
    private Fragment tabInfoFragment;
    private Fragment tabCommentsFragment;
    private SectionsPageAdapter mSectionPageAdapter;

    private TabLayout tabLayout;
    private ViewPager viewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    //should call from SignIn Activity
    DomainController.setUser("u","p");
    //configure toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayShowTitleEnabled(false);

    addItemDialog = new Dialog(this);
    addItemDialog.setContentView(R.layout.dialog_add_item);

    mSectionPageAdapter = new 
    SectionsPageAdapter(getSupportFragmentManager());

    locationViewDialog = new Dialog(this);
    locationViewDialog.setContentView(R.layout.dialog_location_view);

    tabLayout = locationViewDialog.findViewById(R.id.tabsLocation);
    viewPager = locationViewDialog.findViewById(R.id.viewPagerLocation);

    setUpViewPager(viewPager);
    tabLayout.setupWithViewPager(viewPager);
    }

在这里我称为对话框:

    public void setUpViewPager(ViewPager viewPager)
    {
    SectionsPageAdapter adapter = new 
    SectionsPageAdapter(getSupportFragmentManager());
    tabInfoFragment = new Fragment();
    tabCommentsFragment = new Fragment();
    adapter.addFragment(tabInfoFragment,"TabInfoFragment");
    adapter.addFragment(tabCommentsFragment,"TabCommentsFragment");
    viewPager.setAdapter(adapter);
    }

我的部分页面适配器类:

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {


    switch (item.getItemId())
    {
        case R.id.app_bar_search:
            Log.d("MyTag","Search clicked!");
            locationViewDialog.getWindow().setBackgroundDrawable(new 
    ColorDrawable(Color.TRANSPARENT));
            locationViewDialog.show();

            break;

和我的对话框位置视图布局:

public class SectionsPageAdapter extends FragmentPagerAdapter {

private final List<Fragment> mFragmentList = new ArrayList<>();
private final List<String> mFragmentTitleList = new ArrayList<>();

public void addFragment(Fragment fragment,String title)
{
    mFragmentList.add(fragment);
    mFragmentTitleList.add(title);
}

public SectionsPageAdapter(FragmentManager fm) {
    super(fm);
}

@Override
public Fragment getItem(int i) {
    return mFragmentList.get(i);
}

@Nullable
@Override
public CharSequence getPageTitle(int position) {
    return mFragmentTitleList.get(position);
}

@Override
public int getCount() {
    return mFragmentList.size();
}
}

0 个答案:

没有答案