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 6151845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:49:40+00:00 2026-05-23T19:49:40+00:00

I just started programming for Android when my boss asked me to make him

  • 0

I just started programming for Android when my boss asked me to make him a mobile app so I completed all of this in two days and taught myself as I was doing it, mostly from this site. I keep getting a nullPointerException when i run my program and click on the button that switches the the next activity

First activity:

package com.Android.HelpDeskMobileApp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class HelpDeskFront extends Activity{

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.first);
        Button serviceButton = (Button)findViewById(R.id.serviceButton),
                orderButton = (Button)findViewById(R.id.OrderButton),
                programmingButton = (Button)findViewById(R.id.ProgrammingButton);
        serviceButton.setOnClickListener(buttonListener);
        orderButton.setOnClickListener(buttonListener);
        programmingButton.setOnClickListener(buttonListener);
    }
    private OnClickListener buttonListener = new OnClickListener() {

        public void onClick(View v) {
            String serviceType = null;
            Intent i = new Intent(HelpDeskFront.this, Main.class);
            if (v.getId() == R.id.serviceButton)
                serviceType = "service";
            else if (v.getId() == R.id.OrderButton)
                serviceType = "order";
            else if (v.getId() == R.id.ProgrammingButton)
                serviceType = "programming";
            i.putExtra("serviceType", serviceType);
            startActivityForResult(i, Intent.FILL_IN_DATA);
        };
}

Buttons lead to my second activity:

package com.Android.HelpDeskMobileApp;

import java.util.ArrayList;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class Main extends Activity{

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        final Button send = (Button)findViewById(R.id.sendRequest);
        send.setOnClickListener(buttonListener);
    }
    private OnClickListener buttonListener = new OnClickListener() {

        ArrayList<NameValuePair> data = new ArrayList<NameValuePair>(5);
        final EditText caller = (EditText) findViewById(R.id.CallerEnter), 
                 callExt = (EditText) findViewById(R.id.CallNumberEnter),
                 computerName = (EditText) findViewById(R.id.ComputerNameEnter),
                 location = (EditText) findViewById(R.id.LocationEnter),
                 request = (EditText) findViewById(R.id.RequestEnter);

        public void onClick(View v) {
                    Intent i = getIntent();
        final String serviceType = i.getStringExtra("serviceType");
            Intent intent = new Intent(Main.this, HelpDeskEnd.class);
            final String[] email = {"target emails"};
            data.add(new BasicNameValuePair("Caller: ", textToString(caller)));
            data.add(new BasicNameValuePair("Call Ext: ", textToString(callExt)));
            data.add(new BasicNameValuePair("Computer Name: ", textToString(computerName)));
            data.add(new BasicNameValuePair("Locations: ", textToString(location)));
            data.add(new BasicNameValuePair("Request: ", textToString(request)));
            sendData(data);

            String body = data.get(0).toString() + " " + data.get(1).toString() + " " +
                    data.get(2).toString() + " " + data.get(3).toString() + " " + 
                    data.get(4).toString();
            Mail mail = new Mail("an email", "email password");
            mail.setTo(email);
            mail.setBody(body);
            mail.setFrom("an email");
            mail.setSubject(serviceType);
            try {
                mail.send();
            }
            catch (Exception e) {
                 Log.e("Send Mail", e.getMessage(), e);
            }
            intent.putExtra("serivceType", serviceType);
            startActivity(intent);
        }

    };
    private String textToString(EditText x)
    {
        return x.getText().toString();
    }
    private void sendData(ArrayList<NameValuePair> data)
    {
        try {

            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost("https//www.awebsite.com/phpfile.php");
            httpPost.setEntity(new UrlEncodedFormEntity(data));
            HttpResponse response = httpclient.execute(httpPost);
            Log.i("postData", response.getStatusLine().toString());
        }
        catch (Exception e){
            Log.e("log_tag", "Error: " + e.toString());
        }
    }
}

This is probably some really easy fix. Thanks for any help. Here is my manifest file also I don’t know if its helpful but here it is:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.Android.HelpDeskMobileApp"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="12" />
    <uses-permission android:name="android.permission.INTERNET" />

    <application android:icon="@drawable/logo" android:label="@string/app_name">
        <activity android:name=".HelpDeskFront"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:label="@string/app_name" 
                  android:name=".Main">
                  <intent-filter></intent-filter>
        </activity>
        <activity android:label="@string/app_name" 
                  android:name=".HelpDeskEnd">
                  <intent-filter></intent-filter>
        </activity>

    </application>
</manifest>

The error happens when I hit the button to go from the first activity to the .main activity. I have tried commenting out different parts of the code but I cannot figure out what is causing the Null Pointer Exception. Thanks.
log cat:

    07-13 18:37:29.833: ERROR/AndroidRuntime(770): FATAL EXCEPTION: main
07-13 18:37:29.833: ERROR/AndroidRuntime(770): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.Android.HelpDeskMobileApp/com.Android.HelpDeskMobileApp.Main}: java.lang.NullPointerException
07-13 18:37:29.833: ERROR/AndroidRuntime(770):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1672)
07-13 18:37:29.833: ERROR/AndroidRuntime(770):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1764)
07-13 18:37:29.833: ERROR/AndroidRuntime(770):     at android.app.ActivityThread.access$1500(ActivityThread.java:122)
07-13 18:37:29.833: ERROR/AndroidRuntime(770):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1002)
07-13 18:37:29.833: ERROR/AndroidRuntime(770):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-13 18:37:29.833: ERROR/AndroidRuntime(770):     at android.os.Looper.loop(Looper.java:132)
07-13 18:37:29.833: ERROR/AndroidRuntime(770):     at android.app.ActivityThread.main(ActivityThread.java:4025)
07-13 18:37:29.833: ERROR/AndroidRuntime(770):     at java.lang.reflect.Method.invokeNative(Native Method)
07-13 18:37:29.833: ERROR/AndroidRuntime(770):     at java.lang.reflect.Method.invoke(Method.java:491)
07-13 18:37:29.833: ERROR/AndroidRuntime(770):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
07-13 18:37:29.833: ERROR/AndroidRuntime(770):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
07-13 18:37:29.833: ERROR/AndroidRuntime(770):     at dalvik.system.NativeStart.main(Native Method)
07-13 18:37:29.833: ERROR/AndroidRuntime(770): Caused by: java.lang.NullPointerException
07-13 18:37:29.833: ERROR/AndroidRuntime(770):     at android.app.Activity.findViewById(Activity.java:1744)
07-13 18:37:29.833: ERROR/AndroidRuntime(770):     at com.Android.HelpDeskMobileApp.Main$1.<init>(Main.java:35)
07-13 18:37:29.833: ERROR/AndroidRuntime(770):     at com.Android.HelpDeskMobileApp.Main.<init>(Main.java:31)
07-13 18:37:29.833: ERROR/AndroidRuntime(770):     at java.lang.Class.newInstanceImpl(Native Method)
07-13 18:37:29.833: ERROR/AndroidRuntime(770):     at java.lang.Class.newInstance(Class.java:1301)
07-13 18:37:29.833: ERROR/AndroidRuntime(770):     at android.app.Instrumentation.newActivity(Instrumentation.java:1022)
07-13 18:37:29.833: ERROR/AndroidRuntime(770):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1663)
07-13 18:37:29.833: ERROR/AndroidRuntime(770):     ... 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-05-23T19:49:41+00:00Added an answer on May 23, 2026 at 7:49 pm

    It’s line 34 in Main. The lines under “Caused by” in the logcat output are where the relevant info usually is.

    Okay, culprit should be the initializers

    Intent i = getIntent();
            final String serviceType = i.getStringExtra("serviceType");
            final EditText caller = (EditText) findViewById(R.id.CallerEnter), 
                callExt = (EditText) findViewById(R.id.CallNumberEnter),
                computerName = (EditText) findViewById(R.id.ComputerNameEnter),
                location = (EditText) findViewById(R.id.LocationEnter),
                request = (EditText) findViewById(R.id.RequestEnter);
    

    occurring in the Object constructor. Since the onClickListener constructor will run before the onCreate() method, getIntent() will return null, and you will not have set your contentView so all your findViewById()’s will also return null.

    The correct way would be:

    private OnClickListener buttonListener = new OnClickListener() {
    
            ArrayList<NameValuePair> data = new ArrayList<NameValuePair>(5);
    
            public void onClick(View v) {
                        Intent i = getIntent();
            final String serviceType = i.getStringExtra("serviceType");
            final EditText caller = (EditText) findViewById(R.id.CallerEnter), 
                callExt = (EditText) findViewById(R.id.CallNumberEnter),
                computerName = (EditText) findViewById(R.id.ComputerNameEnter),
                location = (EditText) findViewById(R.id.LocationEnter),
                request = (EditText) findViewById(R.id.RequestEnter);
    
                Intent intent = new Intent(Main.this, HelpDeskEnd.class);
                final String[] email = {"target emails"};
                data.add(new BasicNameValuePair("Caller: ", textToString(caller)));
                data.add(new BasicNameValuePair("Call Ext: ", textToString(callExt)));
                data.add(new BasicNameValuePair("Computer Name: ", textToString(computerName)));
                data.add(new BasicNameValuePair("Locations: ", textToString(location)));
                data.add(new BasicNameValuePair("Request: ", textToString(request)));
                sendData(data);
    
                String body = data.get(0).toString() + " " + data.get(1).toString() + " " +
                        data.get(2).toString() + " " + data.get(3).toString() + " " + 
                        data.get(4).toString();
                Mail mail = new Mail("an email", "email password");
                mail.setTo(email);
                mail.setBody(body);
                mail.setFrom("an email");
                mail.setSubject(serviceType);
                try {
                    mail.send();
                }
                catch (Exception e) {
                     Log.e("Send Mail", e.getMessage(), e);
                }
                intent.putExtra("serivceType", serviceType);
                startActivity(intent);
            }
    
        };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just getting started with android programming, and want to see if there is
Sorry for this, I've just started programming with wpf. I can't seem to figure
I've started Android programming recently so bear with me :) I develop an app
i have just started android programming, wrote a quick code, and havn't managed to
I just started programming in Objective-C. Prior to this I was primarily a C#
This is my first post, and I've only recently started programming for Android and
I just started programming a week or two ago, so I apologize for the
sorry for this newb question, i just started programming with php I'm following Yahoo
I just started programming for android. I'm using a tab based layout in my
I'm new to Android app programming and started to read a book, but it

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.