-1

I have tried several methods tutorial and no one is able to solve my prob yet.I am trying it sine 2 days. My problem is when i run my custom list view program it shows error. and it is Error

enter image description here

MainActivity:

public class MainActivity extends Activity {

    ListView list;

    String[]name={

            "Al Fresco",
            "Appeliano",
            "BFC",
            "Mr. Burger",
            "Grind House",
            "Comic Cafe",
            "cafe 5Six7",
            "Cafe Cheeze Panic"
    };


    Integer[]imgid={

            R.drawable.alfresco,
            R.drawable.appeliano,
            R.drawable.bfc,
            R.drawable.burger,
            R.drawable.tbk,
            R.drawable.comiccafe,
            R.drawable.cafefivesixseven,
            R.drawable.cafecheezepanic

    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        CustomAdapter adapter=new CustomAdapter(MainActivity.this,name,imgid);

        list=(ListView)findViewById(R.id.list);
        list.setAdapter(adapter);

    }
}

And customadapter:

public class CustomAdapter extends ArrayAdapter<String> {

    private final Activity context;
    private final String[] name;
    private final Integer[]imgid;

    public CustomAdapter(Activity context,String[] name, Integer[] imgid) {
        super(context,R.layout.mylist, name);
        this.context = context;
        this.name = name;
        this.imgid = imgid;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        LayoutInflater inflater=context.getLayoutInflater();
        View rowView=inflater.inflate(R.layout.mylist,null,true);
        TextView txtTitle= (TextView) rowView.findViewById(R.id.item_name);
        ImageView imageView= (ImageView) rowView.findViewById(R.id.list_item);

        txtTitle.setText(name[position]);
        imageView.setImageResource(imgid[position]);

        return rowView;

    }
}
Bills
  • 768
  • 7
  • 19
MSI
  • 105
  • 9

2 Answers2

0

Since you haven't provide more info, with the details you provided Number one the the appleiano.png image is the one which is causing this issue.Try using another image for the time being for example the application icon and see if the project builds.

This is due to adding an image in drawable which has some extension like(.jpg) and you have changed or saved that to a .png format(this error will occur while changing the image format manually without using a Editor tool). Android studio will throws a error while compiling the resource package using AAPT(Android Asset Packaging Tool), so all you need to do is use some Image Editor tools like "gimp or paint" to save the Extension accordingly. Rebuild your project once everything is done.

Tip: if you are on mac os you can open the terminal and run the following command from images folder: 'sips -s format png *.png --out .' It will properly convert all the files with .png sufix into real PNG files

John
  • 361
  • 1
  • 11
  • Not only appeliano.png all the images are in PNG format. – MSI Nov 10 '16 at 12:12
  • Ok, So if ur having the same issue with all the png's used.Lets try disabling the cruncher in your build.gradle and please note this is not a fix, this is just to see what happens if the cruncher is disabled. android { .... aaptOptions { cruncherEnabled = false } .... } – John Nov 10 '16 at 12:30
  • so plz give me solution exact . – MSI Nov 10 '16 at 15:22
  • What happened when the cruncher was disabled?Did the project build? – John Nov 10 '16 at 15:43
0

i think you are having the same problem as mentioned in the link. try the solution which is given in this link.

Execution failed for task 'app:mergeDebugResources' Crunching Cruncher....png failed

Community
  • 1
  • 1