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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:14:46+00:00 2026-05-26T10:14:46+00:00

NullPointerException error when running the program, I cant figure out why. the exact error

  • 0

NullPointerException error when running the program, I cant figure out why. the exact error is Exception in thread “main” java.lang.NullPointerException
at EditDistance.editDistance(EditDistance.java:32)
at EditDistance.main(EditDistance.java:19)

import java.util.ArrayList;


public class EditDistance 
{

public static void main(String[] args) 
{
    ArrayList<Character> a = new ArrayList<Character>();
    char[] xArray = null;
    char[]yArray = null;
    char[] finalY = null;
    String x = "AACAGTTACC";
    String y = "TAAGGTCA--";
    xArray = x.toCharArray();
    yArray = y.toCharArray();
    a = toArrayList(a , yArray);

    System.out.println(editDistance(a, xArray, finalY, y));


}

public static int editDistance(ArrayList<Character> a, char[] xArray, char[] finalY, String y)
{
    int temp;
    for(int i = 0; i<xArray.length; i++)
    {
        temp = y.indexOf(xArray[i]);
        if(temp != -1)
        {
            finalY[i] = a.get(temp);
            a.remove(temp);
            y = (y.substring(0, temp) + y.substring(temp));
        }

        else if(y.indexOf(xArray[i])==-1)
        {
            xArray[i]='z';
        }           

    }
    for(int j =0; j<xArray.length; j++)
    {
        if(xArray[j]=='z')
        {
            finalY[j]=a.get(j);
        }
    }

    int result = calcScore(finalY, xArray);
    return result;
}

public static ArrayList<Character> toArrayList(ArrayList<Character> a, char[] yArray)
{
    for(int i=0; i<yArray.length;i++)
    {
        a.add(yArray[i]);
    }
    return a;   
}

public static int calcScore(char[] finalY, char[] xArray )
{
    int number = 0;
    for(int i=0; i <xArray.length; i++ )
    {
        if( finalY[i]==(xArray[i]) )
        {

        }
        else if(finalY[i] == '-')
        {
            number++;
            number++;
        }
        else if (finalY[i] != xArray[i])
        {
            number++;
        }
    }

    return number;
}
}

any help is appreciated

  • 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-26T10:14:47+00:00Added an answer on May 26, 2026 at 10:14 am

    You set finalY to null, pass it to editDistance, then attempt to set one of its entries.

    If you want to modify it in editDistance, it must not be null.

    If finalY is not used outside of editDistance, it should not be a parameter: declare and allocate it inside the method.

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

Sidebar

Related Questions

I am having a runtime error that states Exception in thread AWT-EventQueue-0 java.lang.NullPointerException at
Exception in thread Thread-0 java.lang.NullPointerException at org.apache.http.impl.nio.reactor.AbstractIOReactor.closeActiveChannels(AbstractIOReactor.java:532) at org.apache.http.impl.nio.reactor.AbstractIOReactor.hardShutdown(AbstractIOReactor.java:564) at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.doShutdown(AbstractMultiworkerIOReactor.java:411) at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:340) at
06-29 01:24:15.882: ERROR/AndroidRuntime(747): Uncaught handler: thread main exiting due to uncaught exception 06-29 01:24:15.922:
My Logcat 08-06 01:27:34.874: ERROR/AndroidRuntime(721): Uncaught handler: thread main exiting due to uncaught exception
We're getting this error java.lang.NullPointerException at java.util.ArrayList.<init>(Unknown Source) at de.mystuff.ExtendedArrayList.<init>(ExtendedArrayList.java:38) where ExtendedArrayList:38 is new
While running the application I'm getting these errors 10-09 10:20:57.138: ERROR/AndroidRuntime(282): java.lang.RuntimeException: Unable to
What are Null Pointer Exceptions ( java.lang.NullPointerException ) and what causes them? What methods/tools
It doesn't seem to be working right now. I get a java.lang.NullPointerException I have
Logcat 08-17 06:37:22.264: ERROR/AndroidRuntime(1090): java.lang.RuntimeException: Unable to start activity ComponentInfo{one.two/one.two.Booking}: java.lang.NullPointerException 08-17 06:37:22.264: ERROR/AndroidRuntime(1090):
Hi iv been struggling with this error for some time and really cant figure

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.