Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android

Unfortunately, Xaqiiqooyinka has stopped

I am trying to create the project of this question " Extra Credit Array Madness

Create a new project and add two TextViews to the screen. Create an array of numbers and see if you can display the numbers in order in the first TextView and then reversed in the second TextView. " I did my code but unfortunately the app is stopping, here is my code, please help me with what I am supposed to add:

package com.ceelcali.xaqiiqooyinka;

import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.TextView;

import java.util.Random;

import static android.view.View.OnClickListener;

public class MyActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my);
    //Declare my Variables and assign them  to the layout file
    final TextView FactLabel;
    FactLabel = (TextView) findViewById(R.id.FactsTextView);
    Button FactsButton = (Button) findViewById(R.id.FactButton);
    View.OnClickListener Listener = new OnClickListener() {
        @Override
        public void onClick(View view) {
            String[] Numbers  = {"1","2","3","4","5","6","7","8","9"};
              String Number = "";
            Random randomGenerator = new Random();
            int randomNumber = randomGenerator.nextInt(Numbers.length);
            Number = Numbers[randomNumber];
            FactLabel.setText(Number);




           //the button was clicked, so update the facts.

        }
    };

  FactsButton.setOnClickListener(Listener);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.my, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

}

And Here is my Logcat

05-30 20:02:10.770 1371-1371/com.ceelcali.xaqiiqooyinka D/dalvikvm﹕ Late-enabling CheckJNI 05-30 20:02:11.110 1371-1371/com.ceelcali.xaqiiqooyinka D/AndroidRuntime﹕ Shutting down VM 05-30 20:02:11.110 1371-1371/com.ceelcali.xaqiiqooyinka W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xa4d07b20) 05-30 20:02:11.110 1371-1371/com.ceelcali.xaqiiqooyinka E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.ceelcali.xaqiiqooyinka, PID: 1371 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ceelcali.xaqiiqooyinka/com.ceelcali.xaqiiqooyinka.MyActivity}: java.lang.NullPointerException at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) at android.app.ActivityThread.access$800(ActivityThread.java:135) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5001) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.NullPointerException at com.ceelcali.xaqiiqooyinka.MyActivity.onCreate(MyActivity.java:44) at android.app.Activity.performCreate(Activity.java:5231) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)             at android.app.ActivityThread.access$800(ActivityThread.java:135)             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)             at android.os.Handler.dispatchMessage(Handler.java:102)             at android.os.Looper.loop(Looper.java:136)             at android.app.ActivityThread.main(ActivityThread.java:5001)             at java.lang.reflect.Method.invokeNative(Native Method)             at java.lang.reflect.Method.invoke(Method.java:515)             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)             at dalvik.system.NativeStart.main(Native Method) 05-30 20:06:46.438 1475-1475/com.ceelcali.xaqiiqooyinka W/ActivityThread﹕ Application com.ceelcali.xaqiiqooyinka is waiting for the debugger on port 8100... 05-30 20:06:46.458 1475-1475/com.ceelcali.xaqiiqooyinka I/System.out﹕ Sending WAIT chunk 05-30 20:06:47.574 1475-1480/com.ceelcali.xaqiiqooyinka I/dalvikvm﹕ Debugger is active 05-30 20:06:47.670 1475-1475/com.ceelcali.xaqiiqooyinka I/System.out﹕ Debugger has connected 05-30 20:06:47.670 1475-1475/com.ceelcali.xaqiiqooyinka I/System.out﹕ waiting for debugger to settle... 05-30 20:06:47.870 1475-1475/com.ceelcali.xaqiiqooyinka I/System.out﹕ waiting for debugger to settle... 05-30 20:06:48.070 1475-1475/com.ceelcali.xaqiiqooyinka I/System.out﹕ waiting for debugger to settle... 05-30 20:06:48.274 1475-1475/com.ceelcali.xaqiiqooyinka I/System.out﹕ waiting for debugger to settle... 05-30 20:06:48.474 1475-1475/com.ceelcali.xaqiiqooyinka I/System.out﹕ waiting for debugger to settle... 05-30 20:06:48.678 1475-1475/com.ceelcali.xaqiiqooyinka I/System.out﹕ waiting for debugger to settle... 05-30 20:06:48.878 1475-1475/com.ceelcali.xaqiiqooyinka I/System.out﹕ waiting for debugger to settle... 05-30 20:06:49.078 1475-1475/com.ceelcali.xaqiiqooyinka I/System.out﹕ waiting for debugger to settle... 05-30 20:06:49.282 1475-1475/com.ceelcali.xaqiiqooyinka I/System.out﹕ waiting for debugger to settle... 05-30 20:06:49.482 1475-1475/com.ceelcali.xaqiiqooyinka I/System.out﹕ waiting for debugger to settle... 05-30 20:06:49.686 1475-1475/com.ceelcali.xaqiiqooyinka I/System.out﹕ waiting for debugger to settle... 05-30 20:06:49.886 1475-1475/com.ceelcali.xaqiiqooyinka I/System.out﹕ waiting for debugger to settle... 05-30 20:06:50.086 1475-1475/com.ceelcali.xaqiiqooyinka I/System.out﹕ waiting for debugger to settle... 05-30 20:06:50.290 1475-1475/com.ceelcali.xaqiiqooyinka I/System.out﹕ waiting for debugger to settle... 05-30 20:06:50.490 1475-1475/com.ceelcali.xaqiiqooyinka I/System.out﹕ waiting for debugger to settle... 05-30 20:06:50.694 1475-1475/com.ceelcali.xaqiiqooyinka I/System.out﹕ debugger has settled (1441) 05-30 20:06:50.910 1475-1475/com.ceelcali.xaqiiqooyinka D/AndroidRuntime﹕ Shutting down VM 05-30 20:06:50.910 1475-1475/com.ceelcali.xaqiiqooyinka W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xa4d07b20) 05-30 20:06:50.918 1475-1475/com.ceelcali.xaqiiqooyinka E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.ceelcali.xaqiiqooyinka, PID: 1475 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ceelcali.xaqiiqooyinka/com.ceelcali.xaqiiqooyinka.MyActivity}: java.lang.NullPointerException at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) at android.app.ActivityThread.access$800(ActivityThread.java:135) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5001) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.NullPointerException at com.ceelcali.xaqiiqooyinka.MyActivity.onCreate(MyActivity.java:44) at android.app.Activity.performCreate(Activity.java:5231) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)             at android.app.ActivityThread.access$800(ActivityThread.java:135)             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)             at android.os.Handler.dispatchMessage(Handler.java:102)             at android.os.Looper.loop(Looper.java:136)             at android.app.ActivityThread.main(ActivityThread.java:5001)             at java.lang.reflect.Method.invokeNative(Native Method)             at java.lang.reflect.Method.invoke(Method.java:515)             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)             at dalvik.system.NativeStart.main(Native Method)

Hello,

Could you tell us which line of code is line 44 in MyActivity.java? Your NullPointerException is happening there, but your line spacing got clobbered when you copy and pasted your code to the forums.

Hello, James :) , line 44 is FactsButton.setOnClickListener(Listener);

actually they're the same in the code and in the xml but still having the problem :) thanks for being helpful

Could you post your updated code, xml, and error message so that we can see the changes(especially any changes in the error message)?

my updated code = ```package com.ceelcali.xaqiiqooyinka;

import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.TextView;

import java.util.Random;

import static android.view.View.OnClickListener;

public class MyActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my);
    //Declare my Variables and assign them  to the layout file
    final TextView FactLabel;
    FactLabel = (TextView) findViewById(R.id.FactsTextView);
    Button FactsButton = (Button) findViewById(R.id.FactButton);
    View.OnClickListener Listener = new OnClickListener() {
        @Override
        public void onClick(View view) {
            String[] Numbers  = {"1","2","3","4","5","6","7","8","9"};
              String Number = "";
            Random randomGenerator = new Random();
            int randomNumber = randomGenerator.nextInt(Numbers.length);
            Number = Numbers[randomNumber];
            FactLabel.setText(Number);




           //the button was clicked, so update the facts.

        }
    };

    FactsButton.setOnClickListener(Listener);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.my, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

}

My updated 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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MyActivity">

    <TextView
        android:text="@string/hello_world"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textView2" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="There We Go"
        android:id="@+id/textView"
        android:layout_below="@+id/textView2"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="68dp"
        android:textSize="20sp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Here We Are"
        android:id="@+id/textView3"
        android:layout_below="@+id/textView"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="41dp"
        android:textSize="20sp" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Show me"
        android:id="@+id/FactsButton"
        android:layout_toEndOf="@+id/textView2"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

</RelativeLayout>

logcat =

05-31 16:59:48.952    1384-1384/com.ceelcali.xaqiiqooyinka D/AndroidRuntime﹕ Shutting down VM
05-31 16:59:48.952    1384-1384/com.ceelcali.xaqiiqooyinka W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xa4caeb20)
05-31 16:59:48.956    1384-1384/com.ceelcali.xaqiiqooyinka E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.ceelcali.xaqiiqooyinka, PID: 1384
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ceelcali.xaqiiqooyinka/com.ceelcali.xaqiiqooyinka.MyActivity}: java.lang.NullPointerException
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5001)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NullPointerException
            at com.ceelcali.xaqiiqooyinka.MyActivity.onCreate(MyActivity.java:44)
            at android.app.Activity.performCreate(Activity.java:5231)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5001)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)
05-31 16:59:58.420    1384-1384/com.ceelcali.xaqiiqooyinka I/Process﹕ Sending signal. PID: 1384 SIG: 9
05-31 17:01:41.256    1474-1474/com.ceelcali.xaqiiqooyinka D/AndroidRuntime﹕ Shutting down VM
05-31 17:01:41.256    1474-1474/com.ceelcali.xaqiiqooyinka W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xa4caeb20)
05-31 17:01:41.260    1474-1474/com.ceelcali.xaqiiqooyinka E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.ceelcali.xaqiiqooyinka, PID: 1474
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ceelcali.xaqiiqooyinka/com.ceelcali.xaqiiqooyinka.MyActivity}: java.lang.NullPointerException
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5001)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NullPointerException
            at com.ceelcali.xaqiiqooyinka.MyActivity.onCreate(MyActivity.java:44)
            at android.app.Activity.performCreate(Activity.java:5231)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5001)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)
05-31 17:01:47.688    1474-1474/com.ceelcali.xaqiiqooyinka I/Process﹕ Sending signal. PID: 1474 SIG: 9
05-31 17:22:05.376    1593-1593/com.ceelcali.xaqiiqooyinka I/Process﹕ Sending signal. PID: 1593 SIG: 9
05-31 17:24:45.752    1659-1659/com.ceelcali.xaqiiqooyinka W/ActivityThread﹕ Application com.ceelcali.xaqiiqooyinka is waiting for the debugger on port 8100...
05-31 17:24:45.756    1659-1659/com.ceelcali.xaqiiqooyinka I/System.out﹕ Sending WAIT chunk
05-31 17:24:45.936    1659-1665/com.ceelcali.xaqiiqooyinka I/dalvikvm﹕ Debugger is active
05-31 17:24:45.960    1659-1659/com.ceelcali.xaqiiqooyinka I/System.out﹕ Debugger has connected
05-31 17:24:45.960    1659-1659/com.ceelcali.xaqiiqooyinka I/System.out﹕ waiting for debugger to settle...
05-31 17:24:46.164    1659-1659/com.ceelcali.xaqiiqooyinka I/System.out﹕ waiting for debugger to settle...
05-31 17:24:46.372    1659-1659/com.ceelcali.xaqiiqooyinka I/System.out﹕ waiting for debugger to settle...
05-31 17:24:46.576    1659-1659/com.ceelcali.xaqiiqooyinka I/System.out﹕ waiting for debugger to settle...
05-31 17:24:46.776    1659-1659/com.ceelcali.xaqiiqooyinka I/System.out﹕ waiting for debugger to settle...
05-31 17:24:46.976    1659-1659/com.ceelcali.xaqiiqooyinka I/System.out﹕ waiting for debugger to settle...
05-31 17:24:47.184    1659-1659/com.ceelcali.xaqiiqooyinka I/System.out﹕ waiting for debugger to settle...
05-31 17:24:47.384    1659-1659/com.ceelcali.xaqiiqooyinka I/System.out﹕ waiting for debugger to settle...
05-31 17:24:47.588    1659-1659/com.ceelcali.xaqiiqooyinka I/System.out﹕ waiting for debugger to settle...
05-31 17:24:47.788    1659-1659/com.ceelcali.xaqiiqooyinka I/System.out﹕ waiting for debugger to settle...
05-31 17:24:47.992    1659-1659/com.ceelcali.xaqiiqooyinka I/System.out﹕ waiting for debugger to settle...
05-31 17:24:48.192    1659-1659/com.ceelcali.xaqiiqooyinka I/System.out﹕ waiting for debugger to settle...
05-31 17:24:48.396    1659-1659/com.ceelcali.xaqiiqooyinka I/System.out﹕ debugger has settled (1318)
05-31 17:24:48.568    1659-1659/com.ceelcali.xaqiiqooyinka D/AndroidRuntime﹕ Shutting down VM
05-31 17:24:48.568    1659-1659/com.ceelcali.xaqiiqooyinka W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xa4caeb20)
05-31 17:24:48.584    1659-1659/com.ceelcali.xaqiiqooyinka E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.ceelcali.xaqiiqooyinka, PID: 1659
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ceelcali.xaqiiqooyinka/com.ceelcali.xaqiiqooyinka.MyActivity}: java.lang.NullPointerException
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5001)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NullPointerException
            at com.ceelcali.xaqiiqooyinka.MyActivity.onCreate(MyActivity.java:44)
            at android.app.Activity.performCreate(Activity.java:5231)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5001)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)
05-31 17:24:51.576    1659-1659/com.ceelcali.xaqiiqooyinka I/Process﹕ Sending signal. PID: 1659 SIG: 9

1 Answer

Hello,

Its likely that either your button does not have the id of FactButton or it is not located in the activity_my.xml file. Could you double check those two are correct and try again. If this still doesn't help, could you at least post the activity_my.xml file, or post your full code on GitHub, so we can take a further look.

WELL SAID, honestly, I didn't have the id of FactsButton but as I added now, the problem is still there and I checked the xml file and there is also added the FactsButton id.
here is my activity_my.xml file

```<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:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MyActivity">

<TextView
    android:text="@string/hello_world"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/textView2" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="There We Go"
    android:id="@+id/textView"
    android:layout_below="@+id/textView2"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginTop="68dp"
    android:textSize="20sp" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Here We Are"
    android:id="@+id/textView3"
    android:layout_below="@+id/textView"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginTop="41dp"
    android:textSize="20sp" />

<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Show me"
    android:id="@+id/FactsButton"
    android:layout_toEndOf="@+id/textView2"
    android:layout_centerVertical="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

</RelativeLayout>

You actually need to either change it so its FactButton in the xml or FactsButton in the code. They need to be the same.

You need to change R.id.FactButton to be R.id.FactsButton to match your xml's id of FactsButton.

it worked, thank you very much Mr James, I really appreciate that.

You're welcome. Have fun with Android development.