Question

I have some trouble getting my code to compile correctly...

Android Studio gives me an error at the line "((NdefMessage) messages[i];" with read underlining.

The console-error message says: "Constructor Message in class Message cannot be applied to given types;

Found: NdefMessage

reason: actual and formal argument lists differ in length.

When I hover over the error - It says: Message () in Message cannot be applied to (android.nfc.NdefMessage).

...

I hope someone here can explain why I get this error, and maybe what is actually wrong.

It would be cool if someone can point me in the right direction at least, as I am still new to Android Studio/Java and still learning ! :)

The code isn't something I have written. It is from a NFC example code that I grabbed online somewhere.

@Override
public void onNewIntent(Intent intent) {


    Tag tag = intent.getParcelableExtra(nfcAdapter.EXTRA_TAG);


    if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction())) {
        TextView textView = (TextView) findViewById(R.id.title);


        textView.setText("Tag Found!");


        Parcelable[] messages = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
        if (messages != null) {

            vibrate(); // signal found messages :-)

            // parse to records
            for (int i = 0; i < messages.length; i++) {
                try {
                    List <Record> records = new Message((NdefMessage) messages[i]);


                    for (int k = 0; k < records.size(); k++) {


                        Record record = records.get(k);

                        if (record instanceof AndroidApplicationRecord) {
                            AndroidApplicationRecord aar = (AndroidApplicationRecord) record;

                        }

                    }
                } catch (Exception e) {

                }

            }
        }
    } else {


        // ignore
    }

}
Was it helpful?

Solution

You problably import the wrong class of NdefMessage. You should:

import org.ndeftools.Message;

But I guess you're importing "android.nfc.NdefMessage" which is part of Android and not the NdefTools library.

Old answer:


The problem is at this line:

List <Record> records = new Message((NdefMessage) messages[i]);

You're trying to instantiate one NdefMessage (messages[i]) as a List of Records?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top