インテントを通じてリソース ID を別のクラスに渡しました。次に、インテントからエクストラを取得し、int に格納します。
getTag() を使用できるように、その int をビューなどに変換したいのですか? ImageView に割り当てようとしましたが、NullPointer を取得し続けました
合格した:
int resourceId = v.getId();
Intent intent = new Intent(FetchMenu.this,FetchContent.class);
intent.putExtra("ResourceId",resourceId);
startActivity(intent);
受け取った:
int id;
Intent callingIntent = getIntent();
int getView= callingIntent.getIntExtra("ResourceId", 1);
id = getView;
これはlogcatに出力されます:
System.out.println("Resource ID: " + id);
Logcat:"Resource ID: 2131099660"
これは私にNullPointerを与えています:
View v = (View)findViewById(id);
String str=(String) v.getTag();
System.out.println("Tag : " + str);
ありがとう