Note that there are some explanatory texts on larger screens.

plurals
  1. POandroid application is crashing
    primarykey
    data
    text
    <p>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.</p> <p>mainactivity:</p> <pre><code>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); } } </code></pre> <p>main.xml</p> <pre><code>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"&gt; &lt;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" /&gt; &lt;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" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>gameactivity:</p> <pre><code> 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)); } } </code></pre> <p>gameactivity.xml:</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;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" &gt; &lt;/GridView&gt; </code></pre> <p>image view adapter class</p> <pre><code>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; } } </code></pre> <p>logcat:</p> <pre><code>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 </code></pre>
    singulars
    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.
 

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