E
E
eellazy2015-11-05 10:01:07
Java
eellazy, 2015-11-05 10:01:07

Why is the Android program not compiling?

Hello everyone, because of the outdated method, the application does not want to compile. What should be changed to?
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

public class HomeActivity extends FragmentActivity implements
        ActionBar.TabListener {

    private ViewPager viewPager;
    private ActionBar actionBar;
    private TabPagerAdapter tabPagerAdapter;
    private String[] tabs = { "Missed Calls", "Dialled", "Received" };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        viewPager = (ViewPager) findViewById(R.id.pager);
        tabPagerAdapter = new TabPagerAdapter(getSupportFragmentManager());
        viewPager.setAdapter(tabPagerAdapter);
        actionBar = getActionBar();
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        for (String tab_name : tabs) {
            actionBar.addTab(actionBar.newTab().setText(tab_name)
                    .setTabListener(this));
        }

        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

            /**
             * on swipe select the respective tab
             * */
            @Override
            public void onPageSelected(int position) {
                actionBar.setSelectedNavigationItem(position);
            }

            @Override
            public void onPageScrolled(int arg0, float arg1, int arg2) { }

            @Override
            public void onPageScrollStateChanged(int arg0) { }
        });
    }

    @Override
    public void onTabReselected(Tab tab, FragmentTransaction ft) { }

    @Override
    public void onTabSelected(Tab tab, FragmentTransaction ft) {
        viewPager.setCurrentItem(tab.getPosition());
    }

    @Override
    public void onTabUnselected(Tab tab, FragmentTransaction ft) {}
}

11-05 09:52:47.778 31042-31042/com.example.eellazy.myapplication48 E/AndroidRuntime: FATAL EXCEPTION: main
11-05 09:52:47.778 31042-31042/com.example.eellazy.myapplication48 E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.eellazy.myapplication48/com.example.eellazy.myapplication48.HomeActivity}: java.lang.NullPointerException
11-05 09:52:47.778 31042-31042/com.example.eellazy.myapplication48 E/AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2306)
11-05 09:52:47.778 31042-31042/com.example.eellazy.myapplication48 E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
11-05 09:52:47.778 31042-31042/com.example.eellazy.myapplication48 E/AndroidRuntime:     at android.app.ActivityThread.access$600(ActivityThread.java:156)
11-05 09:52:47.778 31042-31042/com.example.eellazy.myapplication48 E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340)
11-05 09:52:47.778 31042-31042/com.example.eellazy.myapplication48 E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:99)
11-05 09:52:47.778 31042-31042/com.example.eellazy.myapplication48 E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:153)
11-05 09:52:47.778 31042-31042/com.example.eellazy.myapplication48 E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5299)
11-05 09:52:47.778 31042-31042/com.example.eellazy.myapplication48 E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method)
11-05 09:52:47.778 31042-31042/com.example.eellazy.myapplication48 E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:511)
11-05 09:52:47.778 31042-31042/com.example.eellazy.myapplication48 E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
11-05 09:52:47.778 31042-31042/com.example.eellazy.myapplication48 E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
11-05 09:52:47.778 31042-31042/com.example.eellazy.myapplication48 E/AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method)
11-05 09:52:47.778 31042-31042/com.example.eellazy.myapplication48 E/AndroidRuntime:  Caused by: java.lang.NullPointerException
11-05 09:52:47.778 31042-31042/com.example.eellazy.myapplication48 E/AndroidRuntime:     at com.example.eellazy.myapplication48.HomeActivity.onCreate(HomeActivity.java:25)
11-05 09:52:47.778 31042-31042/com.example.eellazy.myapplication48 E/AndroidRuntime:     at android.app.Activity.performCreate(Activity.java:5122)
11-05 09:52:47.778 31042-31042/com.example.eellazy.myapplication48 E/AndroidRuntime:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
11-05 09:52:47.778 31042-31042/com.example.eellazy.myapplication48 E/AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
11-05 09:52:47.778 31042-31042/com.example.eellazy.myapplication48 E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358) 
11-05 09:52:47.778 31042-31042/com.example.eellazy.myapplication48 E/AndroidRuntime:     at android.app.ActivityThread.access$600(ActivityThread.java:156) 
11-05 09:52:47.778 31042-31042/com.example.eellazy.myapplication48 E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340) 
11-05 09:52:47.778 31042-31042/com.example.eellazy.myapplication48 E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:99) 
11-05 09:52:47.778 31042-31042/com.example.eellazy.myapplication48 E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:153) 
11-05 09:52:47.778 31042-31042/com.example.eellazy.myapplication48 E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5299) 
11-05 09:52:47.778 31042-31042/com.example.eellazy.myapplication48 E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method) 
11-05 09:52:47.778 31042-31042/com.example.eellazy.myapplication48 E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:511) 
11-05 09:52:47.778 31042-31042/com.example.eellazy.myapplication48 E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833) 
11-05 09:52:47.778 31042-31042/com.example.eellazy.myapplication48 E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) 
11-05 09:52:47.778 31042-31042/com.example.eellazy.myapplication48 E/AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method) 

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
GavriKos, 2015-11-05
@GavriKos

How would the application compile. Error in runtime. And in the pasted code, the numbering of lines is very lacking. The error is on line 25, and which one is 25 is not clear.

D
Dmitry, 2015-11-05
@Thelema

NullPointerException - some variable is not declared (equal to null). Try to comment out everything after setContentView in the onCreate method. and add line by line and you will find the error

A
Alexey Perelygin, 2015-11-05
@orcDamnar

Note: If you want to implement an activity that includes an action bar, you should instead use the ActionBarActivity class, which is a subclass of this one, so allows you to use Fragment APIs on API level 7 and higher. in general, you need to use ActionBarActivity and get getActionBar already there, and it would be even more correct to use AppCompatActivity and get actionBar: getSupportActionbar. before that you will need to include v7.appcompat

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question