我已通过意图将我的资源 ID 传递给另一个类。然后我从意图中检索额外的内容并将其存储在一个 int 中。
现在我想让该 int 转换为视图或其他东西,以便我可以使用 getTag()?我尝试将其分配给 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);
谢谢