[Android Studio] plopmenz:
hello,

i have a problem with my app, i am trying to add NFC for a point system, like get points at a NFC tag.

my java.start (without links)

package plopmenzinc.nsapp;

import android.app.Activity;

import android.app.PendingIntent;

import android.content.Context;

import android.content.Intent;

import android.content.IntentFilter;

import android.content.SharedPreferences;

import android.nfc.NfcAdapter;

import android.preference.PreferenceManager;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.widget.TextView;

import android.widget.Toast;

public class Start extends AppCompatActivity {

int number = 0;

public void onClickBtn(View v)

{

TextView var = (TextView) findViewById(R.id.score);

number++;

String disp = Integer.toString(number);

var.setText(disp);

}

public class MainActivity extends Activity {

public static final String MIME_TEXT_PLAIN = "text/plain";

public static final String TAG = "NfcDemo";

private TextView mTextView;

private NfcAdapter mNfcAdapter;

[MENTION=439709]override[/MENTION]

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_start);

mNfcAdapter = NfcAdapter.getDefaultAdapter(this);

if (mNfcAdapter == null) {

// Stop here, we definitely need NFC

Toast.makeText(this, "This device doesn't support NFC.", Toast.LENGTH_LONG).show();

finish();

return;

}

if (!mNfcAdapter.isEnabled()) {

mTextView.setText("NFC is disabled.");

}

handleIntent(getIntent());

}

[MENTION=439709]override[/MENTION]

protected void onResume() {

super.onResume();

/**

* It's important, that the activity is in the foreground (resumed). Otherwise

* an IllegalStateException is thrown.

*/

setupForegroundDispatch(this, mNfcAdapter);

}

[MENTION=439709]override[/MENTION]

protected void onPause() {

/**

* Call this before onPause, otherwise an IllegalArgumentException is thrown as well.

*/

stopForegroundDispatch(this, mNfcAdapter);

super.onPause();

}

[MENTION=439709]override[/MENTION]

protected void onNewIntent(Intent intent) {

/**

* This method gets called, when a new Intent gets associated with the current activity instance.

* Instead of creating a new activity, onNewIntent will be called. For more information have a look

* at the documentation.

*

* In our case this method gets called, when the user attaches a Tag to the device.

*/

handleIntent(intent);

}

private void handleIntent(Intent intent) {

TextView var = (TextView) findViewById(R.id.score);

number++;

String disp = Integer.toString(number);

var.setText(disp);

}

/**

* [MENTION=955119]param[/MENTION] activity The corresponding {@link Activity} requesting the foreground dispatch.

* [MENTION=955119]param[/MENTION] adapter The {@link NfcAdapter} used for the foreground dispatch.

*/

public void setupForegroundDispatch(final Activity activity, NfcAdapter adapter) {

final Intent intent = new Intent(activity.getApplicationContext(), activity.getClass());

intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

final PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent, 0);

IntentFilter[] filters = new IntentFilter[1];

String[][] techList = new String[][]{};

// Notice that this is the same filter as in our manifest.

filters[0] = new IntentFilter();

filters[0].addAction(NfcAdapter.ACTION_NDEF_DISCOVERED);

filters[0].addCategory(Intent.CATEGORY_DEFAULT);

try {

filters[0].addDataType(MIME_TEXT_PLAIN);

} catch (IntentFilter.MalformedMimeTypeException e) {

throw new RuntimeException("Check your mime type.");

}

adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList);

}

public void stopForegroundDispatch(final Activity activity, NfcAdapter adapter) {

adapter.disableForegroundDispatch(activity);

}

}

}

my activity: (without links)

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="(link)"

xmlns:tools="(link)"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical"

android:paddingBottom="@dimen/activity_vertical_margin"

android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

tools:context="plopmenzinc.nsapp.Start"

android:saveEnabled="true">

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Uw aantal punten:"

android:id="@+id/textView"

android:layout_alignParentTop="true"

android:layout_alignParentLeft="true"

android:layout_alignParentStart="true"

android:layout_marginTop="50dp"

android:singleLine="true"

android:textColor="#FF2646B0"

android:textSize="22sp" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/disp"

android:id="@+id/score"

android:layout_alignBottom="@+id/textView"

android:layout_toRightOf="@+id/textView"

android:layout_toEndOf="@+id/textView"

android:textSize="22sp" />

<Button

android:id="@+id/button1"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="Add Points"

android:onClick="onClickBtn"

android:layout_marginBottom="73dp"

android:layout_alignParentBottom="true"

android:layout_centerHorizontal="true" />

</RelativeLayout>

if you need other files/scripts, just ask.

thank you :)

EDIT: removed the public class MainActivity extends Activity {} and works perfect now :)