Application is not getting open


Last Updated:

  1. Ganesh

    Ganesh Member This Topic's Starter

    Joined:
    Dec 25, 2009
    Messages:
    18
    Likes Received:
    0
    Hello Everyone,


    I am trying to just diplay single image on canvas the code is like following...

    package com.displayImage;
    import android.app.Activity;
    import android.content.Context;
    import android.graphics.drawable.Drawable;
    import android.os.Bundle;
    public class DisplayImage extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Context context = null;
    Drawable helloworldImg= context.getResources().getDrawable(R.drawable.helloworld);
    helloworldImg.setBounds(0, 0, helloworldImg.getIntrinsicWidth(), helloworldImg.getIntrinsicHeight()/2);
    }
    }




    But I am getting following display message and application gets closed (On emulator and device also)

    "The application DisplayImage (process.com.displayImage) has stopped unexpectedly"
     

    Advertisement
  2. eclipsed4utoo

    eclipsed4utoo Well-Known Member

    Joined:
    Nov 12, 2009
    Messages:
    435
    Likes Received:
    27
    Whay are you setting the Context to null then trying to use it? Most likely, you are getting a NullReference Exception because you are trying to use the null context.

    To get the current application context, use this...

    Code (Text):
    1.  
    2. Context myContext = getApplicationContext();
    3.  
     
  3. Ganesh

    Ganesh Member This Topic's Starter

    Joined:
    Dec 25, 2009
    Messages:
    18
    Likes Received:
    0
    Hello eclipsed4utoo,,

    I will try with
    Context myContext = getApplicationContext();

    Thank you in advance







    [​IMG]
     

Share This Page

Loading...