Note that there are some explanatory texts on larger screens.

plurals
  1. POapp crashes when i click on a image
    primarykey
    data
    text
    <p>I had 4 buttons which contains different images, </p> <p>I want to open images in gridview when i click on a image in emulator it should display the image in a new layout(its working fine in 1st adaper class), but when i open images on 2nd button the images in the emulator its shows the images in adapter class2 but when i click on a image it shows the image in 1st adapter class</p> <p>ImageActivity.java </p> <pre><code>public class ImageActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.image_selection); Button a,b,c,d; b = (Button)findViewById(R.id.button1); b.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent i = new Intent(ImageActivity.this, screen2.class); startActivity(i); } }); } } </code></pre> <p>screen2.java</p> <pre><code>public class screen2 extends Activity{ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.screen2); GridView gridview = (GridView) findViewById(R.id.gridview); gridview.setAdapter(new ImageAdapter2(this)); gridview.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; parent, View v, int position, long id) { Intent i = new Intent(getApplicationContext(), FullImageActivity1.class); // passing array index i.putExtra("id", position); startActivity(i); } }); } } </code></pre> <p>ImageAdapter.java</p> <pre><code>public class ImageAdapter2 extends BaseAdapter { private Context mContext; public Integer[] images = { R.drawable.baby1, R.drawable.baby2, R.drawable.baby3,R.drawable.baby4, }; public ImageAdapter2(Context c) { mContext = c; } public int getCount() { return images.length; } public Object getItem(int position) { return null; } public long getItemId(int position) { return 0; } // create a new ImageView for each item referenced by the Adapter public View getView(int position, View convertView, ViewGroup parent) { ImageView imageView; if (convertView == null) { // if it's not recycled, initialize some attributes imageView = new ImageView(mContext); imageView.setLayoutParams(new GridView.LayoutParams(60, 60)); imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); imageView.setPadding(8, 8, 8, 8); } else { imageView = (ImageView) convertView; } imageView.setImageResource(images[position]); return imageView; } </code></pre> <p>}</p> <p>FullImageActivity.java</p> <pre><code> public class FullImageActivity2 extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.full_image2); Intent intent = getIntent(); int position = intent.getExtras().getInt("id"); ImageAdapter2 imageAdapter = new ImageAdapter2(this); ImageView imageView = (ImageView) findViewById(R.id.full_image_view); imageView.setImageResource(imageAdapter.images[position]); } } </code></pre> <p>logcat is </p> <pre><code> 07-19 15:24:24.627: E/AndroidRuntime(1709): FATAL EXCEPTION: main 07-19 15:24:24.627: E/AndroidRuntime(1709): java.lang.RuntimeException: Unable to start activity ComponentInfo{abhinai.image/abhinai.image.FullImageActivity3}: java.lang.NullPointerException 07-19 15:24:24.627: E/AndroidRuntime(1709): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) 07-19 15:24:24.627: E/AndroidRuntime(1709): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 07-19 15:24:24.627: E/AndroidRuntime(1709): at android.app.ActivityThread.access$600(ActivityThread.java:141) 07-19 15:24:24.627: E/AndroidRuntime(1709): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 07-19 15:24:24.627: E/AndroidRuntime(1709): at android.os.Handler.dispatchMessage(Handler.java:99) 07-19 15:24:24.627: E/AndroidRuntime(1709): at android.os.Looper.loop(Looper.java:137) 07-19 15:24:24.627: E/AndroidRuntime(1709): at android.app.ActivityThread.main(ActivityThread.java:5039) 07-19 15:24:24.627: E/AndroidRuntime(1709): at java.lang.reflect.Method.invokeNative(Native Method) 07-19 15:24:24.627: E/AndroidRuntime(1709): at java.lang.reflect.Method.invoke(Method.java:511) 07-19 15:24:24.627: E/AndroidRuntime(1709): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 07-19 15:24:24.627: E/AndroidRuntime(1709): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 07-19 15:24:24.627: E/AndroidRuntime(1709): at dalvik.system.NativeStart.main(Native Method) 07-19 15:24:24.627: E/AndroidRuntime(1709): Caused by: java.lang.NullPointerException 07-19 15:24:24.627: E/AndroidRuntime(1709): at abhinai.image.FullImageActivity3.onCreate(FullImageActivity3.java:19) 07-19 15:24:24.627: E/AndroidRuntime(1709): at android.app.Activity.performCreate(Activity.java:5104) 07-19 15:24:24.627: E/AndroidRuntime(1709): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) 07-19 15:24:24.627: E/AndroidRuntime(1709): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144) 07-19 15:24:24.627: E/AndroidRuntime(1709): ... 11 more </code></pre> <p>can anyone help me</p>
    singulars
    1. This table or related slice is empty.
    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.
    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