0

today i'm try to create a SlidingTabLayout with the video on youtube(https://www.youtube.com/watch?v=YmAS2SEmlws) but the project give me this problem

FATAL EXCEPTION: main Process: com.example.livechannels, PID: 27276 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.livechannels/com.example.livechannels.MainActivity}: java.lang.NullPointerException

MainActivity

package com.example.livechannels;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;

import com.example.livechannels.Tab.SlidingTabLayout;

public class MainActivity extends AppCompatActivity {
    private SlidingTabLayout mSlidingTabLayout;
    private ViewPager mViewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        mViewPager=(ViewPager)findViewById(R.id.vp_tabs);
        mViewPager.setAdapter(new MyAdapter(getSupportFragmentManager(),this));

        mSlidingTabLayout=(SlidingTabLayout)findViewById(R.id.stl_tabs);
        mSlidingTabLayout.setDistributeEvenly(true);
        mSlidingTabLayout.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
        mSlidingTabLayout.setSelectedIndicatorColors(getResources().getColor(R.color.colorAccent));
        //mSlidingTabLayout.setCustomTabView(R.layout.tab_view, R.id.tv_tab);
        mSlidingTabLayout.setViewPager(mViewPager);
    }
}

Activity_main

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <ImageView android:id="@+id/splashscreen"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:src="@drawable/ic_launcher"
        android:layout_gravity="center|top"
        android:contentDescription="@string/app_name"
        android:scaleType="fitXY" />

    <com.example.livechannels.Tab.SlidingTabLayout
        android:id="@+id/stl_tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"></com.example.livechannels.Tab.SlidingTabLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/vp_tabs"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"></android.support.v4.view.ViewPager>


</RelativeLayout>

if you want to see the other file, tell me
What can i do for fix this problem?

GSerg
  • 71,102
  • 17
  • 141
  • 299
Ayoub
  • 1
  • 3
  • 1
    Possible duplicate of [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) – GSerg Dec 20 '15 at 19:21
  • 1
    Are you sure you load the right layout? You use `setContentView()` with `activity_splash` but then named the layout `activity_main`. – Floern Dec 20 '15 at 21:49

1 Answers1

0

I put this line on the activity splash and now it work! but i have another problem

 <com.example.livechannels.Tab.SlidingTabLayout
        android:id="@+id/stl_tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"></com.example.livechannels.Tab.SlidingTabLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/vp_tabs"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"></android.support.v4.view.ViewPager>

but it doesn't show me the icons. this is the problem problem with the icons

Ayoub
  • 1
  • 3