• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Application is not getting open

Ganesh

Newbie
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"
 
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:
Context myContext = getApplicationContext();
 
Back
Top Bottom