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

  • Home
  • SEARCH
  • 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 8003813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:45:08+00:00 2026-06-04T16:45:08+00:00

In learning android I’m making an ICMP ping program. I added an AsyncTask thread

  • 0

In learning android I’m making an ICMP ping program. I added an AsyncTask thread to prevent “networking in main” and now my programming is throwing this run time exception (the one in the title). I’m new to android; if you guys could help me out that would be really great. Here the problematic logcat errors:

05-30 13:52:49.644: E/AndroidRuntime(620): FATAL EXCEPTION: main
05-30 13:52:49.644: E/AndroidRuntime(620): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.icmpping.Joe/com.icmpping.Joe.PingAppActivity}: java.lang.NullPointerException
05-30 13:52:49.644: E/AndroidRuntime(620):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880)
05-30 13:52:49.644: E/AndroidRuntime(620):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
05-30 13:52:49.644: E/AndroidRuntime(620):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
05-30 13:52:49.644: E/AndroidRuntime(620):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
05-30 13:52:49.644: E/AndroidRuntime(620):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-30 13:52:49.644: E/AndroidRuntime(620):  at android.os.Looper.loop(Looper.java:137)
05-30 13:52:49.644: E/AndroidRuntime(620):  at android.app.ActivityThread.main(ActivityThread.java:4424)
05-30 13:52:49.644: E/AndroidRuntime(620):  at java.lang.reflect.Method.invokeNative(Native Method)
05-30 13:52:49.644: E/AndroidRuntime(620):  at java.lang.reflect.Method.invoke(Method.java:511)
05-30 13:52:49.644: E/AndroidRuntime(620):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-30 13:52:49.644: E/AndroidRuntime(620):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-30 13:52:49.644: E/AndroidRuntime(620):  at dalvik.system.NativeStart.main(Native Method)
05-30 13:52:49.644: E/AndroidRuntime(620): Caused by: java.lang.NullPointerException
05-30 13:52:49.644: E/AndroidRuntime(620):  at android.app.Activity.findViewById(Activity.java:1794)
05-30 13:52:49.644: E/AndroidRuntime(620):  at com.icmpping.Joe.PingAppActivity.<init>(PingAppActivity.java:15)
05-30 13:52:49.644: E/AndroidRuntime(620):  at java.lang.Class.newInstanceImpl(Native Method)
05-30 13:52:49.644: E/AndroidRuntime(620):  at java.lang.Class.newInstance(Class.java:1319)
05-30 13:52:49.644: E/AndroidRuntime(620):  at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
05-30 13:52:49.644: E/AndroidRuntime(620):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
05-30 13:52:49.644: E/AndroidRuntime(620):  ... 11 more

I’m pretty sure this has something to do with AsyncTask. The ICMP_Ping.ping method is from another class which returns a String object and takes a String parameter. It uses java.net.InetAddress and System.currentTimeMillis(). Anyway, here is my main class:

////

package com.icmpping.Joe;

import android.app.Activity;
import android.os.AsyncTask;
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;
import android.widget.TextView;

public class PingAppActivity extends Activity {

private TextView console = (TextView) findViewById(R.id.TEXT_STATUS_ID);

private OnClickListener listener = new OnClickListener() {
    public void onClick(View v) {

        Log.d("pingactivity", "Hey LOGCAT2");

        EditText urlbox = (EditText) findViewById(R.id.url_edittext);
        String url = urlbox.getText().toString();

        Log.d("pingactivity", "Hey LOGCAT3");
        new AsyncPing().execute(url);


        Log.d("pingactivity", "Hey LOGCAT4");
    }
};


public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Log.d("pingactivity", "Hey LOGCAT0");

    Button pingbutton = (Button) findViewById(R.id.ping_button);

    pingbutton.setOnClickListener(listener);
    Log.d("pingactivity", "Hey LOGCAT1");

}


private class AsyncPing extends AsyncTask<String, Void, String> {

    @Override
    protected String doInBackground(String... url) {
        return ICMP_Ping.ping(url[0]);
    }

    //protected void onProgressUpdate(Integer... progress) {}

    protected void onPostExecute(String pingresult) {
        console.append(pingresult);

    }
}

}

  • 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-04T16:45:11+00:00Added an answer on June 4, 2026 at 4:45 pm

    this line TextView console = (TextView) findViewById(R.id.yourtextid);

    put after setContentView(R.layout.main);

     

        TextView console;
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            Log.d("pingactivity", "Hey LOGCAT0");
    
            Button pingbutton = (Button) findViewById(R.id.ping_button);
            console = (TextView) findViewById(R.id.yourtextid);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Newb question. How can you know what the main launch Activity is? Learning Android.
I'm learning android now, and i write some simple codes according to the book.
basic question - I'm still learning Android - trying to create a seperate thread
I'm currently learning Android programming and the way I used to create command buttons
I've been learning Android for about two weeks now (expert in as2/3). I have
I started learning android programming a couple of weeks ago. I am a beginner
I'm learning Android programming, and I want to make an application which has to
I am a noob learning Android and making my own little demo project at
I'm just learning Android programming. The way I understand it is that the services
I'm learning Android development. I have a basic app running on the Gingerbread emulator,

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.