Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] java – Showing a blank activity in android

Posted on November 14, 2022

Solution 1 :

I guess the reason why it is not showing properly it is because you don’t have the oncreate() implemented in your project so under

private ViewPager mMyViewPager;
private TabLayout mTabLayout;

Add this :

 override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.main);

}

Don’t forget to delete this line of code setContentView(R.layout.main); from your Init function

Problem :

My problem is when I go to a viewpager it shows for a second and then I get a blank page and I don’t where is the problem.

Here is my code to go from an activity to a viewpager:

final WordAdapter adapter = new WordAdapter(this, words,R.color.category_numbers);
        // Find the {@link ListView} object in the view hierarchy of the {@link Activity}.
        // There should be a {@link ListView} with the view ID called list, which is declared in the
        // activity_numbers.xml layout file.
        // word_list.xml layout file.

        final ListView listView = (ListView) findViewById(R.id.list);
        // Make the {@link ListView} use the {@link WordAdapter} we created above, so that the
        // {@link ListView} will display list items for each {@link Word} in the list.
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Intent intent = new Intent(getApplicationContext(),Main.class);
                adapter.getItemId(i);
                init(i);
                startActivity(intent);
            }
        });

And my the viewpager is here:

    public class Main extends AppCompatActivity {
        // widgets
        private ViewPager mMyViewPager;
        private TabLayout mTabLayout;
    
    
       @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    public void init(int i) {
        mTabLayout = findViewById(R.id.tab_layout);
        mMyViewPager = findViewById(R.id.view_pager);
        ArrayList<Fragment> fragments = new ArrayList<>();
        Hat[] hats = Hats.getHats();
        for (Hat hat : hats) {
            com.example.android.miwok.ViewPagerItemFragment fragment = com.example.android.miwok.ViewPagerItemFragment.getInstance(hat);
            fragments.add(fragment);
        }
        MyPagerAdapter pagerAdapter = new MyPagerAdapter(getSupportFragmentManager() , fragments);
        mMyViewPager.setAdapter(pagerAdapter);
        mTabLayout.setupWithViewPager(mMyViewPager);
        mMyViewPager.setCurrentItem(i);
    }
}

Xml for viewpager is:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns_android="http://schemas.android.com/apk/res/android"
    xmlns_tools="http://schemas.android.com/tools"
    android_layout_width="match_parent"
    android_layout_height="match_parent"
    xmlns_app="http://schemas.android.com/apk/res-auto"
    tools_context=".Main"
    android_orientation="vertical"
    android_weightSum="100"
    android_background="#fff">

    <android.support.v4.view.ViewPager
        android_layout_width="match_parent"
        android_layout_height="0dp"
        android_id="@+id/view_pager"
        android_layout_weight="90">

    </android.support.v4.view.ViewPager>

    <android.support.design.widget.TabLayout
        android_id="@+id/tab_layout"
        android_layout_width="match_parent"
        android_layout_height="wrap_content"
        app_tabBackground="@drawable/tab_selector"
        app_tabGravity="center"
        app_tabIndicatorHeight="0dp"
        app_tabMaxWidth="10dp"/>
</LinearLayout>

And my is here Pageadapter:

public class MyPagerAdapter extends FragmentStatePagerAdapter {

    private ArrayList<Fragment> mFragments = new ArrayList<>();

    public MyPagerAdapter(FragmentManager fm, ArrayList<Fragment> fragments) {
        super(fm);
        mFragments = fragments;
    }

    @Override
    public Fragment getItem(int position) {
        return mFragments.get(position);
    }

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

I edited my code here so you can know more about my code hope someone can help!

READ  [ANSWERED] Android Snackbar crashes(android.view.InflateException) with enabled Proguard
Powered by Inline Related Posts

Comments

Comment posted by Taki

can you please show more of your code to examinate it further

Comment posted by Moataz El-Naggar

you want to see more about the arraylists or the adapter code ?

Comment posted by Taki

Check out my answer , it might help you if not let me know here again , Yeah i want to see your whole code to better understand the structure of your code

Comment posted by Taki

Did you solve it ?

Comment posted by Moataz El-Naggar

No it didn’t 🙁

Comment posted by Moataz El-Naggar

when i debug it gives me this : E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.android.miwok, PID: 11955 java.lang.NullPointerException: Attempt to invoke virtual method ‘void android.support.v4.view.ViewPager.setAdapter(android.support.v4.view.PagerAdapter)’ on a null object reference at com.example.android.miwok.Main.init(Main.java:36) at com.example.android.miwok.PhrasesActivity$1.onItemClick(PhrasesActivity.java:52)

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress