سؤال

new to the forum and to Android. Jet I am super starting and this forum has already been a great help.

Since I couldn't find a solution to my problem on the net, here it goes. It basically displays a Toast message:

private void registerClickCallback() {
        ListView list  = (ListView) findViewById(R.id.listViewSettings);
        list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> paret, View viewClicked, int position, long id) {

            TextView textView = (TextView) viewClicked;
            String message = "You clicked #" + position + ", which is string: " + textView.getText().toString();
            Toast.makeText(Configurations.this, message, Toast.LENGTH_SHORT.show();

            }

        });
    }

I am getting two errors from this line:

Toast.makeText(Configurations.this, message, Toast.LENGTH_SHORT.show();

Cannot invoke show() on the primitive type int Syntax error, insert ")" to complete Expression

Any ideas why ? I have used this expression just like that again with no errors...

Thanks everyone !

هل كانت مفيدة؟

المحلول

Its really simple. You forgot a ) after Toast.LENGTH_SHORT ( happens to me too ;) ). So you are calling the method show() on Toast.LENGTH_SHORT which is an integer. So your code will look like: Toast.makeText(Configurations.this, message, Toast.LENGTH_SHORT).show();

Hope I could help you!

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top