Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8347503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:22:48+00:00 2026-06-09T07:22:48+00:00

I have made an android application in which there is a text and button

  • 0

I have made an android application in which there is a text and button in first activity when I click on button it should go to second activity and view the images in grid view but its not doing that it gives the message it has stopped unexpectedly. Here is the code.

mainactivity:

package com.karan.myjigsaw;

import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.content.Intent;

public class MainActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

}
public void playGame(View view) {
    Intent intent = new Intent(this, GameActivity.class);
    startActivity(intent);

}

}

main.xml

RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
    android:layout_margin="120dip"
    android:layout_width="200dp"
    android:layout_height="150dp"
    android:text="@string/welcome_note"
    android:layout_centerHorizontal="true"
    tools:context=".MainActivity" />

<Button 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/button_play"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:onClick = "playGame" />


   </RelativeLayout> 

gameactivity:

 public class GameActivity extends Activity {

ImageView image;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent intent = getIntent();

    //create grid view
    GridView gridView = new GridView(this);
    gridView = (GridView)findViewById(R.id.grid_view);   

    // Instance of ImageAdapter Class
   gridView.setAdapter(new ImageAdapter(this));
}

}

gameactivity.xml:

 <?xml version="1.0" encoding="utf-8"?>

<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/grid_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="auto_fit"
android:columnWidth="90dp"
android:horizontalSpacing="10dp"
android:verticalSpacing="10dp"
android:gravity="center"
android:stretchMode="columnWidth" > 

</GridView>

image view adapter class

public class ImageAdapter extends BaseAdapter{
 private Context mContext;

// references to our images
    private Integer[] mThumbIds = {R.drawable.imagesl_01,R.drawable.imagesl_02,
               R.drawable.imagesl_03,R.drawable.imagesl_04,R.drawable.imagesl_05,
             R.drawable.imagesl_06,R.drawable.imagesl_07,R.drawable.imagesl_8,
            R.drawable.imagesl_9};

    public ImageAdapter(Context c) {
        mContext = c;
    }

    public int getCount() {
        return mThumbIds.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(85, 85));
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            imageView.setPadding(8, 8, 8, 8);
       } else {
           imageView = (ImageView) convertView;
        }

        imageView.setImageResource(mThumbIds[position]);
        return imageView;
    }

    }

logcat:

08-02 00:24:30.160: D/AndroidRuntime(286): Shutting down VM
08-02 00:24:30.160: W/dalvikvm(286): threadid=1: thread exiting with uncaught     exception (group=0x4001d800)
08-02 00:24:30.190: E/AndroidRuntime(286): FATAL EXCEPTION: main
08-02 00:24:30.190: E/AndroidRuntime(286): java.lang.RuntimeException: Unable to start activity         ComponentInfo{com.bellurbis.karan.myjigsaw/com.bellurbis.karan.myjigsaw.GameActivity}: java.lang.NullPointerException
08-02 00:24:30.190: E/AndroidRuntime(286):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
08-02 00:24:30.190: E/AndroidRuntime(286):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-02 00:24:30.190: E/AndroidRuntime(286):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-02 00:24:30.190: E/AndroidRuntime(286):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-02 00:24:30.190: E/AndroidRuntime(286):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-02 00:24:30.190: E/AndroidRuntime(286):  at android.os.Looper.loop(Looper.java:123)
08-02 00:24:30.190: E/AndroidRuntime(286):  at android.app.ActivityThread.main(ActivityThread.java:4627)
08-02 00:24:30.190: E/AndroidRuntime(286):  at java.lang.reflect.Method.invokeNative(Native Method)
08-02 00:24:30.190: E/AndroidRuntime(286):  at java.lang.reflect.Method.invoke(Method.java:521)
08-02 00:24:30.190: E/AndroidRuntime(286):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-02 00:24:30.190: E/AndroidRuntime(286):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-02 00:24:30.190: E/AndroidRuntime(286):  at dalvik.system.NativeStart.main(Native Method)
08-02 00:24:30.190: E/AndroidRuntime(286): Caused by: java.lang.NullPointerException
08-02 00:24:30.190: E/AndroidRuntime(286):  at com.bellurbis.karan.myjigsaw.GameActivity.onCreate(GameActivity.java:20)
08-02 00:24:30.190: E/AndroidRuntime(286):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-02 00:24:30.190: E/AndroidRuntime(286):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
08-02 00:24:30.190: E/AndroidRuntime(286):  ... 11 more
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T07:22:51+00:00Added an answer on June 9, 2026 at 7:22 am

    Error:U must setContentView(R.layout.gameactivity) firstly,and secondly to use findViewById(R.id.grid_view)!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

the thing is i have made an application in which icons are there.. when
I have a little problem... I have made an Android application which extends the
i have made an android application and in it , there is one scenario
I have made an application which has tabs like in HelloTabActivity, there is also
i made android application. In application i have web view where i want to
I have a Settings activity in my android application which purpose is to save
I am using the XMPP Connection(using smack) for chat in android application.I have made
I have made an application in android that lets the user compress and decompress
I have made an android app which working fine. I implemented the Login functionality
First off thanks to all the users who have made my android developing adventure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.