0

i want to load group of images and text to item in list,so every item have 3 text view and group of image in viewpager , so i make java class contain methods to get and set text and images url,that is my code

updates i solve previous problem but when send array of string to projects class it gives me red underline error

public class Projects {
private String yourText = "";
private String yourstatu= "";
private String yourdes= "";
private String yourversion= "";
private String[] img;

public String getyourText () {
    return yourText ;
}

public void setyourText(String yourText) {
    this.yourText  = yourText;
}
public String getyourdescription () {
    return yourdes ;
}

public void setyourdescription( String yourdes) {
    this.yourdes  = yourdes;
}
public String getyourstatu () {
    return yourstatu ;
}

public void setyourstatu( String yourstatu) {
    this.yourstatu  = yourstatu;
}
public String getYourversion() {
    return yourversion ;
}

public void setYourversion( String yourversion) {
    this.yourversion  = yourversion;
}
public String getYourimages() {
    return new String[] img ;       // here red underline
}

public void setYourimages( String []img) {
    this.img  = img;
}

} part of my main page

mProduct.setyourText(name11);
                mProduct.setyourstatu(status);
                mProduct.setYourversion(version);
                mProduct.setyourdescription(description);
                mArrayList.add(mProduct);


                for (int i = 0; i < jreimages.length(); i++) {
                    JSONObject jjobject = jreimages.getJSONObject(i);
                    String imageid=jjobject.getString("project_id");
                    if(imageid==id){
                        String urlimage=jjobject.getString("screenshot");
                        String total=url+urlimage;
                        images[j]=total;

                    }
                    mProduct.getYourimages(images); // here underline error says getYourimages cannot be applied to java.lang,string[]

how to return array of strings ?

3
  • 2
    Read what the red underline says and check your return type Commented Mar 1, 2017 at 14:42
  • What is the error you get? Commented Mar 1, 2017 at 14:44
  • underline says "not a statement" i want to return array of strings ,is it possible? Commented Mar 1, 2017 at 14:46

1 Answer 1

1

You defined an array of Strings - String[] img, so you can just return it from your function.

Just remove new String[] and left 'img' and change the return type from String to String[]

public String[] getYourimages() {
    return img ;   
}
Sign up to request clarification or add additional context in comments.

4 Comments

ow when i try to send array of strings it refuses that by red underline if(imageid==id){ String urlimage=jjobject.getString("screenshot"); String total=url+urlimage; images[j]=total; } mProduct.getYourimages(images); // here red underline says getYourimages in projects cannot be applied to (java.lang.string[])
I'm not sure I see what the problem is, but I see that you call mProduct.getYourimages(images); but method Projects.getYourimages() accepts no arguments. Likely you wanted to call setYourimages()? So just remove argument 'images' from your call.
sorry , but i have another question when i use mproduct.setYourimages(images) ,it gives me this error " java.lang.NullPointerException: Attempt to invoke virtual method 'void commyc.example.blu_ray91111.timslinesoluation.Projects.setYourimages(java.lang.String[])' on a null object reference" the images array={"img1.sendscraps.com/se/042/004.jpg","http://…"};
Actually, it clearly says that you are trying to invoke a method .setYourimages() on a null object reference, which means that you don't have an instance of Projects class. You need to initialize the instance and assign it to the reference before any call to its reference: mProduct = new Projects() then you can call mProducts.setYourimages(images) ... These things a very basic. Anyway, Good luck!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.