title: Class for name add parameters to instatiate a fragment
body: <p>Ok, my question is a bit hard to explain.</p>
  
  <p>I've a slider which slides fragments. Its just a simple view pager.
  Now I want to make it a bit more reuseable:P </p>
  
  <p>My setup is like this:
  SliderContainer (I get the viewpager here, this is just a fragment which i can include anywere). 
  Slider (This is the slider itself where the problem is caused, this one gets included by the container which holds the slider, so slider container).
  SliderFragment (This is the layout which where you can slide tru, This includes a .xml file and a class which uses this .xml file, then i just can make custom onclicklisteners etc. In the java file, so this is the slider object which gets used by Slider.java).</p>
  
  <p>I want to reuse this code. The slider fragment needs to be replaced only, if I want to add it to another page, becouse another page needs another layout and other functions. </p>
  
  <p>So the class which slider includes (Now its static sliderFragment), but should be called by a parameter, and I should change its name, So I only need to replace the function file, and pass the name of this class to sliderContainer > slider > sliderFragment.</p>
  
  <p>I use class.forname, which can convert a stringname to a class name. All good. 
  This is a piece of code in slider, which includes the sliderFragment.</p>
  
  <pre><code>@Override
  public Fragment getItem(int position) 
  {
      // make the first pager bigger than others
      if (position == slider_firstpage)
          scale = Constants.slider_bigscale;      
      else
          scale = Constants.slider_smallscale;
  
      position = position % slider_pages;
  
      try {
          c = Class.forName("com.homeslider.SliderFragment").getConstructor(Slider.class, Integer.class, Integer.class, Float.class, String.class, String.class); 
          return (Fragment) c.newInstance(context, position, scale, slider_titles, slider_images);
      } catch (InstantiationException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (IllegalAccessException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (IllegalArgumentException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (InvocationTargetException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (NoSuchMethodException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (ClassNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      return null;
  }
  </code></pre>
  
  <p>SliderFragment needs: The context, int, int, String array, String array.
  This are the parameters sliderFragment needs. </p>
  
  <p>Originally I would only do this: </p>
  
  <pre><code>return SliderFragment.newInstance(context, position, scale, slider_titles, slider_images);
  </code></pre>
  
  <p>The code I use doesn't seem really good to me, It only throws a NoSuchMethodFound exception, but whatelse goes wrong?
  There is no other material I can find on the internet which uses this method to instatiate a fragment, so I needed to ask here.</p>
  
  <p>So my final question is:
  Why does it trhow noSuchMethodFound error (I know I use wrong types in getParameters, but I've no idea whatelse I need to use), also what goes wrong in my code besides that?
  Any suggestions?</p>
  
  <p>Im open for any help:) </p>
  
  <p>On request:</p>
  
  <p>SliderContainer.java (Container fragment)</p>
  
  <pre><code>import android.content.Context;
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.support.v4.view.ViewPager;
  import android.util.Log;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  
  public class SliderContainer extends Fragment {
      public Slider adapter;
      public static ViewPager pager;
      public static int slider_pages;
      public static int slider_firstpage;
  //  public int slider_fragmentlayout;
      @Override 
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          Bundle getExtras = this.getArguments();
          View view = inflater.inflate(R.layout.sliderselecting, container, false);
          slider_pages = getExtras.getStringArray("images").length;
          slider_firstpage = slider_pages * Constants.slider_loops / 2;
          pager = (ViewPager) view.findViewById(getExtras.getInt("layoutcontainer"));
          adapter = new Slider(getActivity(), this.getFragmentManager(), getExtras.getStringArray("titles"), 
                  getExtras.getStringArray("images"), slider_pages, slider_firstpage);
          pager.setAdapter(adapter);
          pager.setOnPageChangeListener(adapter);
          pager.setCurrentItem(slider_firstpage);
          pager.setOffscreenPageLimit(3);
          pager.setPageMargin(-220);
          return view;
      }
  
  }
  </code></pre>
  
  <p>This one gets the parameters from his host activity by getArguments, and passes these to Slider.java when setting it as adapter.</p>
  
  <p>Where I init my sliderContainer(So his host activity).</p>
  
  <pre><code>public void SliderInit(int container){
      Bundle slider_addOptions = new Bundle();
      main_radioslider = new SliderContainer();
      slider_addOptions.putStringArray("titles", slider_names);
      slider_addOptions.putStringArray("images", slider_images);
      slider_addOptions.putInt("layoutcontainer", R.id.sliderContainer); // SliderContainer.xml
      main_radioslider.setArguments(slider_addOptions);
      getSupportFragmentManager().beginTransaction().add(container, main_radioslider).commit();       
  }
  </code></pre>
  
  <p>It makes the fragment (SliderContainer.java) and adds the parameters with addArguments.
  R.id.sliderContainer is the viewpager which sliderContainer uses, this doesn't get used in slider.java.</p>
  
  <p>Important note:
  When I used this code without class for name method, it worked.
  So there doesn't go anything wrong here, It goes wrong in sending the data from Slider to SliderFragment.java and making the fragment.</p>
  
  <p>Data recieving in sliderfragment.java:</p>
  
  <pre><code>    public static Fragment newInstance(Context context, int pos, float scale, String[] slider_titles
          , String[] slider_fragmentbackground)
  {
      Bundle b = new Bundle();
      b.putInt("pos", pos);
      b.putFloat("scale", scale);
      b.putStringArray("names", slider_titles);
      b.putStringArray("images", slider_fragmentbackground);
      return Fragment.instantiate(context, SliderFragment.class.getName(), b);
  }
  </code></pre>
  
  <p>than reuse that code later in my code by calling onCreateView and do this.getArgument().get--type--("key")</p>