0

I am building an nfc read tag app. But i am unable to find set layout. problem in
setContentView(R.layout.read); and
txtRead = (TextView) findViewById(R.id.txt_read);

Here is my code:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
 try{
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.read);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.read);

     //    nfcAdapter = NfcAdapter.getDefaultAdapter(null);
     //    detectedTag =getIntent().getParcelableExtra(NfcAdapter.EXTRA_TAG);


        txtRead  = (TextView) findViewById(R.id.txt_read);

        pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, 
                new Intent(this,getClass()).
                addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

        IntentFilter tagDetected = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
        IntentFilter filter2     = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
       // readTagFilters = new IntentFilter[]{tagDetected,filter2};
        Toast.makeText(this, "no Exception caught in on create", Toast.LENGTH_LONG).show();
 }
 catch(Exception e) { Toast.makeText(this, "Exception caught in on create", Toast.LENGTH_LONG).show(); }
    }
Android Developer
  • 987
  • 1
  • 8
  • 22

1 Answers1

0

try setContentView later:

    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); 
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.read);
    setContentView(R.layout.read);

And please check your imported R. Maybe you imported android.R rather than imported a R from your package.

T D Nguyen
  • 7,054
  • 4
  • 51
  • 71