Advertisement
Guest User

Untitled

a guest
Mar 1st, 2013
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.79 KB | None | 0 0
  1. Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment
  2. com.descartes.application.MainActivity$DummySectionFragment:
  3. make sure class name exists, is public, and has an empty constructor that is public
  4.  
  5. Caused by: java.lang.InstantiationException:
  6. can't instantiate class com.descartes.application.MainActivity$DummySectionFragment;
  7. no empty constructor
  8.  
  9. public class MainActivity extends FragmentActivity implements ActionBar.TabListener {
  10.  
  11. /**
  12. * The {@link android.support.v4.view.PagerAdapter} that will provide fragments for each of the
  13. * sections. We use a {@link android.support.v4.app.FragmentPagerAdapter} derivative, which will
  14. * keep every loaded fragment in memory. If this becomes too memory intensive, it may be best
  15. * to switch to a {@link android.support.v4.app.FragmentStatePagerAdapter}.
  16. */
  17. SectionsPagerAdapter mSectionsPagerAdapter;
  18.  
  19. /**
  20. * The {@link ViewPager} that will host the section contents.
  21. */
  22. ViewPager mViewPager;
  23. private static int SCAN = 1;
  24.  
  25. @Override
  26. public void onCreate(Bundle savedInstanceState) {
  27. super.onCreate(savedInstanceState);
  28. setContentView(R.layout.activity_main);
  29.  
  30. Loc lc = new LocImpl(this);
  31. Localisation loc = lc.localiser();
  32. System.out.println(loc.toString());
  33. // Create the adapter that will return a fragment for each of the three primary sections
  34. // of the app.
  35. mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
  36.  
  37. // Set up the action bar.
  38. final ActionBar actionBar = getActionBar();
  39. actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
  40.  
  41. // Set up the ViewPager with the sections adapter.
  42. mViewPager = (ViewPager) findViewById(R.id.pager);
  43. mViewPager.setAdapter(mSectionsPagerAdapter);
  44.  
  45. // When swiping between different sections, select the corresponding tab.
  46. // We can also use ActionBar.Tab#select() to do this if we have a reference to the
  47. // Tab.
  48. mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
  49. @Override
  50. public void onPageSelected(int position) {
  51. actionBar.setSelectedNavigationItem(position);
  52. }
  53. });
  54.  
  55. // For each of the sections in the app, add a tab to the action bar.
  56. for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
  57. // Create a tab with text corresponding to the page title defined by the adapter.
  58. // Also specify this Activity object, which implements the TabListener interface, as the
  59. // listener for when this tab is selected.
  60. actionBar.addTab(
  61. actionBar.newTab()
  62. .setText(mSectionsPagerAdapter.getPageTitle(i))
  63. .setTabListener(this));
  64. }
  65. }
  66.  
  67. @Override
  68. public boolean onCreateOptionsMenu(Menu menu) {
  69. getMenuInflater().inflate(R.menu.activity_main, menu);
  70. return true;
  71. }
  72.  
  73. // Ecouteurs qui correspondent à chaque bouton présent dans la page
  74. public boolean onOptionsItemSelected(MenuItem item) {
  75. switch (item.getItemId()) {
  76. case R.id.menu_camera:
  77.  
  78. // app icon in action bar clicked; go home
  79. Intent intent = new Intent(this, ScanBarActivity.class);
  80. intent.putExtra("METHODE", "SCAN");
  81. startActivityForResult(intent, SCAN);
  82. return true;
  83. default:
  84. return super.onOptionsItemSelected(item);
  85. }
  86. }
  87.  
  88.  
  89. public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
  90. }
  91.  
  92. public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
  93. // When the given tab is selected, switch to the corresponding page in the ViewPager.
  94. mViewPager.setCurrentItem(tab.getPosition());
  95. }
  96.  
  97. public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
  98. }
  99.  
  100. /**
  101. * A {@link FragmentPagerAdapter} that returns a fragment corresponding to one of the primary
  102. * sections of the app.
  103. */
  104. public class SectionsPagerAdapter extends FragmentPagerAdapter {
  105.  
  106. public SectionsPagerAdapter(FragmentManager fm) {
  107. super(fm);
  108. }
  109.  
  110. @Override
  111. public Fragment getItem(int i) {
  112. Fragment fragment = new DummySectionFragment();
  113. Bundle args = new Bundle();
  114. args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, i + 1);
  115. fragment.setArguments(args);
  116. return fragment;
  117. }
  118.  
  119. @Override
  120. public int getCount() {
  121. return 4;
  122. }
  123.  
  124. @Override
  125. public CharSequence getPageTitle(int position) {
  126. switch (position) {
  127. case 0: return getString(R.string.title_section1).toUpperCase();
  128. case 1: return getString(R.string.title_section2).toUpperCase();
  129. case 2: return getString(R.string.title_section3).toUpperCase();
  130. case 3: return getString(R.string.title_section4).toUpperCase();
  131. }
  132. return null;
  133. }
  134. }
  135.  
  136. /**
  137. * A dummy fragment representing a section of the app, but that simply displays dummy text.
  138. */
  139. public class DummySectionFragment extends Fragment {
  140. public DummySectionFragment() {
  141. }
  142.  
  143. public static final String ARG_SECTION_NUMBER = "section_number";
  144.  
  145. @Override
  146. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  147. Bundle savedInstanceState) {
  148.  
  149. Bundle args = getArguments();
  150. switch (args.getInt(ARG_SECTION_NUMBER)){
  151. case 1:
  152. return inflater.inflate(R.layout.page_accueil, container, false);
  153. case 2:
  154.  
  155. break;
  156. case 3:
  157.  
  158. break;
  159. case 4:
  160.  
  161. break;
  162. }
  163. TextView textView = new TextView(getActivity());
  164. textView.setGravity(Gravity.CENTER);
  165. textView.setText(Integer.toString(args.getInt(ARG_SECTION_NUMBER)));
  166. return textView;
  167.  
  168. }
  169. }
  170.  
  171. }
  172.  
  173. public class DummySectionFragment extends Fragment
  174.  
  175. public static class DummySectionFragment extends Fragment
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement