Soru & Cevap

switch, private ve static haatası

08.01.2017 - 10:42

hata şu

privatenin üzerine geldiğimde  medifier private not allowed here

static üzerine geldiğimde medifier static not allowed here

 

switch kodunu 
TouchImageAdapter sınıfı içerisine yerleştirdiğimde de bu defer

switch  le ilgili hata alıyorum.

Teşekkürler

 

public class MatematikGoster extends Activity {
	@Override
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.matematikgoster);
        ExtendedViewPager mViewPager = (ExtendedViewPager) findViewById(R.id.view_pager);
        mViewPager.setAdapter(new TouchImageAdapter());

        Bundle extraData = getIntent().getExtras();
        String Konuid = extraData.getString("id");

        

        switch (Integer.parseInt(Konuid)){
            case 0:
                private static int[] images = { R.drawable.fortemelk1, R.drawable.fortemelk2, R.drawable.fortemelk3 };
                break;
            case 1:
                startActivity(new Intent(getApplicationContext(), MainActivity.class));
                break;
        }
    }
    static class TouchImageAdapter extends PagerAdapter {

        //private static int[] images = { R.drawable.fortemelk1, R.drawable.fortemelk2, R.drawable.fortemelk3 };

        @Override
        public int getCount() {
        	return images.length;
        }

        @Override
        public View instantiateItem(ViewGroup container, int position) {
            TouchImageView img = new TouchImageView(container.getContext());
            img.setImageResource(images[position]);
            container.addView(img, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
            return img;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

    }
}

 

13 Görüntülenme

4 Cevap

Sitedeki sorulara cevap verebilmek için giriş yapın ya da üye olun.

picture-87288-1481814981.jpg
aliosmanküçükk…
08.01.2017 - 03:31

Merhabalar. Sanırım probleminizi çözecektir.

public class MatematikGoster extends Activity {
	
	
	private static int[] images = { R.drawable.ic_launcher,  R.drawable.ic_launcher, R.drawable.ic_launcher };
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.matematikgoster);
		
		ExtendedViewPager mViewPager = (ExtendedViewPager) findViewById(R.id.view_pager);
        mViewPager.setAdapter(new TouchImageAdapter());

        Bundle extraData = getIntent().getExtras();
        String Konuid = extraData.getString("id");

        

        switch (Integer.parseInt(Konuid)){
            case 0:
                images =  new int[]{ R.drawable.ic_launcher,  R.drawable.ic_launcher, R.drawable.ic_launcher };
                break;
            case 1:
                startActivity(new Intent(getApplicationContext(), MainActivity.class));
                break;
        }
        
	}

	static class TouchImageAdapter extends PagerAdapter {

        

        @Override
        public int getCount() {
        	return images.length;
        }

        @Override
        public View instantiateItem(ViewGroup container, int position) {
            TouchImageView img = new TouchImageView(container.getContext());
            img.setImageResource(images[position]);
            container.addView(img, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
            return img;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

		@Override
		public boolean isViewFromObject(View arg0, Object arg1) {
			// TODO Auto-generated method stub
			return false;
		}

    }
}

 

aliosman küçükkaraaslan
08.01.2017 - 03:32
R.drawable resimlerini kendinize göre ayarlamayı unutmayın
picture-89764-1474477893.png
nurullahtayipoglu
08.01.2017 - 02:49

privatenin üzerine geldiğimde  medifier private not allowed here

static üzerine geldiğimde medifier static not allowed here

/sites/default/files/cevaplar/dosya/2020/file-hata1_3.png
picture-89764-1474477893.png
nurullahtayipoglu
08.01.2017 - 02:48

Muhammed bey bu sefer başka hata verdi

privatenin üzerine geldiğimde  medifier private not allowed here

static üzerine geldiğimde medifier static not allowed here

 


images = { R.drawable.fortemelk1, R.drawable.fortemelk2, R.drawable.fortemelk3 };
üzerine geldiğimizde  Array initalizer is not allowed here

mesajı çıkıyor

 

/sites/default/files/cevaplar/dosya/2020/file-hata_26.png
picture-15873-1477252697.png
muhammetcagatay
08.01.2017 - 01:49
public class MatematikGoster extends Activity {
	@Override
	
	int[] images ;
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.matematikgoster);
        ExtendedViewPager mViewPager = (ExtendedViewPager) findViewById(R.id.view_pager);
        mViewPager.setAdapter(new TouchImageAdapter());

        Bundle extraData = getIntent().getExtras();
        String Konuid = extraData.getString("id");

        

        switch (Integer.parseInt(Konuid)){
            case 0:
                images = { R.drawable.fortemelk1, R.drawable.fortemelk2, R.drawable.fortemelk3 };
                break;
            case 1:
                startActivity(new Intent(getApplicationContext(), MainActivity.class));
                break;
        }
    }
	
	
    class TouchImageAdapter extends PagerAdapter {

        //private static int[] images = { R.drawable.fortemelk1, R.drawable.fortemelk2, R.drawable.fortemelk3 };

        @Override
        public int getCount() {
        	return images.length;
        }

        @Override
        public View instantiateItem(ViewGroup container, int position) {
            TouchImageView img = new TouchImageView(container.getContext());
            img.setImageResource(images[position]);
            container.addView(img, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
            return img;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

    }
}

şeklinde düzenle kodu