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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:23:47+00:00 2026-06-13T18:23:47+00:00

With the caveat I am fairly new to android programing I was having some

  • 0

With the caveat I am fairly new to android programing
I was having some trouble with an string array declaration along these lines

String[] title = {
"Abundance",
"Anxiety",
"Breakups",
"Bruxism"};

String[] name = {
"test1",
"test2",
"test3",
"test4"};

The problem arose when I made this change

String[] title = {
"Abundance",
"Anxiety",
"Breakups",
"Bruxism"};

String urlbase = "http://www.somewhere.com/data/";
String imgSel = "/logo.png";
String[] mStrings = new String[title.length];

for(int i=0;i<title.length;i++) {
    mStrings[i] = urlbase + title[i].toLowerCase() + imgSel;
    System.out.println(mStrings[i]);
}

and then on the System.out line I saw this error

Syntax error on token ";", { expected after this token

which confused me and other for a long time until I found something I had no method, all of the previous statements were made in the class declaration.

***learned something here

I saw this in another post and tried their solution which was to add this

public static void main(String[] args) {


}

around my ‘actions’ and this looked like the right thing and made sense so I tried it.
When I did it eclipse blew a screw and no gives me something really weird
I can’t even copy it but it shows up in the console window

<terminated> MainActivity (1) [Java Application] /System/Library/Frameworks/JavaVM.framework/Version/1.4/Home/bin/java (Nov 3, 2012 9:47:42 PM)

The bad part is that even if I erase the code and Clean the project that same error keeps occurring so code was that was working and I try this change see it stop working and remove the code sremains broken

The questions is two parts how do I fix this and what is the exact syntax I need to put in place so I can have my actions inside a method

Here is my original code which should work but it has no the for loop mentioned above is commented out this was actually working just not as I wanted it this my change but now it won’t even run due to my last attempt at a fix

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;

public class MainActivity extends Activity {

ListView list;
LazyAdapter adapter;

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

    list=(ListView)findViewById(R.id.list);
    adapter=new LazyAdapter(this, mStrings);
    list.setAdapter(adapter);

    Button b=(Button)findViewById(R.id.button1);
    b.setOnClickListener(listener);
}

@Override
public void onDestroy()
{
    list.setAdapter(null);
    super.onDestroy();
}

public OnClickListener listener=new OnClickListener(){

    public void onClick(View arg0) {
        adapter.imageLoader.clearCache();
        adapter.notifyDataSetChanged();
    }
};    

String[] title = {
        "Abundance",
        "Anxiety",
        "Breakups",
        "Bruxism",
        "Decisions",
        "Zen"

};

 //I put my fix for the method issue here and eclipse blew up
 //I also uncommented the appropriate lines and commented out the mStrings declaration and
 //assignment



  //   String[] mStrings= new String[title.length];

 //   String urlbase = "http://somewhere.com/data/";
 //   String imgSel = "/logo.png";
 //   for(int i=0;i<title.length;i++){
 //     mStrings[i] =  urlbase + title[9].replaceAll("[^a-zA-Z]", "").toLowerCase() + imgSel;
 //   }

    //String[] mStrings = new String[title.length];

    private String[] mStrings={
        "http://somewhere.com/data/abundance/logo.png",
        "http://somewhere.com/data/anxiety/logo.png",
        "http://somewhere.com/data/breakups/logo.png",
        "http://somewhere.com/data/bruxism/logo.png",
        "http://somewhere.com/data/decisions/logo.png",
        "http://somewhere.com/data/zen/logo.png"
    };   
}
  • 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-13T18:23:49+00:00Added an answer on June 13, 2026 at 6:23 pm
    public static void main(String[] args)
    

    The above belongs in basic Java programs, and is not suited to Android. It handles its own activities and other program entry points.

    Almost all code needs to be within a method, particularly if, while, for, etc. statements. We can put this code within onCreate, as that will be executed first.

    Here is the basic idea:

    public class MainActivity extends Activity {
        // List / Adapter variables here
    
        private String[] title = {
            "Abundance",
            "Anxiety",
            "Breakups",
            "Bruxism",
            "Decisions",
            "Zen"
        };
    
        private String[] mStrings = new String[title.length];
    
        // OnClickListener here
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            // super.onCreate and setContentView
    
            // Here is your for loop, untouched!
            String urlbase = "http://somewhere.com/data/";
            String imgSel = "/logo.png";
            for(int i=0;i<title.length;i++){
                mStrings[i] =  urlbase + title[9].replaceAll("[^a-zA-Z]", "").toLowerCase() + imgSel;
            }
    
            // More onCreate
        }
    
        // onDestroy method here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm fairly new to Android, but have done lots of Java/JSP development and HTML
Was messing around with some array stuff earlier and discovered a very peculiar caveat
Ok i am having some issues designing a base-class to handle generics. Caveat is
I need to find the longest sequence in a string with the caveat that
Caveat: new to Python. Wanting to hear from professionals who actually use it: What
[Caveat] This is not directly a programing question, but it is something that comes
I need some specific and some general advice. I'm a fairly proficient Java programmer
Prelim caveat: I am very new to js and have mainly gotten by through
First, a caveat: I'm brand new to C#, so please forgive me, if this
Caveat: I'm relatively new to coding as well as TextMate , so apologies if

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.