@eellazy

Почему не компилируется Android программа?

Всем привет, из-за устаревшего метода, не хочет компилироватся приложение. На что нужно поменять?
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) 
  • Вопрос задан
  • 292 просмотра
Пригласить эксперта
Ответы на вопрос 3
GavriKos
@GavriKos
Как бы приложение компилируется. Ошибка в рантайме. А в вставленном коде очень нехватает нумерации строк. Ошибка в строке 25, а какая из них 25 - непонятно.
Ответ написан
Thelema
@Thelema
NullPointerException - какая-то переменная не объявлена (равна null). Попробуй в методе onCreate закоментить все после setContentView. и там по строчке добавляй и найдешь ошибку
Ответ написан
orcDamnar
@orcDamnar
Java, C/C++, Android SDK
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. в общем, нужно использовать ActionBarActivity и там уже получать getActionBar а еще правильнее будет использовать AppCompatActivity и получать actionBar: getSupportActionbar. перед этим вам необходимо будет подключить v7.appcompat
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы