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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:49:56+00:00 2026-06-15T02:49:56+00:00

first I am a programming noob and I wanted to do something like taking

  • 0

first I am a programming noob and I wanted to do something like taking the user when he/she select Clear_data and it will take the person to Clear_data activity.

I am running in to a problem with try and catch, as I am still a bit lost in general programming. As I testing it when I select the first choice which is Text_Colour and it opens up the Clear_data activity instead of Text_Colour.

Here is the code:

public class Settings extends ListActivity {


String classes[] = { "Text_Colour", "Clear_data", "Contact Developer" };


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setListAdapter(new ArrayAdapter<String>(Settings.this, android.R.layout.simple_list_item_1, classes));
}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    super.onListItemClick(l, v, position, id);

    String colours = classes[0];
    String cdata = classes[1];

    try {
    Class Class1 = Class.forName("com.example.test1." + colours);
    Intent intent1 = new Intent(Settings.this, Class1);
    startActivity(intent1);
    }catch(ClassNotFoundException e) {
        e.printStackTrace();
    }
    try {
    Class Class2 = Class.forName("com.example.test1." + cdata);
    Intent intent2 = new Intent(Settings.this, Class2);
    startActivity(intent2);
    } 
    catch(ClassNotFoundException d) {
        d.printStackTrace();
    }   

}

Thanks for your time guys.

  • 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-15T02:49:58+00:00Added an answer on June 15, 2026 at 2:49 am

    You sholud probably add a switch operator like this:

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        // TODO Auto-generated method stub
        super.onListItemClick(l, v, position, id);
    
        String colours = classes[0];
        String cdata = classes[1];
    
    switch(position){
    case 0:
        try {
        Class Class1 = Class.forName("com.example.test1." + colours);
        Intent intent1 = new Intent(Settings.this, Class1);
        startActivity(intent1);
        }catch(ClassNotFoundException e) {
            e.printStackTrace();
        }
    break;
    case 1:
        try {
        Class Class2 = Class.forName("com.example.test1." + cdata);
        Intent intent2 = new Intent(Settings.this, Class2);
        startActivity(intent2);
        } 
        catch(ClassNotFoundException d) {
            d.printStackTrace();
        }   
    break;
    }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a total noob at Android programming, and wanted to learn how to debug
Hey all, first post and a noob in Android programming, but willing to learn!
Okay, first, I'm a noob at android programming. I have taken some Java, but
I am currently taking a parallel programming class and our first programming exercise was
I am taking my first steps programming in Lua and get this error when
I'm working on my first programming assignment for Java and I had another question.
I'm working on the first programming homework on Coursera's Algorithms: Design and Analysis course
I'm trying to land my first programming-related job, and I found a website for
I'm doing a homework assignment for my course in C (first programming course). Part
When I first started programming I always followed the convention of defining global variables

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.