Issue
I'm trying to use object Array in my project and i get an error :
incompatible types: Object cannot be converted to String
on this line :
ST1 = new String[]{emt1, emt2, emt3, emt4};
Now i don't figure out what is the cause of this error . please help me .
Object[] ST1;
Object emt1,emt2,emt3,emt4;
private void jButton3ActionPerformed(ActionEvent evt) {
try {
emt1 = null;
emt2 = null;
emt3 = null;
emt4 = null;
ST1 = new String[]{emt1, emt2, emt3, emt4};
}
....
Solution
You have two way one is to cast every Object emt1, emt2, .. to String like this :
ST1 = new String[]{(String)emt1, (String)emt2, (String)emt3, (String)emt4};
Or you should to change the type of your attribute:
Object emt1, emt2, emt3, emt4;
To String
String emt1, emt2, emt3, emt4;
ST1 = new String[]{emt1, emt2, emt3, emt4};
Answered By - YCF_L
Answer Checked By - Clifford M. (JavaFixing Volunteer)