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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:22:27+00:00 2026-05-19T03:22:27+00:00

I Get force close when executed on Android emulator. I can’t figure out the

  • 0

I Get force close when executed on Android emulator. I can’t figure out the error. Here is code of Main Activity SimpleJokeList.java

    package edu.calpoly.android.lab2;

import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;

public class SimpleJokeList extends Activity {

    /** Contains the list Jokes the Activity will present to the user **/
    protected ArrayList<Joke> m_arrJokeList;

    /**
     * LinearLayout used for maintaining a list of Views that each display Jokes
     **/
    protected LinearLayout m_vwJokeLayout;

    /**
     * EditText used for entering text for a new Joke to be added to
     * m_arrJokeList.
     **/
    protected EditText m_vwJokeEditText;

    /**
     * Button used for creating and adding a new Joke to m_arrJokeList using the
     * text entered in m_vwJokeEditText.
     **/
    protected Button m_vwJokeButton;

    /**
     * Background Color values used for alternating between light and dark rows
     * of Jokes.  
     */
    protected int m_nDarkColor;
    protected int m_nLightColor;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initLayout();
        // TODO
        String[] jokestring=getResources().getStringArray(R.array.jokeList);    
        for(String str : jokestring) {
                addJoke(str);
            }
        }

    /**
     * Method used to encapsulate the code that initializes and sets the Layout
     * for this Activity. 
     */
    protected void initLayout() {
        // TODO
        m_vwJokeLayout=new LinearLayout(this);
        m_vwJokeLayout.setOrientation(LinearLayout.VERTICAL);
        ScrollView Sv=new ScrollView(this);
        Sv.addView(m_vwJokeLayout);
        setContentView(Sv);


    }

    /**
     * Method used to encapsulate the code that initializes and sets the Event
     * Listeners which will respond to requests to "Add" a new Joke to the 
     * list. 
     */
    protected void initAddJokeListeners() {
        // TODO
    }

    /**
     * Method used for encapsulating the logic necessary to properly initialize
     * a new joke, add it to m_arrJokeList, and display it on screen.
     * 
     * @param strJoke
     *            A string containing the text of the Joke to add.
     */
    protected void addJoke(String strJoke) {
        // TODO
        Joke j=new Joke(strJoke);
        m_arrJokeList.add(j);
        TextView TV=new TextView(this);
        m_vwJokeLayout.addView(TV);
        TV.setText(strJoke);
    }
}

Here is code of Joke.java

   package edu.calpoly.android.lab2;
public class Joke {
    public static final int UNRATED = 0;
    public static final int LIKE = 1;
    public static final int DISLIKE = 2;
    private String m_strJoke;
    private int m_nRating;
    public Joke() {
        //TODO
        m_strJoke="";
        m_nRating=UNRATED;
    }
    public Joke(String strJoke) {
        //TODO
        m_strJoke=strJoke;
        m_nRating=UNRATED;
    }
    public Joke(String strJoke, int nRating) {
        //TODO
        m_strJoke=strJoke;
        m_nRating=nRating;
    }
    public String getJoke() {
        //TODO
        return m_strJoke;
    }
    public void setJoke(String mstrJoke) {
        //TODO
        m_strJoke=mstrJoke;
    }
    public int getRating() {
        //TODO
        return m_nRating;
    }
    public void setRating(int rating) {
        //TODO
        m_nRating=rating;
    }
    @Override
    public String toString() {
        //TODO
        return m_strJoke;
    }
    @Override
    public boolean equals(Object obj) {
        //TODO
        boolean ret=false;
        if(obj!=null)
        {
            if(obj.getClass()==Joke.class)
                if(obj.toString().equals(this.m_strJoke))
                    ret=true;
        }
        else
            ret=false;

        return ret;
    }
}

Here is Code of Manifest.xml

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="edu.calpoly.android.lab2"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
        <uses-library android:name="android.test.runner" />
        <activity android:name=".SimpleJokeList"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-sdk android:minSdkVersion="4" />
    <instrumentation android:name="android.test.InstrumentationTestRunner"
                     android:targetPackage="edu.calpoly.android.lab2"
                     android:label="Tests for Api Demos."/>
</manifest> 
  • 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-19T03:22:27+00:00Added an answer on May 19, 2026 at 3:22 am

    You are not initializing m_arrJokeList

    try

     protected ArrayList<Joke> m_arrJokeList = new ArrayList<Joke> ();
    

    Note: Since you are overriding equals method in the Joke class, you should override the hashCode method aswell

    What issues should be considered when overriding equals and hashCode in Java?

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

Sidebar

Related Questions

I'm Trying to start the saveBookmark activity and I get Force Close for some
I get this error: Can't locate Foo.pm in @INC Is there an easier way
I'm trying to delete a bookmark using contentResolver.delete() and I get force close for
Can i get the source code for a WAMP stack installer somewhere? Any help
We get the following error; The request was aborted: Could not create SSL/TLS secure
I get an Access is Denied error message when I use the strong name
I get the following error when running my Visual Studio 2008 ASP.NET project (start
I get the following error when building my Windows Forms solution: LC.exe exited with
I get the following error when trying to run the latest Cygwin version of
I get this error on an update panel within a popupControlExtender which is within

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.