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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:01:12+00:00 2026-06-10T10:01:12+00:00

Answered Mike suggested I added some code to the default: break; part of the

  • 0

Answered

Mike suggested I added some code to the

default:
break;

part of the switch. I added an exception to it, and there is no need to change anything else. The code now runs successfully. Thanks guys!


EDITED FOR READABILITY:

Error: “Description Resource Path Location Type
The local variable messages may not have been initialized TweetFragment.java /Offline Twitter/src/com/deadpixels/offline/twitter line 78 Java Problem”

for line:

int handleStartsAt = messages[i].indexOf('@');

And the same error happens twice on line 80, that being:

ph = messages[i].substring(handleStartsAt, messages[i].length());

As far as your questions, the

default:
break;

line was added as the int tweet type should only be either 0, 1, or 2. The function is called within a controlled environment and that way I am sure the call will not return an exception.

END OF EDIT.

I am trying to create a method to return a String array. This String array has a size that will change depending on the message type that is passed to the method as a parameter. I am having some issues getting this done, as apparently I am not initializing my variable; although, I think I am.

The variable I am having issues with is the “messages” array.

Bear in mind that I cannot declare the following:

String [] messages = new String [arrayLength];

As at this point in the call I do not know the length of the array. And I cannot do this:

String [] messages = null;

since after this, I will run into a runtime error, despite of not getting alerts at compile time.

Also, just to clarify, I would have though that:

messages = OfflineTwitter.mentions;

the above line would be initializing the variable, “OfflineTwitter.mentions” is an array, only stored in a different class.

Here is the code snippet.

public String[] getHandles (int tweetType) {

    int arrayLength = 0;
    String [] handles;
    String [] messages;

    switch (tweetType) {
    case 0:
        arrayLength = OfflineTwitter.mentions.length;
        messages = OfflineTwitter.mentions;
        break;
    case 1:
        arrayLength = OfflineTwitter.directMessages.length;
        messages = OfflineTwitter.directMessages;
        break;
    case 2:
        arrayLength = OfflineTwitter.allTweets.length;
        messages = OfflineTwitter.allTweets;
    default:
        break;
    }

    handles = new String [arrayLength];

    for (int i = 0; i < arrayLength; i++) {
        int handleStartsAt = messages[i].indexOf('@');
        String ph = "";
        ph = messages[i].substring(handleStartsAt, messages[i].length());
        int handleEndsAt = ph.indexOf(":");
        String sender = ph.substring(0, handleEndsAt);
        handles[i] = sender;
    }

    return handles;
}
  • 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-10T10:01:13+00:00Added an answer on June 10, 2026 at 10:01 am

    If tweetType < 0 || tweetType > 2 then

    default:
        break;
    

    is reached which does not assign a value to messages.

    You need to assign a value in the default branch, or throw an exception, or return so that the array is initialized at first use.

    Perhaps change that to

    default:
        throw new IllegalArgumentException("Invalid tweet type : " + tweetType);
    

    or ideally change tweetType to be an enum so that you can cover all cases exhaustively.

    enum TweetType {
      MENTIONS,
      DIRECT_MESSAGES,
      ALL_MESSAGES,
      ;
    }
    

    and change int tweetType to TweetType tweetType.

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

Sidebar

Related Questions

This question has been answered. Below is most of the code that you need
I've just answered problem with sockets in c# where in my example code I
As asked and answered in this post , I need to replace '[' with
We've been having some weird crashes in some Intel FORTRAN code, and I eventually
Answered: Result can bee seen here: http://apitecture.com/dev/cked/index.2.html Working code excerpt: $('a.color').on({ click : function()
Thanks to those who answered my last couple questions, I got the following code
After this was answered I continued to work my way through the code. It
Thanks to those who answered my last question I got the code below to
Recently answered this question with a change to a core file: Approach on changing
Someone answered in my past question and provided me with the code necessary to

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.