डायनामिक ड्रॉबल नाम के आधार पर पीएनजी से छवि कैसे सेट करें?
मैं त्रुटि प्राप्त करके निम्नलिखित कोड का उपयोग करता हूं।
मेरे पास पीएनजी हैं:
R.drawable.model_1.png
R.drawable.model_2.png
... and etc
कोड
try
{
String imageName = "model_" + uv.categoryID;
int id = context.getResources().getIdentifier(imageName, "drawable", context.getPackageName());
imageView.setImageResource(id);
}
catch(Exception ex)
{
Log.e(TAG, ex);
}
त्रुटि
एक शून्य वस्तु संदर्भ पर आभासी विधि 'शून्य android.widget.ImageView.setImageResource (int)' का आह्वान करने का प्रयास
0
DmitryBoyko
21 पद 2017, 09:25
3 जवाब
सबसे बढ़िया उत्तर
इसे आज़माएं आप imageView
को बांधना भूल गए हैं।
try
{
ImageView imageView = (ImageView) findViewById(R.id.Yourimageview);
String imageName = "model_" + uv.categoryID;
int id = context.getResources().getIdentifier(imageName, "drawable", context.getPackageName());
imageView.setImageResource(id);
}
catch(Exception ex)
{
Log.e(TAG, ex);
}
1
Nilesh Rathod
21 पद 2017, 09:41
ये कोशिश करें:
try
{
ImageView imageView = (ImageView)findViewById(R.id.imageView);
int categoryID = 0;
String imageName = "model_" + categoryID;
int id = this.getResources().getIdentifier(imageName, "drawable", this.getPackageName());
imageView.setImageResource(id);
}
catch(Exception ex)
{
Log.e("NIKHIL", ex.toString());
}
2
Nikhil Lotke
21 पद 2017, 09:42
ऐसा लगता है कि आप bind
ImageView
को भूल गए हैं।
imageView = (ImageView) findViewById(R.id.image_view_id);
2
Nilesh Rathod
21 पद 2017, 09:43
संबंधित सवाल
नए सवाल
java
जावा एक उच्च स्तरीय प्रोग्रामिंग भाषा है। इस टैग का उपयोग तब करें जब आपको भाषा का उपयोग करने या समझने में समस्या हो। इस टैग का उपयोग शायद ही कभी किया जाता है और इसका उपयोग अक्सर [वसंत], [वसंत-बूट], [जकार्ता-ई], [Android], [javafx], [हडूप], [श्रेणी] और [मावेन] के साथ किया जाता है।