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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:38:50+00:00 2026-06-09T03:38:50+00:00

im very new in developing an android app.. when i run my program in

  • 0

im very new in developing an android app.. when i run my program in the emulator it force close.. i figure it out that i need to set an nullpointerexception but i dont know where to set those stuff.. pls help me.

public class SampleActivity extends Activity {

TextView dp_octet1, dp_octet2, dp_octet3, dp_octet4, dp_slashes;
int i = 0;
int j = 0;
int octet[];

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sample);
    iniTextView();
    generatingRandomIpAddress();
}

private void generatingRandomIpAddress() {


   Random i = new Random();           //Random number between 0-2
   if(i.nextInt(3)==0){
       octet[0] = 8+(i.nextInt(22));
       octet[1] = 1+(i.nextInt(126));
   }
   if(i.nextInt(3)==1){
       octet[0] = 16+(i.nextInt(14));
       octet[1] = 128+(i.nextInt(63));
   }
   if(i.nextInt(3)==2){
       octet[0] = 24+(i.nextInt(6));
       octet[1] = 192+(i.nextInt(31));
   }
   octet[2] = (i.nextInt(255));
   octet[3] = (i.nextInt(255));
   octet[4] = (i.nextInt(255));

   //Display the problem
   dp_slashes.setText(octet[0]);
   dp_octet1.setText(octet[1]);
   dp_octet2.setText(octet[2]);
   dp_octet3.setText(octet[3]);
   dp_octet4.setText(octet[4]);

}



private void iniTextView() {
    // TODO Auto-generated method stub
    dp_octet1 = (TextView) findViewById(R.id.octet1);
    dp_octet2 = (TextView) findViewById(R.id.octet2);
    dp_octet3 = (TextView) findViewById(R.id.octet3);
    dp_octet4 = (TextView) findViewById(R.id.octet4);
    dp_slashes = (TextView) findViewById(R.id.slashes);
}

log cat

08-05 09:11:07.180: D/AndroidRuntime(1286): Shutting down VM
08-05 09:11:07.180: W/dalvikvm(1286): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
08-05 09:11:07.203: E/AndroidRuntime(1286): FATAL EXCEPTION: main
08-05 09:11:07.203: E/AndroidRuntime(1286): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myscratches/com.example.myscratches.SampleActivity}: java.lang.ArrayIndexOutOfBoundsException
08-05 09:11:07.203: E/AndroidRuntime(1286): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
08-05 09:11:07.203: E/AndroidRuntime(1286): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-05 09:11:07.203: E/AndroidRuntime(1286): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-05 09:11:07.203: E/AndroidRuntime(1286): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-05 09:11:07.203: E/AndroidRuntime(1286): at android.os.Handler.dispatchMessage(Handler.java:99)
08-05 09:11:07.203: E/AndroidRuntime(1286): at android.os.Looper.loop(Looper.java:123)
08-05 09:11:07.203: E/AndroidRuntime(1286): at android.app.ActivityThread.main(ActivityThread.java:4627)
08-05 09:11:07.203: E/AndroidRuntime(1286): at java.lang.reflect.Method.invokeNative(Native Method)
08-05 09:11:07.203: E/AndroidRuntime(1286): at java.lang.reflect.Method.invoke(Method.java:521)
08-05 09:11:07.203: E/AndroidRuntime(1286): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-05 09:11:07.203: E/AndroidRuntime(1286): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-05 09:11:07.203: E/AndroidRuntime(1286): at dalvik.system.NativeStart.main(Native Method)
08-05 09:11:07.203: E/AndroidRuntime(1286): Caused by: java.lang.ArrayIndexOutOfBoundsException
08-05 09:11:07.203: E/AndroidRuntime(1286): at com.example.myscratches.SampleActivity.generatingRandomIpAddress(SampleActivity.java:32)
08-05 09:11:07.203: E/AndroidRuntime(1286): at com.example.myscratches.SampleActivity.onCreate(SampleActivity.java:24)
08-05 09:11:07.203: E/AndroidRuntime(1286): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-05 09:11:07.203: E/AndroidRuntime(1286): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
08-05 09:11:07.203: E/AndroidRuntime(1286): … 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-09T03:38:52+00:00Added an answer on June 9, 2026 at 3:38 am

    You need to initialize octet before you can start assigning values to its elements. Change your declaration to:

    int octet[] = new int[4];
    

    Alternatively, add this line:

    octet = new int[4];
    

    to generatingRandomIpAddress() before you start assigning to the elements of octet.

    P.S. In the future, when you are asking for help with an exception, you should post the logcat output showing the stack trace for the exception.

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

Sidebar

Related Questions

I am very new to android and I am developing this app which allows
I am first time developing an android app. Very new to this. I have
I have been slowing learning and building my first android app. I'm VERY new
I'm developing an Android Application that has three very similar Activities. I would like
I'm very new to developing on Android and the Java language in general and
I am developing an android application that rely very much on internet, I retrieve
I am developing android application for Google TV. I am very new to Google
I'm very new to developing apps to android, so bear with me. Having said
I am very much new to cocos2d.. I am developing an application in android
I am very new to android. I am developing an application in android 2.2

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.