Search Results

Search found 7 results on 1 pages for 'lynnooi'.

Page 1/1 | 1 

  • problem in loading images from web

    - by Lynnooi
    hi, I am new in android and had developed an app which get images from the website and display it. I got it working in emulator but not in real phones. In some device, it will crash or take very long loading period. Can anyone please help me or guide me in improving it as i'm not sure whether the way i loads the images is correct or not. Here are the code i use to get the images from the web and display accordingly. if (xmlURL.length() != 0) { try { URL url = new URL(xmlURL); SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); /* Get the XMLReader of the SAXParser we created. */ XMLReader xr = sp.getXMLReader(); /* * Create a new ContentHandler and apply it to the * XML-Reader */ xr.setContentHandler(myExampleHandler); /* Parse the xml-data from our URL. */ xr.parse(new InputSource(url.openStream())); /* Parsing has finished. */ /* * Our ExampleHandler now provides the parsed data to * us. */ ParsedExampleDataSet parsedExampleDataSet = myExampleHandler.getParsedData(); } catch (Exception e) { } } if (s.equalsIgnoreCase("wallpapers")) { Context context = helloAndroid.this.getBaseContext(); for (int j = 0; j <= myExampleHandler.filenames.size() - 1; j++) { if (myExampleHandler.filenames.elementAt(j).toString() != null) { helloAndroid.this.ed = myExampleHandler.thumbs.elementAt(j) .toString(); if (helloAndroid.this.ed.length() != 0) { Drawable image = ImageOperations(context, helloAndroid.this.ed, "image.jpg"); file_info = myExampleHandler.filenames .elementAt(j).toString(); author = "\nby " + myExampleHandler.authors.elementAt(j) .toString(); switch (j + 1) { case 1: ImageView imgView1 = new ImageView(context); imgView1 = (ImageView) findViewById(R.id.image1); if (image.getIntrinsicHeight() > 0) { imgView1.setImageDrawable(image); } else imgView1 .setImageResource(R.drawable.empty_wallpaper); tv = (TextView) findViewById(R.id.filename1); tv.setText(file_info); tv = (TextView) findViewById(R.id.author1); tv.setText(author); imgView1 .setOnClickListener(new View.OnClickListener() { public void onClick(View view) { // Perform action on click Intent myIntent1 = new Intent( helloAndroid.this, galleryFile.class); Bundle b = new Bundle(); b.putString("fileID",myExampleHandler.fileid.elementAt(0).toString()); b.putString("page", "1"); b.putString("family", s); b.putString("fi",myExampleHandler.folder_id.elementAt(folder).toString()); b.putString("kw", keyword); myIntent1.putExtras(b); startActivityForResult( myIntent1, 0); } }); break; case 2: ImageView imgView2 = new ImageView(context); imgView2 = (ImageView) findViewById(R.id.image2); imgView2.setImageDrawable(image); tv = (TextView) findViewById(R.id.filename2); tv.setText(file_info); tv = (TextView) findViewById(R.id.author2); tv.setText(author); imgView2 .setOnClickListener(new View.OnClickListener() { public void onClick(View view) { // Perform action on click Intent myIntent1 = new Intent( helloAndroid.this, galleryFile.class); Bundle b = new Bundle(); b.putString("fileID",myExampleHandler.fileid.elementAt(1).toString()); b.putString("page", "1"); b.putString("family", s); b.putString("fi",myExampleHandler.folder_id.elementAt(folder).toString()); b.putString("kw", keyword); myIntent1.putExtras(b); startActivityForResult( myIntent1, 0); } }); break; case 3: //same code break; } } } } } private Drawable ImageOperations(Context ctx, String url, String saveFilename) { try { InputStream is = (InputStream) this.fetch(url); Drawable d = Drawable.createFromStream(is, "src"); return d; } catch (MalformedURLException e) { e.printStackTrace(); return null; } catch (IOException e) { e.printStackTrace(); return null; } } public Object fetch(String address) throws MalformedURLException, IOException { URL url = new URL(address); Object content = url.getContent(); return content; }

    Read the article

  • How to call a new thread from button click

    - by Lynnooi
    Hi, I'm trying to call a thread on a button click (btn_more) but i cant get it right. The thread is to get some data and update the images. The problem i have is if i only update 4 or 5 images then it works fine. But if i load more than 5 images i will get a force close. At times when the internet is slow I will face the same problem too. Can please help me to solve this problem or provide me some guidance? Here is the error i got from LogCat: 04-19 18:51:44.907: ERROR/AndroidRuntime(1034): Uncaught handler: thread main exiting due to uncaught exception 04-19 18:51:44.927: ERROR/AndroidRuntime(1034): java.lang.NullPointerException 04-19 18:51:44.927: ERROR/AndroidRuntime(1034): at mobile9.android.gallery.GalleryWallpapers.setWallpaperThumb(GalleryWallpapers.java:383) 04-19 18:51:44.927: ERROR/AndroidRuntime(1034): at mobile9.android.gallery.GalleryWallpapers.access$4(GalleryWallpapers.java:320) 04-19 18:51:44.927: ERROR/AndroidRuntime(1034): at mobile9.android.gallery.GalleryWallpapers$1.handleMessage(GalleryWallpapers.java:266) 04-19 18:51:44.927: ERROR/AndroidRuntime(1034): at android.os.Handler.dispatchMessage(Handler.java:99) 04-19 18:51:44.927: ERROR/AndroidRuntime(1034): at android.os.Looper.loop(Looper.java:123) 04-19 18:51:44.927: ERROR/AndroidRuntime(1034): at android.app.ActivityThread.main(ActivityThread.java:4310) 04-19 18:51:44.927: ERROR/AndroidRuntime(1034): at java.lang.reflect.Method.invokeNative(Native Method) 04-19 18:51:44.927: ERROR/AndroidRuntime(1034): at java.lang.reflect.Method.invoke(Method.java:521) 04-19 18:51:44.927: ERROR/AndroidRuntime(1034): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 04-19 18:51:44.927: ERROR/AndroidRuntime(1034): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 04-19 18:51:44.927: ERROR/AndroidRuntime(1034): at dalvik.system.NativeStart.main(Native Method) My Code: public class GalleryWallpapers extends Activity implements Runnable { public static String MODEL = android.os.Build.MODEL ; private static final String rootURL = "http://www.uploadhub.com/mobile9/gallery/c/"; private int wallpapers_count = 0; private int ringtones_count = 0; private int index = 0; private int folder_id; private int page; private int page_counter = 1; private String family; private String keyword; private String xmlURL = ""; private String thread_op = "xml"; private ImageButton btn_back; private ImageButton btn_home; private ImageButton btn_filter; private ImageButton btn_search; private TextView btn_more; private ProgressDialog pd; GalleryExampleHandler myExampleHandler = new GalleryExampleHandler(); Context context = GalleryWallpapers.this.getBaseContext(); Drawable image; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); MODEL = "HTC Legend"; // **needs to be remove after testing** try { MODEL = URLEncoder.encode(MODEL,"UTF-8"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.gallerywallpapers); Bundle b = this.getIntent().getExtras(); family = b.getString("fm").trim(); folder_id = Integer.parseInt(b.getString("fi")); keyword = b.getString("kw").trim(); page = Integer.parseInt(b.getString("page").trim()); WindowManager w = getWindowManager(); Display d = w.getDefaultDisplay(); final int width = d.getWidth(); final int height = d.getHeight(); xmlURL = rootURL + "wallpapers/1/?output=rss&afm=wallpapers&mdl=" + MODEL + "&awd=" + width + "&aht=" + height; if (folder_id > 0) { xmlURL = xmlURL + "&fi=" + folder_id; } pd = ProgressDialog.show(GalleryWallpapers.this, "", "Loading...", true, false); Thread thread = new Thread(GalleryWallpapers.this); thread.start(); btn_more = (TextView) findViewById(R.id.btn_more); btn_more.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { myExampleHandler.filenames.clear(); myExampleHandler.authors.clear(); myExampleHandler.duration.clear(); myExampleHandler.fileid.clear(); btn_more.setBackgroundResource(R.drawable.btn_more_click); page = page + 1; thread_op = "xml"; xmlURL = rootURL + "wallpapers/1/?output=rss&afm=wallpapers&mdl=" + MODEL + "&awd=" + width + "&aht=" + height; xmlURL = xmlURL + "&pg2=" + page; index = 0; pd = ProgressDialog.show(GalleryWallpapers.this, "", "Loading...", true, false); Thread thread = new Thread(GalleryWallpapers.this); thread.start(); } }); } public void run() { if(thread_op.equalsIgnoreCase("xml")){ readXML(); } else if(thread_op.equalsIgnoreCase("getImg")){ getWallpaperThumb(); } handler.sendEmptyMessage(0); } private Handler handler = new Handler() { @Override public void handleMessage(Message msg) { int count = 0; if (!myExampleHandler.filenames.isEmpty()){ count = myExampleHandler.filenames.size(); } count = 6; if(thread_op.equalsIgnoreCase("xml")){ pd.dismiss(); thread_op = "getImg"; btn_more.setBackgroundResource(R.drawable.btn_more); } else if(thread_op.equalsIgnoreCase("getImg")){ setWallpaperThumb(); index++; if (index < count){ Thread thread = new Thread(GalleryWallpapers.this); thread.start(); } } } }; private void readXML(){ if (xmlURL.length() != 0) { try { /* Create a URL we want to load some xml-data from. */ URL url = new URL(xmlURL); /* Get a SAXParser from the SAXPArserFactory. */ SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); /* Get the XMLReader of the SAXParser we created. */ XMLReader xr = sp.getXMLReader(); /* * Create a new ContentHandler and apply it to the * XML-Reader */ xr.setContentHandler(myExampleHandler); /* Parse the xml-data from our URL. */ xr.parse(new InputSource(url.openStream())); /* Parsing has finished. */ /* * Our ExampleHandler now provides the parsed data to * us. */ ParsedExampleDataSet parsedExampleDataSet = myExampleHandler .getParsedData(); } catch (Exception e) { //showDialog(DIALOG_SEND_LOG); } } } private void getWallpaperThumb(){ int i = this.index; if (!myExampleHandler.filenames.elementAt(i).toString().equalsIgnoreCase("")){ image = ImageOperations(context, myExampleHandler.thumbs.elementAt(i).toString(), "image.jpg"); } } private void setWallpaperThumb(){ int i = this.index; if (myExampleHandler.filenames.elementAt(i).toString() != null) { String file_info = myExampleHandler.filenames.elementAt(i).toString(); String author = "\nby " + myExampleHandler.authors.elementAt(i).toString(); final String folder = myExampleHandler.folder_id.elementAt(folder_id).toString(); final String fid = myExampleHandler.fileid.elementAt(i).toString(); ImageView imgView = new ImageView(context); TextView tv_filename = null; TextView tv_author = null; switch (i + 1) { case 1: imgView = (ImageView) findViewById(R.id.image1); tv_filename = (TextView) findViewById(R.id.filename1); tv_author = (TextView) findViewById(R.id.author1); break; case 2: imgView = (ImageView) findViewById(R.id.image2); tv_filename = (TextView) findViewById(R.id.filename2); tv_author = (TextView) findViewById(R.id.author2); break; case 3: imgView = (ImageView) findViewById(R.id.image3); tv_filename = (TextView) findViewById(R.id.filename3); tv_author = (TextView) findViewById(R.id.author3); break; case 4: . . . . . case 10: imgView = (ImageView) findViewById(R.id.image10); tv_filename = (TextView) findViewById(R.id.filename10); tv_author = (TextView) findViewById(R.id.author10); break; } if (image.getIntrinsicHeight() > 0) { imgView.setImageDrawable(image); } else { imgView.setImageResource(R.drawable.default_wallpaper); } tv_filename.setText(file_info); tv_author.setText(author); imgView.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { // Perform action on click } }); } } private Drawable ImageOperations(Context ctx, String url, String saveFilename) { try { InputStream is = (InputStream) this.fetch(url); Drawable d = Drawable.createFromStream(is, "src"); return d; } catch (MalformedURLException e) { e.printStackTrace(); return null; } catch (IOException e) { e.printStackTrace(); return null; } } }

    Read the article

  • progress indicator

    - by Lynnooi
    Hi, Is there any way to make the progress bar into a circle shape? I have a play button in my apps and would like to show the progress of loading the song around the button.

    Read the article

  • force close when assign onclick to button

    - by Lynnooi
    hi, i am very new in android development as well as in java. i had developed an application that gets an image url from a site and wanted to download it into the device and later on i would like to enable users to set it as wallpapers. however, i am met a problem when assigning onclick event to a button. Once i uncomment the line in red, it will pop up a box stating that the application was stopped unexpectedly. Can someone please help me with this? private ImageView imView = null; public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); try { /* Create a URL we want to load some xml-data from. */ URL url = new URL(xmlURL); /* Get a SAXParser from the SAXPArserFactory. */ SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); /* Get the XMLReader of the SAXParser we created. */ XMLReader xr = sp.getXMLReader(); /* Create a new ContentHandler and apply it to the XML-Reader */ ExampleHandler myExampleHandler = new ExampleHandler(); xr.setContentHandler(myExampleHandler); /* Parse the xml-data from our URL. */ xr.parse(new InputSource(url.openStream())); /* Parsing has finished. */ /* Our ExampleHandler now provides the parsed data to us. */ ParsedExampleDataSet parsedExampleDataSet = myExampleHandler .getParsedData(); /* Set the result to be displayed in our GUI. */ if (myExampleHandler.filenames != null) { a = a + "\n" + myExampleHandler.filenames + ", by " + myExampleHandler.authors + "\nhits: " + myExampleHandler.hits + " downloads"; this.ed = myExampleHandler.thumbs; this.imageURL = myExampleHandler.mediafiles; } } catch (Exception e) { a = e.getMessage(); } // get thumbnail Context context = this.getBaseContext(); if (ed.length() != 0) { Drawable image = ImageOperations(context, this.ed, "image.jpg"); ImageView imgView = new ImageView(context); imgView = (ImageView) findViewById(R.id.image1); imgView.setImageDrawable(image); } TextView tv = (TextView) findViewById(R.id.txt_name); tv.setText(a); Button bt3 = (Button) findViewById(R.id.get_imagebt); //bt3.setOnClickListener(getImageBtnOnClick); } OnClickListener getImageBtnOnClick = new OnClickListener() { public void onClick(View view) { downloadFile(imageURL); } }; void downloadFile(String fileUrl) { URL myFileUrl = null; try { myFileUrl = new URL(fileUrl); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { HttpURLConnection conn = (HttpURLConnection) myFileUrl .openConnection(); conn.setDoInput(true); conn.connect(); int length = conn.getContentLength(); InputStream is = conn.getInputStream(); bmImg = BitmapFactory.decodeStream(is); // this.imView.setImageBitmap(bmImg); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } private Drawable ImageOperations(Context ctx, String url, String saveFilename) { try { InputStream is = (InputStream) this.fetch(url); Drawable d = Drawable.createFromStream(is, "src"); return d; } catch (MalformedURLException e) { e.printStackTrace(); return null; } catch (IOException e) { e.printStackTrace(); return null; } } public Object fetch(String address) throws MalformedURLException, IOException { URL url = new URL(address); Object content = url.getContent(); return content; } Main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/viewgroup"> <ImageView android:id="@+id/image1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" /> <ImageView android:id="@+id/image2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" /> <TextView android:id="@+id/txt_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" /> <Button id="@+id/get_imagebt" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="xxx Get an image" android:layout_gravity="center" /> <ImageView id="@+id/imview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" /> </LinearLayout>

    Read the article

  • problem with send me log

    - by Lynnooi
    Hi, I had try to implement the send me log feature into my apps but I can't get it right. Can anyone please help me with it? In the logcat, it shows the errors: 03-29 21:23:37.636: ERROR/AndroidRuntime(820): Uncaught handler: thread AsyncTask #1 exiting due to uncaught exception 03-29 21:23:37.726: ERROR/AndroidRuntime(820): java.lang.RuntimeException: An error occured while executing doInBackground() 03-29 21:23:37.726: ERROR/AndroidRuntime(820): at android.os.AsyncTask$3.done(AsyncTask.java:200) 03-29 21:23:37.726: ERROR/AndroidRuntime(820): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:234) 03-29 21:23:37.726: ERROR/AndroidRuntime(820): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:258) 03-29 21:23:37.726: ERROR/AndroidRuntime(820): at java.util.concurrent.FutureTask.run(FutureTask.java:122) 03-29 21:23:37.726: ERROR/AndroidRuntime(820): at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:648) 03-29 21:23:37.726: ERROR/AndroidRuntime(820): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:673) 03-29 21:23:37.726: ERROR/AndroidRuntime(820): at java.lang.Thread.run(Thread.java:1058) 03-29 21:23:37.726: ERROR/AndroidRuntime(820): Caused by: java.lang.NullPointerException 03-29 21:23:37.726: ERROR/AndroidRuntime(820): at resonet.android.androidgallery.helloAndroid$CheckForceCloseTask.doInBackground(helloAndroid.java:1565) 03-29 21:23:37.726: ERROR/AndroidRuntime(820): at resonet.android.androidgallery.helloAndroid$CheckForceCloseTask.doInBackground(helloAndroid.java:1) 03-29 21:23:37.726: ERROR/AndroidRuntime(820): at android.os.AsyncTask$2.call(AsyncTask.java:185) 03-29 21:23:37.726: ERROR/AndroidRuntime(820): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:256) 03-29 21:23:37.726: ERROR/AndroidRuntime(820): ... 4 more Thanks. Here is my code: public class helloAndroid extends Activity implements OnClickListener { public static final int DIALOG_SEND_LOG = 345350; protected static final int DIALOG_PROGRESS_COLLECTING_LOG = 3255; protected static final int DIALOG_FAILED_TO_COLLECT_LOGS = 3535122; private static final int DIALOG_REPORT_FORCE_CLOSE = 3535788; private LogCollector mLogCollector; public void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_NO_TITLE); Bundle b = this.getIntent().getExtras(); s = b.getString("specialValue").trim(); String xmlURL = ""; CheckForceCloseTask task = new CheckForceCloseTask(); task.execute(); } private void throwException() { throw new NullPointerException(); } @Override protected Dialog onCreateDialog(int id) { Dialog dialog = null; switch (id) { case DIALOG_SEND_LOG: case DIALOG_REPORT_FORCE_CLOSE: Builder builder = new AlertDialog.Builder(this); String message; if (id==DIALOG_SEND_LOG) message = "Do you want to send me your logs?"; else message = "It appears this app has been force-closed, do you want to report it to me?"; builder.setTitle("Warning") .setIcon(android.R.drawable.ic_dialog_alert) .setMessage(message) .setPositiveButton("Yes", this) .setNegativeButton("No", this); dialog = builder.create(); break; case DIALOG_PROGRESS_COLLECTING_LOG: ProgressDialog pd = new ProgressDialog(this); pd.setTitle("Progress"); pd.setMessage("Collecting logs..."); pd.setIndeterminate(true); dialog = pd; break; case DIALOG_FAILED_TO_COLLECT_LOGS: builder = new AlertDialog.Builder(this); builder.setTitle("Error") .setMessage("Failed to collect logs.") .setNegativeButton("OK", null); dialog = builder.create(); } return dialog; } class CheckForceCloseTask extends AsyncTask { @Override protected Boolean doInBackground(Void... params) { return mLogCollector.hasForceCloseHappened(); } @Override protected void onPostExecute(Boolean result) { if (result) { showDialog(DIALOG_REPORT_FORCE_CLOSE); } else Toast.makeText(getApplicationContext(), "No force close detected.", Toast.LENGTH_LONG).show(); } } public void onClick(DialogInterface dialog, int which) { switch (which) { case DialogInterface.BUTTON_POSITIVE: new AsyncTask() { @Override protected Boolean doInBackground(Void... params) { return mLogCollector.collect(); } @Override protected void onPreExecute() { showDialog(DIALOG_PROGRESS_COLLECTING_LOG); } @Override protected void onPostExecute(Boolean result) { dismissDialog(DIALOG_PROGRESS_COLLECTING_LOG); if (result) mLogCollector.sendLog("[email protected]", "Error Log", "Preface\nPreface line 2"); else showDialog(DIALOG_FAILED_TO_COLLECT_LOGS); } }.execute(); } dialog.dismiss(); } }

    Read the article

  • sleep/wait in android apps

    - by Lynnooi
    Hi, I had an activity which calls a thread for 10times one after another. However, if the network is slow or too much information loaded, force close will occur. Will adding sleep in each thread help to solve this problem? or is there any other ways to solve it?

    Read the article

  • android - how to cache an image from a remote site

    - by Lynnooi
    Hi, Can anyone please provide me some example on how to save an image i fetch from websites into a cache. I had try to include the following function into my code and call it once i run the activity. public void getRemoteImage(String imageUrl) { imageUrl = "http://marga.mobile9.com/download/thumb/295/sexylady7_xo6npovn.jpg"; URL aURL = null; URLConnection conn = null; Bitmap bmp = null; CacheResult cache_result = CacheManager.getCacheFile(imageUrl, new HashMap()); if (cache_result == null) { try { aURL = new URL(imageUrl); conn = aURL.openConnection(); conn.connect(); InputStream is = conn.getInputStream(); cache_result = new CacheManager.CacheResult(); CacheManager.saveCacheFile(imageUrl, cache_result); } catch (Exception e) { //return null; } } bmp = BitmapFactory.decodeStream(cache_result.getInputStream());*/ Toast.makeText(context,"Please work.. namo namo namo", Toast.LENGTH_SHORT).show(); //return bmp; } However, I got a nullPointerException. Can someone please help me with it as i'm quite new in android.

    Read the article

1