0

Could anyone point out the missing or incorrect line of code in my program, This is the code I'm working with. Btw thanks in advance for those who will help. This is the line of code in which the error 'Method call expected' is always popping.

 View v = layoutInflater.inflate(layouts(position),container,false); 

You can see the full code below.

import android.content.Context; import android.content.Intent; import android.support.v4.view.PagerAdapter; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; public class MainActivity extends AppCompatActivity { private Viewpager viewpager; private Intromanager intromanager; private int[] layouts; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); intromanager = new Intromanager(this); if(!intromanager.Check()) { intromanager.setFirst(false); Intent i = new Intent(MainActivity.this, Main2Activity.class); startActivity(i); finish(); } setContentView(R.layout.activity_main); layouts = new int[]{R.layout.activity_screen_1,R.layout.activity_screen_2,R.layout.activity_screen_3}; } public class ViewPagerAdapter extends PagerAdapter { private LayoutInflater layoutInflater; @Override public Object instantiateItem(ViewGroup container, int position) { layoutInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = layoutInflater.inflate(layouts(position),container,false); container.addView(v); return v; } @Override public int getCount() { return layouts.length; } @Override public boolean isViewFromObject(View view, Object object) { return view==object; } @Override public void destroyItem(ViewGroup container, int position, Object object) { View v =(View)object; container.removeView(v); } } } 
3
  • 1
    layouts is an array. You access elements of an array with square brackets, not parentheses - layouts[position]. Commented May 7, 2017 at 12:49
  • Use layouts[position] there. Commented May 7, 2017 at 12:49
  • 1
    Thanks a lot. I only just started working with java just recently. Thanks again. Commented May 7, 2017 at 12:55

1 Answer 1

0

layouts is an int array so you should put the index into the [] brackets. () is used when the user put parameter into a method.

Example:

arrayList.add(item); 

Correct code:

View v = layoutInflater.inflate(layouts[position], container, false); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.