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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:21:10+00:00 2026-06-15T23:21:10+00:00

In my project I have a server that handles multiple clients that connect to

  • 0

In my project I have a server that handles multiple clients that connect to it. Each time a client is connected, a new “Guitar” is created, specific to that client on a new thread. Each “Guitar” is an array of 12 guitar strings, and when a key corresponding to a string is pressed in the client window, that guitar’s string is plucked.

I have a method called notePlayed(char key) in my Guitar class that “plucks” the string and adds all of the “plucks” into the combined audio to be played. However, I am running into this error anytime it is called:

key pressedj
Exception in thread "Thread-4" java.lang.NullPointerException
notePlayed accessed
at Guitar.notePlayed(Guitar.java:29)
at GuitarListener.run(GuitarServer.java:33)
at java.lang.Thread.run(Thread.java:680)

My guitarserver looks like this:

class GuitarListener implements Runnable {
private Socket sock;
private GuitarListenerGui gui;
private Guitar guitar;

public GuitarListener(Socket s, GuitarListenerGui g, Guitar gt) {
    this.sock = s;
    this.gui = g;
    this.guitar = gt;
}

public void run() {
    boolean loop=true;
    try {
        //setting up printwriters and bufferedreaders removed
        System.out.println("key pressed" + key);
        Guitar.notePlayed(key);
        }

with the new Guitar and threads created in the GuitarServer class further down

String keyboard ="qwertyuiop[]";
            GuitarString[] gStrings = new GuitarString[keyboard.length()];
            Guitar guitar = new Guitar(gStrings, keyboard);
            GuitarListener job = new GuitarListener(serverSocket.accept(), gui, guitar);

            // start a new thread to handle the connection
            Thread t = new Thread(job);
            t.start();

and my Guitar class looks like this:

public class Guitar {

private static String keyboard;;
private static GuitarString[] gStrings; 

public Guitar (GuitarString[] gStrings, String keyboard){
    this.keyboard=keyboard;
    this.gStrings=gStrings;
}

with the for-loop causing the error here:

    public static void notePlayed (char key){
  double sample=0.0;
               for (int i=0; i<keyboard.length(); i++){//adds all of the strings to sample to be played
                   sample+=gStrings[i].sample();        

Sorry about the length of the post, but can anybody point me in the right direction or let me know how far off I am? Thanks in advance. I am happy to answer anymore questions you may have.

In the main function of Guitar I initialize the guitarstrings with this loop:

for(int i=0;i<keyboard.length();i++){
        double iNote = 440.0* Math.pow(2, i/12.0);//puts the correct frequency with each string
        System.out.println(iNote);
        gStrings[i] = new GuitarString(iNote);
    }   
  • 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-15T23:21:12+00:00Added an answer on June 15, 2026 at 11:21 pm
     GuitarString[] gStrings = new GuitarString[keyboard.length()]; 
    

    will result in an array of GuitarString objects with the size of keyboard.length() all initialized with null value. You have to initialize each GuitarString object in the array before using it in the for loop in the line sample+=gStrings[i].sample();

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

Sidebar

Related Questions

I have created a separate project to connect my server component to clients using
We have a Flex client and a server that is using the Spring/Blazeds project.
I have an RMI server that is using a class from another project. I
in the tomcat6 server I have a project that contains a servlet, I called
I have a project that I've added to my Jenkins server. The project includes
We have a project that uses JPA/Hibernate on the server side, the mapped entity
I have one project inside that I have SqlServerFunctions in test.cs file. code: [Microsoft.SqlServer.Server.SqlFunction]
I have a django project that runs on a Linux server, and I've been
I have a large project that runs on an application server. It does pipelined
We have an ASP.Net MVC project that will start with a single web server

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.