Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid activity exception rises wen i click on proceed widout selecting a image from grid using checkbox..want to handle exception
    primarykey
    data
    text
    <p>Here's the code for ur help</p> <pre><code>public class SelectImageActivity extends Activity { private int count; private Bitmap[] thumbnails; private boolean[] thumbnailsselection; private int selectedIndices[]; private String[] arrPath; private ImageAdapter imageAdapter; String servletPath = "http://192.168.46.1:8084//ServletModule/"; GridView imagegrid; CheckBox cbPrev = null; int sel = 0; int cpSelectedStat=0; Point clickPoints[]; String accno = "", pass = "",state =""; int stat=0; TextView tv; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_select_image); Bundle extras = getIntent().getExtras(); if(extras != null){ accno = extras.getString("accno"); pass = extras.getString("pass"); state = extras.getString("state"); } selectedIndices = new int[5]; tv = (TextView)findViewById(R.id.tvSelectedItems); clickPoints = new Point[5]; showCurrentStat(); Vector&lt;MyImage&gt; imgVec = new Vector&lt;MyImage&gt;(); imgVec = (Vector&lt;MyImage&gt;)callServlet("", "FetchAllImages"); count = 20; this.thumbnails = new Bitmap[this.count]; this.thumbnailsselection = new boolean[this.count]; MyImage mi; for (int i = 0; i &lt; this.count; i++) { mi = imgVec.elementAt(i); this.thumbnails[i] = Bitmap.createBitmap(mi.ww, mi.hh, Config.ARGB_8888); this.thumbnails[i].setPixels(mi.img, 0, mi.ww, 0, 0, mi.ww, mi.hh); } imagegrid = (GridView) findViewById(R.id.PhoneImageGrid); imageAdapter = new ImageAdapter(); imagegrid.setAdapter(imageAdapter); //imagecursor.close(); final Button selectBtn = (Button) findViewById(R.id.BtnSelectImages); selectBtn.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub for(int i=0;i&lt;20;i++) thumbnailsselection[i] = false; imageAdapter = new ImageAdapter(); imagegrid.setAdapter(imageAdapter); selectedIndices[sel] = cbPrev.getId(); sel++; showCurrentStat(); if(sel == 5){ Intent ii = new Intent(v.getContext(),SelectClickPoint.class); ii.putExtra("imageindex", selectedIndices[0]); ii.putExtra("stat", 0); startActivityForResult(ii, 1); return; } } }); } @Override public void onBackPressed() { Intent iii = new Intent(SelectImageActivity.this,MainMenuActivity.class); iii.putExtra("uid", accno); iii.putExtra("pass", pass); iii.putExtra("stat", state); startActivity(iii); finish(); return; } void showCurrentStat(){ tv.setText(sel + " of 5 Images Selected!"); } Object callServlet(Object inp, String servletName){ Object ret = null; try{ String urlstr = servletPath + servletName; URL url = new URL(urlstr); URLConnection connection = url.openConnection(); connection.setDoOutput(true); connection.setDoInput(true); // don't use a cached version of URL connection connection.setUseCaches(false); connection.setDefaultUseCaches(false); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); // specify the content type that binary data is sent connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); ObjectOutputStream out = new ObjectOutputStream(connection.getOutputStream()); // send and serialize the object out.writeObject(inp); out.close(); // define a new ObjectInputStream on the input stream ObjectInputStream in = new ObjectInputStream(connection.getInputStream()); // receive and deserialize the object, note the cast ret = in.readObject(); in.close(); }catch(Exception e) { System.out.println("E:" + e); } return ret; } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub super.onActivityResult(requestCode, resultCode, data); if(resultCode == RESULT_OK){ clickPoints[cpSelectedStat] = new Point(data.getExtras().getInt("clickx"), data.getExtras().getInt("clicky")); cpSelectedStat++; if(cpSelectedStat == 5){ SingleUser u = new SingleUser(); u.accno = accno; u.pass = pass; u.gpMultiple = ""; for(int i=0;i&lt;5;i++){ u.gpMultiple += selectedIndices[i] + ","; u.gpSequence[i] = clickPoints[i].x + "," + clickPoints[i].y; } u.gpMultiple = u.gpMultiple.substring(0,u.gpMultiple.length()-1); String ret = (String)callServlet(u, "SetGraphicalPassword"); Toast.makeText(SelectImageActivity.this, "Graphical Password Set Successfully!", Toast.LENGTH_LONG).show(); finish(); state=Integer.toString(1); Intent i = new Intent(this,MainMenuActivity.class); i.putExtra("uid", u.accno); i.putExtra("pass", u.pass); i.putExtra("stat", state); startActivity(i); return; } Intent ii = new Intent(this,SelectClickPoint.class); ii.putExtra("imageindex", selectedIndices[cpSelectedStat]); ii.putExtra("stat", cpSelectedStat); startActivityForResult(ii, 1); } } public class ImageAdapter extends BaseAdapter { private LayoutInflater mInflater; public ImageAdapter() { mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); } public int getCount() { return count; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; if (convertView == null) { holder = new ViewHolder(); convertView = mInflater.inflate( R.layout.galleryitem, null); holder.imageview = (ImageView) convertView.findViewById(R.id.thumbImage); holder.checkbox = (CheckBox) convertView.findViewById(R.id.itemCheckBox); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.checkbox.setId(position); holder.imageview.setId(position); holder.checkbox.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub if(cbPrev != null){ cbPrev.setChecked(false); } cbPrev = (CheckBox) v; int id = cbPrev.getId(); cbPrev.setChecked(true); } }); holder.imageview.setImageBitmap(thumbnails[position]); holder.checkbox.setChecked(thumbnailsselection[position]); holder.id = position; return convertView; } } class ViewHolder { ImageView imageview; CheckBox checkbox; int id; } } </code></pre> <p>Want to use this Block of code to execute when checkbox is not selected and proceed button is clicked</p> <pre><code> AlertDialog ad = new AlertDialog.Builder(SelectImageActivity.this).create(); ad.setCancelable(false); ad.setMessage("Please Select an Image to proceed"); ad.setButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); ad.show(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload