1

I'm developing an app. When saving/compiling my app, I'm getting the error

Syntax error, insert ";" to complete Statement

and

Syntax error, insert ")" to complete Expression

at the bottom } here:

@Override
public void onNothingSelected(AdapterView<?> arg0) {
    // TODO Auto-generated method stub
}


}

I can't figure out why I'm getting these errors. I've looked through my code but have found no open () and no places that need a ;. My code is posted below.

Stationlist.java

public class StationList extends Activity {

    Spinner Spinner1 = (Spinner) findViewById(R.id.spinner1); 
    Spinner Spinner2 = (Spinner) findViewById(R.id.spinner2);
    String Red_Line = this.getString(R.string.Red_Line);
    String Blue_Line = this.getString(R.string.Blue_Line);
    String Green_Line = this.getString(R.string.Green_Line);
    String Orange_Line = this.getString(R.string.Orange_Line);
    String Brown_Line = this.getString(R.string.Brown_Line);
    String Pink_Line = this.getString(R.string.Pink_Line);
    String Purple_Line = this.getString(R.string.Purple_Line);
    String Yellow_Line = this.getString(R.string.Yellow_Line);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_station_list);
        // Show the Up button in the action bar.
        getActionBar().setDisplayHomeAsUpEnabled(true);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_station_list, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case android.R.id.home:
            // This ID represents the Home or Up button. In the case of this
            // activity, the Up button is shown. Use NavUtils to allow users
            // to navigate up one level in the application structure. For
            // more details, see the Navigation pattern on Android Design:
            //
            // http://developer.android.com/design/patterns/navigation.html#up-vs-back
            //
            NavUtils.navigateUpFromSameTask(this);
            return true;
        }
        return super.onOptionsItemSelected(item);


    Spinner1.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1,
                int arg2, long arg3) {
                // TODO Auto-generated method stub

                String selectedValue = arg0.getSelectedItem().toString();
                if(selectedValue.equalsIgnoreCase(Red_Line))
                {
                    ArrayAdapter<String> firstAdapter = new ArrayAdapter<String>(StationList.this,R.array.Red_Line);

                    Spinner2.setAdapter(firstAdapter);//
                }

               if(selectedValue.equalsIgnoreCase(Blue_Line))
               {
                  ArrayAdapter<String> firstAdapter = new ArrayAdapter<String>(StationList.this,R.array.Blue_Line);

                  Spinner2.setAdapter(firstAdapter);
               }
        }

    public void sendTest(View a) {
        Intent Intent9 = new Intent(StationList.this, TestStation.class);
        startActivityForResult(Intent9, 0); 
        setContentView(R.layout.test_station);
    }

    public void onBackPressed(){
        startActivity(new Intent(StationList.this, MainActivity.class));
        finish();
    }

    @Override
    public void onNothingSelected(AdapterView<?> arg0) {
        // TODO Auto-generated method stub
    }

}
}
}

I would appreciate any help you could give me on this. Thank you for your help.

7
  • What are you compiling with? Eclipse gives you a ton and a half worth of tools to go straight to these sort of compiler errors. Additionally, it will highlight {}[]() pairs. Commented Oct 1, 2013 at 0:13
  • Eclipse. But when I focus on the error, it just goes to the }, which doesn't do any good. Is there something else that I could use in Eclipse to focus down this error? @nhgrif Commented Oct 1, 2013 at 0:14
  • 3
    I hope your indentation is only that messed up because of SO. If you're in Eclipse or Netbeans, Ctrl+Shift+F to format your code and you'll probably catch the problem right away. Commented Oct 1, 2013 at 0:14
  • 1
    I'm not sure Eclipse will be able to format the code, because the structure seems meaningless. I suggest beginning at the beginning, working through making sure that braces are opened and closed at the right place. Commented Oct 1, 2013 at 0:21
  • 2
    And just so you know dude, once you fix all those compilation errors, your code will have NPE all over the place because you are using "findViewById(R.id.spinner1);" during initialization, which will return always null, the only way to get views is after setContentView has been executed... Good Luck... Commented Oct 1, 2013 at 0:38

5 Answers 5

2

Fix this method to be this:

Spinner1.setOnItemSelectedListener(new OnItemSelectedListener() {
    @Override
    public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
        // TODO Auto-generated method stub

        String selectedValue = arg0.getSelectedItem().toString();
        if(selectedValue.equalsIgnoreCase(Red_Line))
        {
            ArrayAdapter<String> firstAdapter = new ArrayAdapter<String (StationList.this,R.array.Red_Line);
            Spinner2.setAdapter(firstAdapter);//
        }

        if(selectedValue.equalsIgnoreCase(Blue_Line))
        {
            ArrayAdapter<String> firstAdapter = new ArrayAdapter<String (StationList.this,R.array.Blue_Line);

            Spinner2.setAdapter(firstAdapter);
        }
    }
});

And this method to be this:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
        // This ID represents the Home or Up button. In the case of this
        // activity, the Up button is shown. Use NavUtils to allow users
        // to navigate up one level in the application structure. For
        // more details, see the Navigation pattern on Android Design:
        //
        // http://developer.android.com/design/patterns/navigation.html#up-vs-back
        //
        NavUtils.navigateUpFromSameTask(this);
        return true;
    }
    return super.onOptionsItemSelected(item);
}

And at the end, delete two of the three closing curly braces:

Yours was this:

@Override
public void onNothingSelected(AdapterView<?> arg0) {
    // TODO Auto-generated method stub

}


}
}
}

Make it this:

    @Override
    public void onNothingSelected(AdapterView<?> arg0) {
        // TODO Auto-generated method stub
    } // this ones ends this onNothingSelected method

} // this one ends the entire class
Sign up to request clarification or add additional context in comments.

2 Comments

It tells me just to delete the } at return super.onOptionsItemSelected(item); }
@hichris123 delete two of the curly braces at the very end. I'll update my answer
0
public boolean onOptionsItemSelected

Looks like the method is never closed.... Or rather not closed at the right spot. Also the other commenter is pointing out you did not wrap new OnItemSelectedListener() { with the proper ); see his code example as well.

Comments

0

Try as,

 public class StationList extends Activity {   
    Spinner Spinner1;  
    Spinner Spinner2; 
    String Red_Line; 
    String Blue_Line; 
    String Green_Line; 
    String Orange_Line; 
    String Brown_Line; 
    String Pink_Line; 
    String Purple_Line; 
    String Yellow_Line;



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_station_list);
    // Show the Up button in the action bar.
    getActionBar().setDisplayHomeAsUpEnabled(true);
Spinner1 = (Spinner) findViewById(R.id.spinner1); 
Spinner2 = (Spinner) findViewById(R.id.spinner2);
Red_Line = this.getString(R.string.Red_Line);
Blue_Line = this.getString(R.string.Blue_Line);
Green_Line = this.getString(R.string.Green_Line);
Orange_Line = this.getString(R.string.Orange_Line);
Brown_Line = this.getString(R.string.Brown_Line);
Pink_Line = this.getString(R.string.Pink_Line);
Purple_Line = this.getString(R.string.Purple_Line);
Yellow_Line = this.getString(R.string.Yellow_Line);
  Spinner1.setOnItemSelectedListener(new OnItemSelectedListener() {
           @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1,
                    int arg2, long arg3) {
                // TODO Auto-generated method stub

                String selectedValue = arg0.getSelectedItem().toString();
                if(selectedValue.equalsIgnoreCase(Red_Line))
                {
                    ArrayAdapter<String> firstAdapter = new ArrayAdapter<String>(StationList.this,R.array.Red_Line);

                    Spinner2.setAdapter(firstAdapter);//
                }

               if(selectedValue.equalsIgnoreCase(Blue_Line))
               {
                  ArrayAdapter<String> firstAdapter = new ArrayAdapter<String>(StationList.this,R.array.Blue_Line);

                  Spinner2.setAdapter(firstAdapter);



               }



        }



});
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_station_list, menu);
    return true;
}



@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // This ID represents the Home or Up button. In the case of this
        // activity, the Up button is shown. Use NavUtils to allow users
        // to navigate up one level in the application structure. For
        // more details, see the Navigation pattern on Android Design:
        //
        // http://developer.android.com/design/patterns/navigation.html#up-vs-back
        //
        NavUtils.navigateUpFromSameTask(this);
        return true;
    }
    return super.onOptionsItemSelected(item);
}



public void sendTest(View a) {
    Intent Intent9 = new Intent(StationList.this, TestStation.class);
    startActivityForResult(Intent9, 0); 
    setContentView(R.layout.test_station);
    }






public void onBackPressed(){

startActivity(new Intent(StationList.this, MainActivity.class));
finish();
}



@Override
public void onNothingSelected(AdapterView<?> arg0) {
    // TODO Auto-generated method stub

}


}

Comments

0

Indentation issue. Try with the following solution

public class StationList extends Activity {

    Spinner Spinner1 = (Spinner) findViewById(R.id.spinner1); 
    Spinner Spinner2 = (Spinner) findViewById(R.id.spinner2);
    String Red_Line = this.getString(R.string.Red_Line);
    String Blue_Line = this.getString(R.string.Blue_Line);
    String Green_Line = this.getString(R.string.Green_Line);
    String Orange_Line = this.getString(R.string.Orange_Line);
    String Brown_Line = this.getString(R.string.Brown_Line);
    String Pink_Line = this.getString(R.string.Pink_Line);
    String Purple_Line = this.getString(R.string.Purple_Line);
    String Yellow_Line = this.getString(R.string.Yellow_Line);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_station_list);
        // Show the Up button in the action bar.
        getActionBar().setDisplayHomeAsUpEnabled(true);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_station_list, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                // This ID represents the Home or Up button. In the case of this
                // activity, the Up button is shown. Use NavUtils to allow users
                // to navigate up one level in the application structure. For
                // more details, see the Navigation pattern on Android Design:
                //
                // http://developer.android.com/design/patterns/navigation.html#up-vs-back
                //
                NavUtils.navigateUpFromSameTask(this);
                return true;
            }
        return super.onOptionsItemSelected(item);
    }

    Spinner1.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            // TODO Auto-generated method stub
            String selectedValue = arg0.getSelectedItem().toString();
            if(selectedValue.equalsIgnoreCase(Red_Line)) {
                ArrayAdapter<String> firstAdapter = new ArrayAdapter<String>(StationList.this,R.array.Red_Line);
                Spinner2.setAdapter(firstAdapter);//
            }

            if(selectedValue.equalsIgnoreCase(Blue_Line)) {
                ArrayAdapter<String> firstAdapter = new ArrayAdapter<String>(StationList.this,R.array.Blue_Line);
                Spinner2.setAdapter(firstAdapter);
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub
        }
    });

    public void sendTest(View a) {
        Intent Intent9 = new Intent(StationList.this, TestStation.class);
        startActivityForResult(Intent9, 0); 
        setContentView(R.layout.test_station);
    }

    public void onBackPressed() {
        startActivity(new Intent(StationList.this, MainActivity.class));
        finish();
    }
}

Comments

0

are you using your spinner in onOptionsItemSelectedmethod? if no then moveSpinner1.setOnItemSelectedListener(new OnItemSelectedListener() inonCreatemethod like:

// Spinner Spinner1 = (Spinner) findViewById(R.id.spinner1);
// Spinner Spinner2 = (Spinner) findViewById(R.id.spinner2);
// String Red_Line = this.getString(R.string.Red_Line);
// String Blue_Line = this.getString(R.string.Blue_Line);
// String Green_Line = this.getString(R.string.Green_Line);
// String Orange_Line = this.getString(R.string.Orange_Line);
// String Brown_Line = this.getString(R.string.Brown_Line);
// String Pink_Line = this.getString(R.string.Pink_Line);
// String Purple_Line = this.getString(R.string.Purple_Line);
// String Yellow_Line = this.getString(R.string.Yellow_Line);

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // Show the Up button in the action bar.
    getActionBar().setDisplayHomeAsUpEnabled(true);

    Spinner1.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1,
                int arg2, long arg3) {
            // TODO Auto-generated method stub

            String selectedValue = arg0.getSelectedItem().toString();
            if (selectedValue.equalsIgnoreCase(Red_Line)) {
                // ArrayAdapter<String> firstAdapter = new
                // ArrayAdapter<String>(StationList.this,R.array.Red_Line);
                //
                // Spinner2.setAdapter(firstAdapter);//
            }

            if (selectedValue.equalsIgnoreCase(Blue_Line)) {
                // ArrayAdapter<String> firstAdapter = new
                // ArrayAdapter<String>(StationList.this,R.array.Blue_Line);
                //
                // Spinner2.setAdapter(firstAdapter);

            }

        }

        public void sendTest(View a) {
            // Intent Intent9 = new Intent(StationList.this,
            // TestStation.class);
            // startActivityForResult(Intent9, 0);
            // setContentView(R.layout.test_station);
        }

        public void onBackPressed() {

            // startActivity(new Intent(StationList.this,
            // MainActivity.class));
            // finish();
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub

        }

    });
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    // getMenuInflater().inflate(R.menu.activity_station_list, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // This ID represents the Home or Up button. In the case of this
        // activity, the Up button is shown. Use NavUtils to allow users
        // to navigate up one level in the application structure. For
        // more details, see the Navigation pattern on Android Design:
        //
        // http://developer.android.com/design/patterns/navigation.html#up-vs-back
        //
        NavUtils.navigateUpFromSameTask(this);
        return true;
    }
    return super.onOptionsItemSelected(item);

}

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.