Search Results

Search found 641 results on 26 pages for 'imageview'.

Page 11/26 | < Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >

  • Reason for Null pointer Exception

    - by Rahul Varma
    Hi, I cant figure out why my program is showing null pointer exception. Plz help me...Here's the program... public class MusicListActivity extends Activity { List<HashMap<String, String>> songNodeDet = new ArrayList<HashMap<String,String>>(); HashMap<?,?>[] songNodeWeb; XMLRPCClient client; String logInSess; ArrayList<String> paths=new ArrayList<String>(); public ListAdapter adapter ; Object[] websongListObject; List<SongsList> SngList=new ArrayList<SongsList>(); Runnable r; ProgressDialog p; ListView lv; String s; @Override public void onCreate(Bundle si){ super.onCreate(si); setContentView(R.layout.openadiuofile); lv=(ListView)findViewById(R.id.list1); r=new Runnable(){ public void run(){ try{ getSongs(); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (XMLRPCException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }; Thread t=new Thread(r,"background"); t.start(); Log.e("***","process over"); } @Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); } private Runnable returnRes = new Runnable() { @Override public void run() { Log.d("handler","handler"); removeDialog(0); p.dismiss(); list(); } }; public void list() { Log.d("#####","#####"); LayoutInflater inflater=getLayoutInflater(); String[] from={}; int[] n={}; adapter=new SongsAdapter(getApplicationContext(),songNodeDet,R.layout.row,from,n,inflater); lv.setAdapter(adapter);} private Handler handler = new Handler() { public void handleMessage(Message msg){ Log.d("*****","handler"); removeDialog(0); p.dismiss(); } }; public void webObjectList(Object[] imgListObj,String logInSess) throws XMLRPCException{ songNodeWeb = new HashMap<?,?>[imgListObj.length]; if(imgListObj!=null){ Log.e("completed","completed"); for(int i=0;i<imgListObj.length;i++){ //imgListObj.length songNodeWeb[i]=(HashMap<?,?>)imgListObj[i]; String nodeid=(String) songNodeWeb[i].get("nid"); break; Log.e("img",i+"completed"); HashMap<String,String> nData=new HashMap<String,String>(); nData.put("nid",nodeid); Object nodeget=client.call("node.get",logInSess,nodeid); HashMap<?,?> imgNode=(HashMap<?,?>)nodeget; String titleName=(String) imgNode.get("titles"); String movieName=(String) imgNode.get("album"); String singerName=(String) imgNode.get("artist"); nData.put("titles", titleName); nData.put("album", movieName); nData.put("artist", singerName); Object[] imgObject=(Object[])imgNode.get("field_image"); HashMap<?,?>[] imgDetails=new HashMap<?,?>[imgObject.length]; imgDetails[0]=(HashMap<?, ?>)imgObject[0]; String path=(String) imgDetails[0].get("filepath"); if(path.contains(" ")){ path=path.replace(" ", "%20"); } String imgPath="http://www.gorinka.com/"+path; paths.add(imgPath); nData.put("path", imgPath); Log.e("my path",path); String mime=(String)imgDetails[0].get("filemime"); nData.put("mime", mime); SongsList songs=new SongsList(titleName,movieName,singerName,imgPath,imgPath); SngList.add(i,songs); songNodeDet.add(i,nData); } Log.e("paths values",paths.toString()); // return imgNodeDet; handler.sendEmptyMessage(0); } } public void getSongs() throws MalformedURLException, XMLRPCException { String ur="http://www.gorinka.com/?q=services/xmlrpc"; URL u=new URL(ur); client = new XMLRPCClient(u); //Connecting to the website HashMap<?, ?> siteConn =(HashMap<?, ?>) client.call("system.connect"); // Getting initial sessio id String initSess=(String)siteConn.get("sessid"); //Login to the site using session id HashMap<?, ?> logInConn =(HashMap<?, ?>) client.call("user.login",initSess,"prakash","stellentsoft2009"); //Getting Login sessid logInSess=(String)logInConn.get("sessid"); websongListObject =(Object[]) client.call("nodetype.get",logInSess,""); webObjectList(websongListObject,logInSess); Log.d("webObjectList","webObjectList"); runOnUiThread(returnRes); } } Here's the Adapter associated... public class SongsAdapter extends SimpleAdapter{ static List<HashMap<String,String>> songsList; Context context; LayoutInflater inflater; public SongsAdapter(Context context,List<HashMap<String,String>> imgListWeb,int layout,String[] from,int[] to,LayoutInflater inflater) { super(context,songsList,layout,from,to); this.songsList=songsList; this.context=context; this.inflater=inflater; // TODO Auto-generated constructor stub } @Override public View getView(int postition,View convertView,ViewGroup parent)throws java.lang.OutOfMemoryError{ try { View v = ((LayoutInflater) inflater).inflate(R.layout.row,null); ImageView images=(ImageView)v.findViewById(R.id.image); TextView tvTitle=(TextView)v.findViewById(R.id.text1); TextView tvAlbum=(TextView)v.findViewById(R.id.text2); TextView tvArtist=(TextView)v.findViewById(R.id.text3); HashMap<String,String> songsHash=songsList.get(postition); String path=songsHash.get("path"); String title=songsHash.get("title"); String album=songsHash.get("album"); String artist=songsHash.get("artist"); String imgPath=path; final ImageView imageView = (ImageView) v.findViewById(R.id.image); AsyncImageLoaderv asyncImageLoader=new AsyncImageLoaderv(); Bitmap cachedImage = asyncImageLoader.loadDrawable(imgPath, new AsyncImageLoaderv.ImageCallback() { public void imageLoaded(Bitmap imageDrawable, String imageUrl) { imageView.setImageBitmap(imageDrawable); } }); imageView.setImageBitmap(cachedImage); tvTitle.setText(title); tvAlbum.setText(album); tvArtist.setText(artist); return v; } catch(Exception e){ Log.e("error",e.toString()); } return null; } public static Bitmap loadImageFromUrl(String url) { InputStream inputStream;Bitmap b; try { inputStream = (InputStream) new URL(url).getContent(); BitmapFactory.Options bpo= new BitmapFactory.Options(); bpo.inSampleSize=2; b=BitmapFactory.decodeStream(inputStream, null,bpo ); return b; } catch (IOException e) { throw new RuntimeException(e); } } } Here is what logcat is showing... 04-23 16:02:02.211: ERROR/completed(1450): completed 04-23 16:02:02.211: ERROR/paths values(1450): [] 04-23 16:02:02.211: DEBUG/*****(1450): handler 04-23 16:02:02.211: DEBUG/AndroidRuntime(1450): Shutting down VM 04-23 16:02:02.211: WARN/dalvikvm(1450): threadid=3: thread exiting with uncaught exception (group=0x4001aa28) 04-23 16:02:02.222: ERROR/AndroidRuntime(1450): Uncaught handler: thread main exiting due to uncaught exception 04-23 16:02:02.241: DEBUG/webObjectList(1450): webObjectList 04-23 16:02:02.252: ERROR/AndroidRuntime(1450): java.lang.NullPointerException 04-23 16:02:02.252: ERROR/AndroidRuntime(1450): at com.stellent.gorinka.MusicListActivity$2.handleMessage(MusicListActivity.java:81) 04-23 16:02:02.252: ERROR/AndroidRuntime(1450): at android.os.Handler.dispatchMessage(Handler.java:99) 04-23 16:02:02.252: ERROR/AndroidRuntime(1450): at android.os.Looper.loop(Looper.java:123) 04-23 16:02:02.252: ERROR/AndroidRuntime(1450): at android.app.ActivityThread.main(ActivityThread.java:4203) 04-23 16:02:02.252: ERROR/AndroidRuntime(1450): at java.lang.reflect.Method.invokeNative(Native Method) 04-23 16:02:02.252: ERROR/AndroidRuntime(1450): at java.lang.reflect.Method.invoke(Method.java:521) 04-23 16:02:02.252: ERROR/AndroidRuntime(1450): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) 04-23 16:02:02.252: ERROR/AndroidRuntime(1450): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549) 04-23 16:02:02.252: ERROR/AndroidRuntime(1450): at dalvik.system.NativeStart.main(Native Method) I have declared the getter and setter methods in a seperate claa named SongsList. Plz help me determine the problem...

    Read the article

  • Getting the number of frames from a video in Android

    - by Jay Patel
    I want to get the number of frames from a video. I'm using the following code: package com.vidualtest; import java.io.File; import java.io.FileDescriptor; import android.app.Activity; import android.graphics.Bitmap; import android.media.MediaMetadataRetriever; import android.os.Bundle; import android.os.Environment; import android.widget.ImageView; public class VidualTestActivity extends Activity { /** Called when the activity is first created. */ File file; ImageView img; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); img = (ImageView) findViewById(R.id.img); File sdcard = Environment.getExternalStorageDirectory(); file = new File(sdcard, "myvid.mp4"); MediaMetadataRetriever retriever = new MediaMetadataRetriever(); try { retriever.setDataSource(file.getAbsolutePath()); img.setImageBitmap(retriever.getFrameAtTime(10000,MediaMetadataRetriever.OPTION_CLOSEST)); } catch (IllegalArgumentException ex) { ex.printStackTrace(); } catch (RuntimeException ex) { ex.printStackTrace(); } finally { try { retriever.release(); } catch (RuntimeException ex) { } } } } In getFrameAtTime() I'm passing different static time values like 10000, 20000, etc. in milliseconds, but still I'm getting the same frame from the video. My goal is to get different frames with a different time interval.

    Read the article

  • Android:How to display images from the in a ListView?

    - by Maxood
    Android:How to display images from the web in a ListView?I have the following code to display image from a URL in an ImageView: import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; import android.app.ListActivity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Bundle; import android.widget.ImageView; public class HttpImgDownload extends ListActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Bitmap bitmap = // DownloadImage( // "http://www.streetcar.org/mim/cable/images/cable-01.jpg"); DownloadImage( "http://s.twimg.com/a/1258674567/images/default_profile_3_normal.png"); ImageView img = (ImageView) findViewById(R.id.img); img.setImageBitmap(bitmap); } private InputStream OpenHttpConnection(String urlString) throws IOException { InputStream in = null; int response = -1; URL url = new URL(urlString); URLConnection conn = url.openConnection(); if (!(conn instanceof HttpURLConnection)) throw new IOException("Not an HTTP connection"); try{ HttpURLConnection httpConn = (HttpURLConnection) conn; httpConn.setAllowUserInteraction(false); httpConn.setInstanceFollowRedirects(true); httpConn.setRequestMethod("GET"); httpConn.connect(); response = httpConn.getResponseCode(); if (response == HttpURLConnection.HTTP_OK) { in = httpConn.getInputStream(); } } catch (Exception ex) { throw new IOException("Error connecting"); } return in; } private Bitmap DownloadImage(String URL) { Bitmap bitmap = null; InputStream in = null; try { in = OpenHttpConnection(URL); bitmap = BitmapFactory.decodeStream(in); in.close(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } return bitmap; } } Now how can i display images in an array in a listview? Here's how i want to display the images: http://sites.google.com/site/androideyecontact/_/rsrc/1238086823282/Home/android-eye-contact-lite/eye_contact-list_view_3.png?height=420&width=279

    Read the article

  • Load image in device independent and screen independent fashion into a layout view using 1.6 SDK

    - by Mark Wigzell
    I'm having trouble getting an asset image to scale up when I load it. The new call to BitmapDrawable(Resources, BitmapDrawable) is not available on 1.6 SDK. Is there a workaround to load the BitmapDrawable the old way and then somehow manipulate it? I have tried calling setTargetDensity() to no avail. My code (which doesn't scale properly) is: ImageView iv = (ImageView)view.findViewById(R.id.image); iv.setImageDrawable(new BitmapDrawable(view.getContext().getAssets().open(path)));

    Read the article

  • Animate move and scale of image UIButton

    - by Sam V
    I want it to be animated so I'm using [UIView beginAnimations] I've tried animating using button.imageView.frame (with image set as imageView) but it only animates the position, the image doesn't get scaled down at all. using hateButton.frame (when image is set as backgroundImage), the backgroundImage gets scaled down but it's not animated. How do I animate-scale a UIButton image?

    Read the article

  • Unable to stretch TableLayout to screen width

    - by Rendrik
    I've tried unsuccessfully for quite a few hours now to simply get a TableLayout to scale to the full screen. I've tried stretchColumns, shrinkColumns, (specifying the column index or using *) you name it. It's almost as if the parent element (TableLayout) is completely ignoring 'android:layout_width="fill_parent"'. I've read through similar questions here, though they haven't solved it for me. The XML below has 3 rows, and the table always shrink wraps to the size of the content. Apparently I'm too new to post pictures(?) Here is the XML rendered into the project i'm working on. http://www.dashiva.com/images/Capture.png What am I missing here, it's quite frustrating! <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="*"> <TableRow> <TextView android:id="@+id/AmountText" android:text="@string/general_amount" android:paddingRight="8dip" android:layout_gravity="center"></TextView> <TextView android:id="@+id/CardText" android:text="@string/general_card" android:paddingRight="8dip" android:layout_gravity="center"></TextView> <TextView android:text="@string/general_date" android:id="@+id/DateText" android:paddingRight="8dip" android:layout_gravity="center"></TextView> <TextView android:id="@+id/ErrorText" android:text="@string/general_error" android:paddingRight="8dip" android:layout_gravity="center"></TextView> </TableRow> <TableRow> <TextView android:text="Amount here..." android:id="@+id/AmountNum" android:paddingRight="8dip" android:layout_gravity="center"></TextView> <TextView android:id="@+id/CardNum" android:text="Num here..." android:paddingRight="8dip" android:layout_gravity="center"></TextView> <TextView android:text="date here..." android:id="@+id/DateDate" android:paddingRight="8dip" android:layout_gravity="center"></TextView> <TextView android:text="Code here..." android:id="@+id/ErrorCode" android:paddingRight="8dip" android:layout_gravity="center"></TextView> </TableRow> <TableRow> <ImageView android:id="@+id/cc_image" android:src="@drawable/mastercard" android:background="@drawable/row_bg2" android:layout_gravity="center" android:layout_weight="1"></ImageView> <TextView android:id="@+id/ResponseText" android:layout_span="4" android:text="Response text here..." android:textSize="18dip" android:layout_weight="1"></TextView> </TableRow> <ImageView android:layout_gravity="center_vertical" android:background="@drawable/gradient_bg" android:layout_height="3dip" android:layout_width="fill_parent"></ImageView> </TableLayout>

    Read the article

  • Ho to stop scrolling in a Gallery Widget?

    - by Alexi
    I loaded some images into a gallery. Now I'm able to scroll but once started scrolling the scrolling won't stop. I would like the gallery to just scroll to the next image and then stop until the user does the scroll gesture again. this is my code import android.widget.ImageView; import android.widget.Toast; import android.widget.AdapterView.OnItemClickListener; public class GalleryExample extends Activity { private Gallery gallery; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); gallery = (Gallery) findViewById(R.id.examplegallery); gallery.setAdapter(new AddImgAdp(this)); gallery.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView parent, View v, int position, long id) { Toast.makeText(GalleryExample.this, "Position=" + position, Toast.LENGTH_SHORT).show(); } }); } public class AddImgAdp extends BaseAdapter { int GalItemBg; private Context cont; private Integer[] Imgid = { R.drawable.a_1, R.drawable.a_2, R.drawable.a_3, R.drawable.a_4, R.drawable.a_5, R.drawable.a_6, R.drawable.a_7 }; public AddImgAdp(Context c) { cont = c; TypedArray typArray = obtainStyledAttributes(R.styleable.GalleryTheme); GalItemBg = typArray.getResourceId(R.styleable.GalleryTheme_android_galleryItemBackground, 0); typArray.recycle(); } public int getCount() { return Imgid.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View convertView, ViewGroup parent) { ImageView imgView = new ImageView(cont); imgView.setImageResource(Imgid[position]); i.setScaleType(ImageView.ScaleType.FIT_CENTER); imgView.setBackgroundResource(GalItemBg); return imgView; } } } and the xmlLayout file <?xml version="1.0" encoding="utf-8"?> <LinearLayout android:id="@+id/LinearLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" > <Gallery xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/examplegallery" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </LinearLayout>

    Read the article

  • Android - Custom Icons in ListView

    - by Ryan
    Is there any way to place a custom icon for each group item? Like for phone I'd like to place a phone, for housing I'd like to place a house. Here is my code, but it keeps throwing a Warning and locks up on me. ListView myList = (ListView) findViewById(R.id.myList); //ExpandableListAdapter adapter = new MyExpandableListAdapter(data); List<Map<String, Object>> groupData = new ArrayList<Map<String, Object>>(); Iterator it = data.entrySet().iterator(); while (it.hasNext()) { //Get the key name and value for it Map.Entry pair = (Map.Entry)it.next(); String keyName = (String) pair.getKey(); String value = pair.getValue().toString(); //Add the parents -- aka main categories Map<String, Object> curGroupMap = new HashMap<String, Object>(); groupData.add(curGroupMap); if (value == "Phone") curGroupMap.put("ICON", findViewById(R.drawable.phone)); else if (value == "Housing") curGroupMap.put("NAME", keyName); curGroupMap.put("VALUE", value); } // Set up our adapter mAdapter = new SimpleAdapter( mContext, groupData, R.layout.exp_list_parent, new String[] { "ICON", "NAME", "VALUE" }, new int[] { R.id.iconImg, R.id.rowText1, R.id.rowText2 } ); myList.setAdapter(mAdapter); The error i'm getting: 05-28 17:36:21.738: WARN/System.err(494): java.io.IOException: Is a directory 05-28 17:36:21.809: WARN/System.err(494): at org.apache.harmony.luni.platform.OSFileSystem.readImpl(Native Method) 05-28 17:36:21.838: WARN/System.err(494): at org.apache.harmony.luni.platform.OSFileSystem.read(OSFileSystem.java:158) 05-28 17:36:21.851: WARN/System.err(494): at java.io.FileInputStream.read(FileInputStream.java:319) 05-28 17:36:21.879: WARN/System.err(494): at java.io.BufferedInputStream.fillbuf(BufferedInputStream.java:183) 05-28 17:36:21.908: WARN/System.err(494): at java.io.BufferedInputStream.read(BufferedInputStream.java:346) 05-28 17:36:21.918: WARN/System.err(494): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method) 05-28 17:36:21.937: WARN/System.err(494): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:459) 05-28 17:36:21.948: WARN/System.err(494): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:271) 05-28 17:36:21.958: WARN/System.err(494): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:296) 05-28 17:36:21.978: WARN/System.err(494): at android.graphics.drawable.Drawable.createFromPath(Drawable.java:801) 05-28 17:36:21.988: WARN/System.err(494): at android.widget.ImageView.resolveUri(ImageView.java:501) 05-28 17:36:21.998: WARN/System.err(494): at android.widget.ImageView.setImageURI(ImageView.java:289) Thanks in advance for your help!!

    Read the article

  • png image store in database and retrieve in android 1.5

    - by hany
    hai, I am new to android. I have problem. This is my code but it will not work, the problem is in view binder. Please correct it. // this is my activity package com.android.Fruits2; import java.util.ArrayList; import java.util.HashMap; import android.app.ListActivity; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Bundle; import android.widget.SimpleAdapter; import android.widget.SimpleCursorAdapter; import android.widget.SimpleAdapter.ViewBinder; public class Fruits2 extends ListActivity { private DBhelper mDB; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // setContentView(R.layout.main); mDB = new DBhelper(this); mDB.Reset(); Bitmap img = BitmapFactory.decodeResource(getResources(), R.drawable.icon); mDB.createPersonEntry(new PersonData(img, "Harsha", 24,"mca")); String[] columns = {mDB.KEY_ID, mDB.KEY_IMG, mDB.KEY_NAME, mDB.KEY_AGE, mDB.KEY_STUDY}; String table = mDB.PERSON_TABLE; Cursor c = mDB.getHandle().query(table, columns, null, null, null, null, null); startManagingCursor(c); SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.data, c, new String[] {mDB.KEY_IMG, mDB.KEY_NAME, mDB.KEY_AGE, mDB.KEY_STUDY}, new int[] {R.id.img, R.id.name, R.id.age,R.id.study}); adapter.setViewBinder( new MyViewBinder()); setListAdapter(adapter); } } //my viewbinder package com.android.Fruits2; import android.database.Cursor; import android.graphics.BitmapFactory; import android.view.View; import android.widget.ImageView; import android.widget.SimpleCursorAdapter; public class MyViewBinder implements SimpleCursorAdapter.ViewBinder { public boolean setViewValue(View view, Cursor cursor, int columnIndex) { if( (view instanceof ImageView) ) { ImageView iv = (ImageView) view; byte[] img = cursor.getBlob(columnIndex); iv.setImageBitmap(BitmapFactory.decodeByteArray(img, 0, img.length)); return true; } return false; } } // data package com.android.Fruits2; import android.graphics.Bitmap; public class PersonData { private Bitmap bmp; private String name; private int age; private String study; public PersonData(Bitmap b, String n, int k, String v) { bmp = b; name = n; age = k; study = v; } public Bitmap getBitmap() { return bmp; } public String getName() { return name; } public int getAge() { return age; } public String getStudy() { return study; } } //dbhelper package com.android.Fruits2; import java.io.ByteArrayOutputStream; import android.content.ContentValues; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.graphics.Bitmap; import android.provider.BaseColumns; public class DBhelper { public static final String KEY_ID = BaseColumns._ID; public static final String KEY_NAME = "name"; public static final String KEY_AGE = "age"; public static final String KEY_STUDY = "study"; public static final String KEY_IMG = "image"; private DatabaseHelper mDbHelper; private SQLiteDatabase mDb; private static final String DATABASE_NAME = "PersonalDB"; private static final int DATABASE_VERSION = 1; public static final String PERSON_TABLE = "Person"; private static final String CREATE_PERSON_TABLE = "create table "+PERSON_TABLE+" (" +KEY_ID+" integer primary key autoincrement, " +KEY_IMG+" blob not null, " +KEY_NAME+" text not null , " +KEY_AGE+" integer not null, " +KEY_STUDY+" text not null);"; private final Context mCtx; private boolean opened = false; private static class DatabaseHelper extends SQLiteOpenHelper { DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } public void onCreate(SQLiteDatabase db) { db.execSQL(CREATE_PERSON_TABLE); } public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLE IF EXISTS "+PERSON_TABLE); onCreate(db); } } public void Reset() { openDB(); mDbHelper.onUpgrade(this.mDb, 1, 1); closeDB(); } public DBhelper(Context ctx) { mCtx = ctx; mDbHelper = new DatabaseHelper(mCtx); } private SQLiteDatabase openDB() { if(!opened) mDb = mDbHelper.getWritableDatabase(); opened = true; return mDb; } public SQLiteDatabase getHandle() { return openDB(); } private void closeDB() { if(opened) mDbHelper.close(); opened = false; } public void createPersonEntry(PersonData about) { openDB(); ByteArrayOutputStream out = new ByteArrayOutputStream(); about.getBitmap().compress(Bitmap.CompressFormat.PNG, 100, out); ContentValues cv = new ContentValues(); cv.put(KEY_IMG, out.toByteArray()); cv.put(KEY_NAME, about.getName()); cv.put(KEY_AGE, about.getAge()); cv.put(KEY_STUDY, about.getStudy()); mDb.insert(PERSON_TABLE, null, cv); closeDB(); } } //data.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="wrap_content"> <ImageView android:id = "@+id/img" android:layout_width = "wrap_content" android:layout_height = "wrap_content" > </ImageView> <TextView android:id = "@+id/name" android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:textSize="15dp" android:textColor="#ff0000" > </TextView> <TextView android:id = "@+id/age" android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:textSize="15dp" android:textColor="#ff0000" /> <TextView android:id = "@+id/study" android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:textSize="15dp" android:textColor="#ff0000" /> </LinearLayout> When I run this in android 1.6 and 2.1, it works. But when I run in android 1.5, not work. My application is android 1.5. Please correct and send code to me. Thank you.

    Read the article

  • ListActivity problem when using with RelativeLayout

    - by tomgamer
    Newb alert, I'm sure I'm doing something dumb here. I've been progressively expanding my UI, and I want to add a ListView in the middle of my UI. When I add it and change the activity to extend a ListActivity instead of just an Activity, I'm getting a Force Close. Using 1.5. Does a ListView not work embedded in a RelativeLayout? Thanks public class Categories extends ListActivity{ final static String[] ITEMS = {"blah", "floop", "gnarlp", "stuff"}; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.categories); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.listrow, R.id.textview, ITEMS); setListAdapter(adapter); XML looks like this: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout android:id="@+id/RelativeLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <ImageView android:id="@+id/ImageView01" android:layout_height="fill_parent" android:layout_width="fill_parent" android:scaleType="center" android:background="@drawable/background"> </ImageView> <ImageView android:id="@+id/ImageView02" android:src="@drawable/cat_heading" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_centerHorizontal="true"> </ImageView> <ListView android:id="@+id/ListView01" android:layout_below="@id/ImageView02" android:layout_width="wrap_content" android:layout_height="wrap_content"></ListView> <RelativeLayout android:id="@+id/RelativeLayout02" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignBottom="@+id/RelativeLayout01" android:layout_centerHorizontal="true"> <ImageButton android:id="@+id/ImageButtonRecipes" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:src="@drawable/recipes"></ImageButton> <ImageButton android:id="@+id/ImageButtonSearch" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_toRightOf="@+id/ImageButtonRecipes" android:src="@drawable/search"></ImageButton> </RelativeLayout> </RelativeLayout> and the listrow.xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textview"/> </LinearLayout>

    Read the article

  • How to add Listview in tab activity?

    - by sandip armal
    I have one "SubjectTabActivity" and i need to show listview on this activity. But when i want to implement ListActivity it doesn't show listActivity. I have two(addchapter,addsubject) xml file with "SubjectTabActivity". and i need to show my database item il list view in respective xml file. but i don't understand how to do that? How to add Listactivity in TabActivity?. Please give me any reference or code. Thanks in advance.. Here is my reference code. public class MasterMainActivity extends TabActivity { LayoutInflater layoutInflater = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.master); Intent intent=getIntent(); setResult(RESULT_OK, intent); layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); TabHost tabHost = getTabHost(); TabHost.TabSpec tab1spec = tabHost.newTabSpec("tabOneSpec"); ImageView imgView = new ImageView(this); imgView.setBackgroundResource(R.drawable.subject); tab1spec.setIndicator("Subject", imgView.getBackground()); tab1spec.setContent(new TabContentLayout()); TabHost.TabSpec tab2spec = tabHost.newTabSpec("tabTwoSpec"); tab2spec.setContent(new TabContentLayout()); ImageView imgView1 = new ImageView(this); imgView1.setBackgroundResource(R.drawable.chapter); tab2spec.setIndicator("Chapter", imgView1.getBackground()); tabHost.addTab(tab1spec); tabHost.addTab(tab2spec); } private class TabContentLayout implements TabHost.TabContentFactory { @Override public View createTabContent(String tag) { View view = null; if(tag.equals("tabOneSpec")) { try { //static final String[] FRUITS = new String[] { "Apple", "Avocado", "Banana", // "Blueberry", "Coconut", "Durian", "Guava", "Kiwifruit", //"Jackfruit", "Mango", "Olive", "Pear", "Sugar-apple" }; view = (LinearLayout) layoutInflater.inflate(R.layout.subjecttabview, null); //setListAdapter(new ArrayAdapter<String>(this, R.layout.subjecttabview,FRUITS)); } catch(Exception e) { e.printStackTrace(); } } if(tag.equals("tabTwoSpec")) { try { view = (LinearLayout) layoutInflater.inflate(R.layout.chaptertabview, null); } catch(Exception e) { e.printStackTrace(); } } return view; } } How to add ListActivity in this TabActivity

    Read the article

  • Web image loaded by thread in android

    - by Bostjan
    I have an extended BaseAdapter in a ListActivity: private static class RequestAdapter extends BaseAdapter { and some handlers and runnables defined in it // Need handler for callbacks to the UI thread final Handler mHandler = new Handler(); // Create runnable for posting final Runnable mUpdateResults = new Runnable() { public void run() { loadAvatar(); } }; protected static void loadAvatar() { // TODO Auto-generated method stub //ava.setImageBitmap(getImageBitmap("URL"+pic)); buddyIcon.setImageBitmap(avatar); } In the getView function of the Adapter, I'm getting the view like this: if (convertView == null) { convertView = mInflater.inflate(R.layout.messageitem, null); // Creates a ViewHolder and store references to the two children views // we want to bind data to. holder = new ViewHolder(); holder.username = (TextView) convertView.findViewById(R.id.username); holder.date = (TextView) convertView.findViewById(R.id.dateValue); holder.time = (TextView) convertView.findViewById(R.id.timeValue); holder.notType = (TextView) convertView.findViewById(R.id.notType); holder.newMsg = (ImageView) convertView.findViewById(R.id.newMsg); holder.realUsername = (TextView) convertView.findViewById(R.id.realUsername); holder.replied = (ImageView) convertView.findViewById(R.id.replied); holder.msgID = (TextView) convertView.findViewById(R.id.msgID_fr); holder.avatar = (ImageView) convertView.findViewById(R.id.buddyIcon); holder.msgPreview = (TextView) convertView.findViewById(R.id.msgPreview); convertView.setTag(holder); } else { // Get the ViewHolder back to get fast access to the TextView // and the ImageView. holder = (ViewHolder) convertView.getTag(); } and the image is getting loaded this way: Thread sepThread = new Thread() { public void run() { String ava; ava = request[8].replace(".", "_micro."); Log.e("ava thread",ava+", username: "+request[0]); avatar = getImageBitmap(URL+ava); buddyIcon = holder.avatar; mHandler.post(mUpdateResults); //holder.avatar.setImageBitmap(getImageBitmap(URL+ava)); } }; sepThread.start(); Now, the problem I'm having is that if there are more items that need to display the same picture, not all of those pictures get displayed. When you scroll up and down the list maybe you end up filling all of them. When I tried the commented out line (holder.avatar.setImageBitmap...) the app sometimes force closes with "only the thread that created the view can request...". But only sometimes. Any idea how I can fix this? Either option.

    Read the article

  • Setting custom UITableViewCells height

    - by Vijayeta
    I am using a custum UITableViewCell , which has some labels , buttons imageviews to be displayed.There is one label in the cell whose text is a NSString object and the length of string could be variable , due to this i cannot set a constant height to the cell in UITableViews : heightForCellAtIndex method.The ceels height depends on the labels height , whcich can be determined using the NSStrings sizeWithFont method . i tried using it , but looks like i m going wrong somewhere . Can anyone help me out in this , adding the code used in iniatilizing the cell if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) { self.selectionStyle = UITableViewCellSelectionStyleNone; UIImage *image = [UIImage imageNamed:@"dot.png"]; imageView = [[UIImageView alloc] initWithImage:image]; imageView.frame = CGRectMake(45.0,10.0,10,10); headingTxt = [[UILabel alloc] initWithFrame: CGRectMake(60.0,0.0,150.0,post_hdg_ht)]; [headingTxt setContentMode: UIViewContentModeCenter]; headingTxt.text = postData.user_f_name; headingTxt.font = [UIFont boldSystemFontOfSize:13]; headingTxt.textAlignment = UITextAlignmentLeft; headingTxt.textColor = [UIColor blackColor]; dateTxt = [[UILabel alloc] initWithFrame:CGRectMake(55.0,23.0,150.0,post_date_ht)]; dateTxt.text = postData.created_dtm; dateTxt.font = [UIFont italicSystemFontOfSize:11]; dateTxt.textAlignment = UITextAlignmentLeft; dateTxt.textColor = [UIColor grayColor]; NSString * text1 = postData.post_body; NSLog(@"text length = %d",[text1 length]); CGRect bounds = [UIScreen mainScreen].bounds; CGFloat tableViewWidth; CGFloat width = 0; tableViewWidth = bounds.size.width/2; width = tableViewWidth - 40; //fudge factor //CGSize textSize = {width, 20000.0f}; //width and height of text area CGSize textSize = {245.0, 20000.0f}; //width and height of text area CGSize size1 = [text1 sizeWithFont:[UIFont systemFontOfSize:11.0f] constrainedToSize:textSize lineBreakMode:UILineBreakModeWordWrap]; CGFloat ht = MAX(size1.height, 28); textView = [[UILabel alloc] initWithFrame:CGRectMake(55.0,42.0,245.0,ht)]; textView.text = postData.post_body; textView.font = [UIFont systemFontOfSize:11]; textView.textAlignment = UITextAlignmentLeft; textView.textColor = [UIColor blackColor]; textView.lineBreakMode = UILineBreakModeWordWrap; textView.numberOfLines = 3; textView.autoresizesSubviews = YES; [self.contentView addSubview:imageView]; [self.contentView addSubview:textView]; [self.contentView addSubview:webView]; [self.contentView addSubview:dateTxt]; [self.contentView addSubview:headingTxt]; [self.contentView sizeToFit]; [imageView release]; [textView release]; [webView release]; [dateTxt release]; [headingTxt release]; } textView = [[UILabel alloc] initWithFrame:CGRectMake(55.0,42.0,245.0,ht)]; this is the label whose height and widh are going wrong

    Read the article

  • How to put overlay NSImageView and keep it at the top of a WebView?

    - by frankish
    How to put overlay view (NSImageView) and keep it at the top in front of a WebView ( which runs core animation or )? Standard ordering in interface builder does not help.. imageview is shown in front of the webview but when i load the contents of webview with a tag or only just an html opacity animation, suddently webview takeovers the top position and shows over the imageview. Can't i do this?

    Read the article

  • Displaying an Image in an activity using URI

    - by evkwan
    Hi, I'm writing an application that uses Intent(MediaStore.ACTION_IMAGE_CAPTURE) to capture and image. On the process of capturing the image, I noted the output of the image's URI. Right after finishing the camera activity, I wish to display the image using this specific URI. The method I used to capture images is: private void saveFullImage() { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File file = new File(Environment.getExternalStorageDirectory(), "test.jpg"); outputFileUri = Uri.fromFile(file); intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); startActivityForResult(intent, TAKE_PICTURE); } Which is a method taken from Reto Meier's book Professional Android 2 Application Development. The method works fine, and I assume that the URI of the picture I just took is stored in the outputFileUri variable. Then at this point of the code is where I want to display the picture: @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == TAKE_PICTURE) { //I want to display the picture I just took here //using the URI } } I'm not sure how to do it. I tried creating a new layout object and a new ImageView object using the method setImageURI(outputFileUri). My main layout (xml) did not have a ImageView object. But even when I set the contentView to the new layout with the ImageView attached to it, it doesn't display anything. I tried creating a Bitmap object from the URI and set it to the ImageView, but I get an unexpected error and forced exit. I have seen examples from here here which creates a Bitmap from URI, but it's not displaying it? My question is just how to display an image in the middle of a running activity? Do I need to get the File Path (like this) in order to display it? If I make a Bitmap out of the URI, how do I display the Bitmap? I'm just probably missing something simple...so any help would be a greatly appreciated! Also additional question for thought: If I were to take multiple pictures, would you recommend me to use the SimpleCursorAdapter instead? Thanks!

    Read the article

  • imagePickerController won't return camera photo. Will return album photo.

    - by yesimarobot
    i'm loading photos from my library just fine, but photos coming from he camera don't display in the imageView. I've used CFShow(info) and the data from the camera is not nil... - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { UIImage *image = [info objectForKey:@"UIImagePickerControllerEditedImage"]; [self.imageView setImage:image]; [self dismissModalViewControllerAnimated:YES]; [picker release]; }

    Read the article

  • Draw points in a view on iPhone screen?

    - by micropsari
    Hello, in my class I have an attribute IBOutlet UIImageView *imageView; And if I want to draw an image in this view I do : imageView.image = [UIImage imageNamed:@"foo.png"]; But how can I do to draw some points with coordinate x, y (in pixel) directly in the view ? Thanks !

    Read the article

  • android.view.InflateException: Binary XML file line #11

    - by kostas
    i have a listview with some items.when the user touch the first list item it starts a dialog activity with a photo and some text below.that happens for every list item.but unfortunately i m getting this android.view.InflateException: Binary XML file line #11 force down error..this is a part of my manifest: <activity android:name=".kalamaki" android:label="Beaches in Chania" android:screenOrientation="portrait" android:configChanges="orientation|keyboardHidden" android:theme="@android:style/Theme.Dialog" /> this is my .xml file: <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#cfcfcc" > <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ImageView android:layout_marginTop="5px" android:id="@+id/image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@+id/image" /> <TextView android:layout_marginTop="5px" android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@+id/text" android:textColor="#262626" /> </LinearLayout> </ScrollView> and this is my logcat error: 04-30 19:08:34.433: ERROR/AndroidRuntime(405): Uncaught handler: thread main exiting due to uncaught exception 04-30 19:08:34.463: ERROR/AndroidRuntime(405): java.lang.RuntimeException: Unable to start activity ComponentInfo{kostas.menu.chania/kostas.menu.chania.sfinari}: android.view.InflateException: Binary XML file line #11: Error inflating class <unknown> 04-30 19:08:34.463: ERROR/AndroidRuntime(405): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2454) 04-30 19:08:34.463: ERROR/AndroidRuntime(405): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2470) 04-30 19:08:34.463: ERROR/AndroidRuntime(405): at android.app.ActivityThread.access$2200(ActivityThread.java:119) 04-30 19:08:34.463: ERROR/AndroidRuntime(405): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821) 04-30 19:08:34.463: ERROR/AndroidRuntime(405): at android.os.Handler.dispatchMessage(Handler.java:99) 04-30 19:08:34.463: ERROR/AndroidRuntime(405): at android.os.Looper.loop(Looper.java:123) 04-30 19:08:34.463: ERROR/AndroidRuntime(405): at android.app.ActivityThread.main(ActivityThread.java:4310) 04-30 19:08:34.463: ERROR/AndroidRuntime(405): at java.lang.reflect.Method.invokeNative(Native Method) 04-30 19:08:34.463: ERROR/AndroidRuntime(405): at java.lang.reflect.Method.invoke(Method.java:521) 04-30 19:08:34.463: ERROR/AndroidRuntime(405): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 04-30 19:08:34.463: ERROR/AndroidRuntime(405): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 04-30 19:08:34.463: ERROR/AndroidRuntime(405): at dalvik.system.NativeStart.main(Native Method) 04-30 19:08:34.463: ERROR/AndroidRuntime(405): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class <unknown> 04-30 19:08:34.463: ERROR/AndroidRuntime(405): at android.view.LayoutInflater.createView(LayoutInflater.java:513) 04-30 19:08:34.463: ERROR/AndroidRuntime(405): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 04-30 19:08:34.463: ERROR/AndroidRuntime(405): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563) 04-30 19:08:34.463: ERROR/AndroidRuntime(405): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618) 04-30 19:08:34.463: ERROR/AndroidRuntime(405): at android.view.LayoutInflater.rInflate(LayoutInflater.java:621) 04-30 19:08:34.463: ERROR/AndroidRuntime(405): at android.view.LayoutInflater.inflate(LayoutInflater.java:407) 04-30 19:08:34.463: ERROR/AndroidRuntime(405): at android.view.LayoutInflater.inflate(LayoutInflater.java:320) 04-30 19:08:34.463: ERROR/AndroidRuntime(405): at android.view.LayoutInflater.inflate(LayoutInflater.java:276) 04-30 19:08:34.463: ERROR/AndroidRuntime(405): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198) 04-30 19:08:34.463: ERROR/AndroidRuntime(405): at android.app.Activity.setContentView(Activity.java:1622) 04-30 19:08:34.463: ERROR/AndroidRuntime(405): at kostas.menu.chania.sfinari.onCreate(sfinari.java:15) 04-30 19:08:34.463: ERROR/AndroidRuntime(405): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 04-30 19:08:34.463: ERROR/AndroidRuntime(405): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417) 04-30 19:08:34.463: ERROR/AndroidRuntime(405): ... 11 more 04-30 19:08:34.463: ERROR/AndroidRuntime(405): Caused by: java.lang.reflect.InvocationTargetException 04-30 19:08:34.463: ERROR/AndroidRuntime(405): at android.widget.ImageView.<init>(ImageView.java:105) 04-30 19:08:34.463: ERROR/AndroidRuntime(405): at java.lang.reflect.Constructor.constructNative(Native Method) 04-30 19:08:34.463: ERROR/AndroidRuntime(405): at java.lang.reflect.Constructor.newInstance(Constructor.java:446) 04-30 19:08:34.463: ERROR/AndroidRuntime(405): at android.view.LayoutInflater.createView(LayoutInflater.java:500) 04-30 19:08:34.463: ERROR/AndroidRuntime(405): ... 23 more 04-30 19:08:34.463: ERROR/AndroidRuntime(405): Caused by: android.content.res.Resources$NotFoundException: File res/drawable-mdpi/scrollbar_handle_vertical.9.png from drawable resource ID #0x7f050000 04-30 19:08:34.463: ERROR/AndroidRuntime(405): at android.content.res.Resources.loadDrawable(Resources.java:1710) 04-30 19:08:34.463: ERROR/AndroidRuntime(405): at android.content.res.TypedArray.getDrawable(TypedArray.java:548) 04-30 19:08:34.463: ERROR/AndroidRuntime(405): at android.widget.ImageView.<init>(ImageView.java:115) 04-30 19:08:34.463: ERROR/AndroidRuntime(405): ... 27 more 04-30 19:08:34.463: ERROR/AndroidRuntime(405): Caused by: java.io.FileNotFoundException: res/drawable-mdpi/scrollbar_handle_vertical.9.png 04-30 19:08:34.463: ERROR/AndroidRuntime(405): at android.content.res.AssetManager.openNonAssetNative(Native Method) 04-30 19:08:34.463: ERROR/AndroidRuntime(405): at android.content.res.AssetManager.openNonAsset(AssetManager.java:391) 04-30 19:08:34.463: ERROR/AndroidRuntime(405): at android.content.res.Resources.loadDrawable(Resources.java:1702) 04-30 19:08:34.463: ERROR/AndroidRuntime(405): ... 29 more

    Read the article

  • Android Canvas Coordinate System

    - by Mitch
    I'm trying to find information on how to change the coordinate system for the canvas. I have some vector data I'd like to draw to a canvas using things like circles and lines, but the data's coordinate system doesn't match the canvas coordinate system. Is there a way to map the units I'm using to the screen's units? I'm drawing to an ImageView which isn't taking up the entire display. If I have to do my own calculations prior to each drawing call, how to I find the width and height of my ImageView? The getWidth() and getHeight() calls I tried seem to be returning the entire canvas size and not the size of the ImageView which isn't helpful. I see some matrix stuff, is that something that will work for me? I tried to use the "public void scale(float sx, float sy)", but that works more like a pixel level zoom rather than a vector scale function by expanding each pixel. This means if the dimensions are increased to fit the screen, the line thickness is also increased. Update: After some research I'm starting to think there's no way to change coordinate systems to something else. I'll need to map all my coordinates to the screen's pixel coordinates and do so by modifying each vector. The getWidth() and getHeight() seem to be working better for me now. I can say what was wrong, but I suspect I can't use these methods inside the constructor.

    Read the article

  • how can convert bitmap to byte array

    - by narasimha
    hi sir i am implementing image upload in sdcard image converting bitmap in bitmap convert in bytearray i am implementing this code import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.EOFException; import java.io.File; import java.io.FileDescriptor; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import android.R.array; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Bundle; import android.util.Log; import android.widget.ImageView; public class Photo extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); File f = new File("/sdcard/DCIM/1.jpg"); FileInputStream is = null; try { is = new FileInputStream(f); Bitmap bm; bm = BitmapFactory.decodeStream(is,null,null); ByteArrayOutputStream baos = new ByteArrayOutputStream(1000); bm.compress(Bitmap.CompressFormat.JPEG,75, baos); System.out.println("3........................"+bm); ImageView pic=(ImageView)this.findViewById(R.id.picview); pic.setImageBitmap(bm); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } } }this code is i am implementing how can convert bitmap in byte array INFO/System.out(12658): 3........................android.graphics.Bitmap@4358e3d0 in debug this will be displayed how can retrieve bitmap to byte array

    Read the article

  • RubyQT QGraphicsview scale images to fit window

    - by shadowskill
    I'm trying to make an image scale inside of a QGraphicsView and having zero success. I did find this C++ question with what seemed to be the same problem:http://stackoverflow.com/questions/2489754/qgraphicsview-scrolling-and-image-scaling-cropping I borrowed the approach of overriding the drawback/foreground. However when I run the script I'm greeted with a method_missing error: method_missing: undefined method drawPixmap for #<Qt::Painter:0x7ff11eb9b088> QPaintDevice: Cannot destroy paint device that is being painted What should I be doing to get the QGraphicsView to behave the way I want? class Imageview < Qt::GraphicsView attr_reader :pixmap def initialize(parent=nil) # @parent=parent super() @pixmap=pixmap Qt::MetaObject.connectSlotsByName(self) end def loadimage(pixmap) @pixmap=pixmap end def drawForeground(painter, rect) #size=event.size() #item= self.items()[0] #Qt::GraphicsPixmapItem.new #pixmap=@pixmap #painter=Qt::Painter.new [email protected](Qt::Size.new(rect.width,rect.height),Qt::KeepAspectRatio, Qt::SmoothTransformation) # painter.begin(self) painter.drawPixmap(rect,sized,Qt::Rect.new(0.0, 0.0, sized.width,sized.height)) #painter.end() # item.setPixmap(sized) #painter.end self.centerOn(1.0,1.0) #item.scale() # item.setTransformationMode(Qt::FastTransformation) # self.fitInView(item) end def updateSceneRect painter=Qt::Painter.new() drawForeground(painter,self.sceneRect) end end app=Qt::Application.new(ARGV) #grview=Imageview.new pic=Qt::Pixmap.new('pic') grview=Imageview.new() grview.loadimage(pic) scene=Qt::GraphicsScene.new #scene.addPixmap(pic) grview.setScene(scene) #grview.fitInView(scene) grview.renderHint=Qt::Painter::Antialiasing | Qt::Painter::SmoothPixmapTransform grview.backgroundBrush = Qt::Brush.new(Qt::Color.new(230, 200, 167)) grview.show app.exec

    Read the article

  • how to implement bitmap to byte array in android

    - by satyamurthy
    hi sir i am implementing image upload in sdcard image converting bitmap in bitmap convert in bytearray i am implementing this code import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.EOFException; import java.io.File; import java.io.FileDescriptor; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import android.R.array; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Bundle; import android.util.Log; import android.widget.ImageView; public class Photo extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); File f = new File("/sdcard/DCIM/1.jpg"); FileInputStream is = null; try { is = new FileInputStream(f); Bitmap bm; bm = BitmapFactory.decodeStream(is,null,null); ByteArrayOutputStream baos = new ByteArrayOutputStream(1000); bm.compress(Bitmap.CompressFormat.JPEG,75, baos); System.out.println("3........................"+bm); ImageView pic=(ImageView)this.findViewById(R.id.picview); pic.setImageBitmap(bm); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } } }this code is i am implementing how can convert bitmap in byte array INFO/System.out(12658): 3........................android.graphics.Bitmap@4358e3d0 in debug this will be displayed how can retrieve bitmap to byte array

    Read the article

  • Android - Views in Custom Compound Component are not inflated (findByView returns null)

    - by Julian Arz
    I have made a Custom Component in XML, consisting of a button with an imageview stacked on top of it: <myapp.widget.ClearableCaptionedButton xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> <Button android:id="@+id/ccbutton_button" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_vertical|left" android:textAppearance="?android:attr/textAppearanceMedium" android:background="@android:drawable/edit_text"/> <ImageView android:id="@+id/ccbutton_clear" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="5dip" android:layout_alignRight="@id/ccbutton_button" android:layout_alignTop="@id/ccbutton_button" android:layout_alignBottom="@id/ccbutton_button"/> </myapp.widget.ClearableCaptionedButton> extract of java source code: public class ClearableCaptionedButton extends RelativeLayout implements OnClickListener { ... public ClearableCaptionedButton(Context context, AttributeSet attrs) { super(context, attrs); // some stuff that works fine } .. protected void onFinishInflate() { super.onFinishInflate(); mButton = (Button) findViewById(R.id.ccbutton_button); mClear = (ImageView) findViewById(R.id.ccbutton_clear); mButton.setText(""); // error here: mButton == null } My problem is similar to this one. When i try to find the views inside the custom compound, findViewById returns null. But, as you can see, i already added super(context, attrs); to the constructor. i am using the custom component directly in xml layout, like this: <LinearLayout> <!-- some stuff --> <de.pockettaxi.widget.ClearableCaptionedButton android:layout_width="fill_parent" android:layout_height="wrap_content" app:caption="to"/> </LinearLayout> can anybody spot something? thanks.

    Read the article

  • Android media thumbnails. Serious issues?

    - by Ralphleon
    I've been playing with android's thumbnails for a while now, and I've seen some inconsistencies that make me want to scream. My goal is to have a simple list of all Images (and a separate list for video) with the thumbnail and filename. Device: HTC Evo (fresh from Google I/o) First off: http://androidsamples.blogspot.com/2009/06/how-to-display-thumbnails-of-images.html That code doesn't seem to work at all, thumbnails are duplicated... some with the "mirror" effect and some without. Also some won't load and just display a black square. I've tried rebuilding the thumbnails by deleting the "alblum thumbs" directory from the SD card. HTC's gallery application seem to show everything fine. This approach seems to work: Bitmap thumb = MediaStore.Images.Thumbnails.getThumbnail( getContentResolver(), id, MediaStore.Video.Thumbnails.MICRO_KIND, null); imageView.setImageBitmap(curThumb); where id is the original images id and imageView is some image view. This is great! But, strangely, way too slow to be used inside a SimpleViewBinder. Next approach: String [] proj = {MediaStore.Images.Thumbnails._ID}; Cursor c = managedQuery(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, proj, MediaStore.Images.Thumbnails.IMAGE_ID + "=" +id , null, null); if (c != null && c.moveToFirst()) { Uri thumb = Uri.withAppendedPath(mThumbUri,c.getLong(0)+""); imageView.setImageURI(thumb); } I should explain that I feel the needed WHERE condition is required because there doesn't seem to be any guarantee that your uri will have the same ID for both a thumbnail and its parent image. This works for all of the current images, but as soon as I start adding pictures with the camera they show up as blank! Debugging shows a dreaded: SkImageDecoder::Factory returned null error and the URI is returned as invalid. These are the same images that work with the previous call. Can anyone either catch my logical failure or point me to some working code?

    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

< Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >