Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8627005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:09:59+00:00 2026-06-12T08:09:59+00:00

I have a very specific problem here. I wrote an app to send messages

  • 0

I have a very specific problem here. I wrote an app to send messages to NFC chips, but it keeps crashing when I press the button. The editor I use, Eclipse, doesn’t give any errors or warnings, so it’s not an error in the code.

The thing that I find very, very strange is that it crashes despite the try/catch block containing all the code. The part where it launches and checks if NFC is enabled works just fine, but pressing “Write” just makes the app crash:

the application Tag Writer (process com.harold.tag.writer) has stopped unexpectedly.

Can you guys help me out here??

if you need any other information please ask.

package com.harold.tag.writer;

import java.util.Locale;

import android.app.Activity;
import android.content.Intent;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
import android.nfc.Tag;
import android.nfc.tech.Ndef;
import android.nfc.tech.NdefFormatable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.google.common.base.Charsets;
import com.google.common.primitives.Bytes;

public class Main extends Activity implements OnClickListener {

EditText etUser;
Button bWrite;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    initialise();
}

private void initialise(){

    nfcsettings();

    etUser = (EditText)findViewById(R.id.etTag);
    bWrite = (Button)findViewById(R.id.bWrite);

    bWrite.setOnClickListener(this);

}

public void onClick(View v) {
    try
    {
        //initialize nfc part
        nfcsettings();
        Intent intent = this.getIntent();
        Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
        writeTag(tag);   
    }
    catch (Exception e){
        Toast.makeText(getBaseContext(), "Button clicking", Toast.LENGTH_SHORT).show();
    }
}

private void writeTag(Tag tag){
    try
    {
    nfcsettings();
    Locale locale = Locale.ROOT;
    final byte[] langBytes = locale.getLanguage().getBytes(Charsets.US_ASCII);
    final byte[] textBytes = etUser.toString().getBytes(Charsets.UTF_8);
    final int utfBit = 0;
    final char status = (char)(utfBit + langBytes.length);
    final byte[] data = Bytes.concat(new byte[] {(byte) status}, langBytes, textBytes);
    NdefRecord record = new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_TEXT, new byte[0], data);


        NdefRecord[] records = {record};
        NdefMessage message = new NdefMessage(records);
        Ndef ndef = Ndef.get(tag);
        if (ndef != null) {
            ndef.connect();
            ndef.writeNdefMessage(message);
        } else {
            NdefFormatable format = NdefFormatable.get(tag);
            if (format != null) {
                format.connect();
                format.format(message);
            }           
        }
    }
    catch (Exception e)
    {
        //Display toast when there is a write error
        Toast.makeText(getBaseContext(), "Tag write unsuccessful.", Toast.LENGTH_SHORT).show();
    }
}

private void nfcsettings(){

    if(!NfcAdapter.getDefaultAdapter(this).isEnabled()){
        Toast.makeText(getApplicationContext(), "Please activate NFC and press Back to return to the application!", Toast.LENGTH_LONG).show();
        startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS));
    }
}
}

EDIT: i found that my problem lies in these lines:

import com.google.common.base.Charsets;
import com.google.common.primitives.Bytes;

The imports mentioned above are apparently not exported along with the rest of the app. I have Guava 9 included in my build path, but that doesn’t do the trick… How do i include the Charsets and Bytes imports in my app???

EDIT: SOLVED!!

Turns out, adding the guavalib.jar file from the default android-sdk to my project’s lib folder does the trick.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:10:00+00:00Added an answer on June 12, 2026 at 8:10 am

    Turns out, adding the guavalib.jar file from the default android-sdk to my project’s lib folder does the trick.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very specific problem here. I have a multi-dimensional array that I
The problem that I have is somehow very specific. I have to implement a
i have a very specific problem with the mapping of an xml file to
Bear with me, this is possibly a very specific problem we've encountered here: We
I have a specific problem but the solutions are hopefully probably generic for similar
I have a very specific problem which don't seem to be asked before -
I have a very specific problem where I need to know how to swap
I have a very specific problem, and a work around solution will not help.
I have a very specific case that I need to debug. I need to
I have a very specific SSL issue on my Android. If I try to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.