質問編集履歴
4
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -124,7 +124,7 @@
|
|
124
124
|
|
125
125
|
E/AndroidRuntime: FATAL EXCEPTION: Thread-11563
|
126
126
|
|
127
|
-
Process: com.example.user.
|
127
|
+
Process: com.example.user.test, PID: 7454
|
128
128
|
|
129
129
|
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.nfc.Tag.hasTech(int)' on a null object reference
|
130
130
|
|
3
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -124,7 +124,7 @@
|
|
124
124
|
|
125
125
|
E/AndroidRuntime: FATAL EXCEPTION: Thread-11563
|
126
126
|
|
127
|
-
Process: com.example.
|
127
|
+
Process: com.example.user.playertest, PID: 7454
|
128
128
|
|
129
129
|
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.nfc.Tag.hasTech(int)' on a null object reference
|
130
130
|
|
2
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -59,3 +59,89 @@
|
|
59
59
|
|
60
60
|
|
61
61
|
よろしくお願いします。
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
__**追記:別threadを作成**__
|
68
|
+
|
69
|
+
```Java
|
70
|
+
|
71
|
+
public void onNewIntent(Intent intent) {
|
72
|
+
|
73
|
+
transaction(intent); //画面遷移メソッドを呼び出し
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
SuicaCheck check = new SuicaCheck();
|
78
|
+
|
79
|
+
check.start();
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
class SuicaCheck extends Thread {
|
86
|
+
|
87
|
+
public void run(){
|
88
|
+
|
89
|
+
Intent intent = new Intent();
|
90
|
+
|
91
|
+
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
|
92
|
+
|
93
|
+
Ndef ndef = Ndef.get(tag);
|
94
|
+
|
95
|
+
try {
|
96
|
+
|
97
|
+
ndef.connect();
|
98
|
+
|
99
|
+
while(ndef.isConnected()){
|
100
|
+
|
101
|
+
Toast.makeText(this, "タッチしています", Toast.LENGTH_LONG).show();
|
102
|
+
|
103
|
+
}
|
104
|
+
|
105
|
+
Toast.makeText(this, "タグが離れました", Toast.LENGTH_LONG).show();
|
106
|
+
|
107
|
+
} catch (IOException e) {
|
108
|
+
|
109
|
+
Toast.makeText(this, "エラー", Toast.LENGTH_LONG).show();
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
```
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
__実行結果__
|
120
|
+
|
121
|
+
Suicaをかざした時点でアプリ終了
|
122
|
+
|
123
|
+
エラー内容
|
124
|
+
|
125
|
+
E/AndroidRuntime: FATAL EXCEPTION: Thread-11563
|
126
|
+
|
127
|
+
Process: com.example.nishi.playertest, PID: 7454
|
128
|
+
|
129
|
+
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.nfc.Tag.hasTech(int)' on a null object reference
|
130
|
+
|
131
|
+
at android.nfc.tech.Ndef.get(Ndef.java:146)
|
132
|
+
|
133
|
+
at com.example.user.test.MainActivity$SuicaCheck.run(MainActivity.java:144)
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
MainACtivityの144行目は
|
138
|
+
|
139
|
+
```Java
|
140
|
+
|
141
|
+
Ndef ndef = Ndef.get(tag);
|
142
|
+
|
143
|
+
```
|
144
|
+
|
145
|
+
です。tagが他が正しく値を持ってこれていないのでしょうか、
|
146
|
+
|
147
|
+
onNewIntentにあった時との違いがいまいち分かりません・・・
|
1
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
|
9
9
|
かざしていたSuicaを端末から離した時に元の画面に戻りたいのです。
|
10
10
|
|
11
|
-
なお、遷移先の画面
|
11
|
+
なお、遷移先の画面はFragmentで、MainActivityの上に乗っけています。
|
12
12
|
|
13
13
|
Suicaを離した時はこの画面Bを削除することで元のMainActivityを再表示するイメージです。
|
14
14
|
|