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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:45:25+00:00 2026-05-28T20:45:25+00:00

I have a submenu that contains 3 choices for the user. Each option when

  • 0

I have a submenu that contains 3 choices for the user. Each option when chosen calls one of the 3 functions below:

    void viewLast5Packets()
{
    userDefinedCount = 4;
    prefEditor.putString(lastpacketsPHP, "/* Put PHP file link here */");
    prefEditor.commit();
    assignInfoToHistoryTextView();
}

void viewLast10Packets()
{
    userDefinedCount = 9;
    prefEditor.putString(lastpacketsPHP, "/* Put PHP file link here */");
    prefEditor.commit();
    assignInfoToHistoryTextView();
}

void viewLast20Packets()
{
    userDefinedCount = 19;
    prefEditor.putString(lastpacketsPHP, "/* Put PHP file link here */");
    prefEditor.commit();
    assignInfoToHistoryTextView();
}

Each function creates a shared preference called lastpacketsPHP and puts a different URL into the preference. When assignInfoToHistoryTextView is called it calls another function located in a different class file. The class is shown below:

package shc_BalloonSat.namespace;

import java.text.DecimalFormat;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.SubMenu;
import android.widget.TextView;
import android.widget.Toast;

public class Shc_BalloonSat_Activity extends Activity
{
int historyCountFromUser;
httpAPI api = new httpAPI(this);
kmlAPI kml = new kmlAPI(this);
DecimalFormat df = new DecimalFormat("##.#####");
DecimalFormat decimalf = new DecimalFormat("##.######");
SharedPreferences pref;
Editor prefEditor;
String lastpacketsPHP;

// User to determine how many packet the user would like to see.
int userDefinedCount = 4;

/** Called when the activity is first created. 
 * @param view */

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    String returned = null;
    prefEditor.putString(lastpacketsPHP, "http://www.wktechnologies.com/shc_android_app/get_last_5_BS_packets.php");

    try
    {
        returned = api.getData();
    }

    catch (Exception e)
    {
        e.printStackTrace();
    }

    TextView infoTV = (TextView)this.findViewById(R.id.info);
    infoTV.setText(returned);
    assignInfoToInfoTextView();
    assignInfoToHistoryTextView();
}

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.mainmenu, menu);

    SubMenu submenu = menu.addSubMenu(0, Menu.FIRST, Menu.NONE, "Preferences");
    submenu.add(0, 5, Menu.NONE, "Get Last 5 Packets");
    submenu.add(0, 10, Menu.NONE, "Get Last 10 Packets");
    submenu.add(0, 20, Menu.NONE, "Get Last 20 Packets");
    inflater.inflate(R.menu.mainmenu, submenu);

    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item)
{
    // Handle item selection
    switch (item.getItemId())
    {
        case R.id.viewKML:
            viewKML();
            return true;
        case 5:
            viewLast5Packets();
            return true;
        case 10:
            viewLast10Packets();
            return true;
        case 20:
            viewLast5Packets();
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}

public void assignInfoToInfoTextView()
{
    TextView infoTV = (TextView)this.findViewById(shc_BalloonSat.namespace.R.id.info); 

    try
    {
        JSONArray jArray = new JSONArray(api.result);
        for (int count = 0; count < 2; count++)
        {
            JSONObject json_data = jArray.getJSONObject(count);

            double altitudeData = json_data.getDouble("altitude");
            String infoText = "Last Known Altitude: " + df.format(altitudeData) + "\n";

            Double speedData = json_data.optDouble("speed");

            if (speedData.isNaN())
            {
                speedData = 0.00;
            }

            infoText += "Last Known Speed: " + df.format(speedData) + "\n";

            double recentLatitudeData = json_data.getDouble("latitude");
            infoText += "Last Known Latitude: " + df.format(recentLatitudeData) + "\n";

            double recentLongitudeData = json_data.getDouble("longitude");
            infoText += "Last Known Longtitude: " + df.format(recentLongitudeData) + "\n";

            infoTV.setText(infoText);
        }
    }

    catch (JSONException e)
    {
        // TODO Auto-generated catch block
        Log.e("<tag>", e.getMessage());
        Toast.makeText(this,"Error in (Last Known) method!",Toast.LENGTH_SHORT).show();
    }
}

public void assignInfoToHistoryTextView()
{
    try
    {
        JSONArray jArray = new JSONArray(api.result);

        for (int count = 1; count <= userDefinedCount; count++)
        {
            TextView historyTV = (TextView)this.findViewById(shc_BalloonSat.namespace.R.id.history);
            JSONObject json_data = jArray.getJSONObject(count);

            double altitudeData = json_data.getDouble("altitude");
            String historyText = "Altitude: " + decimalf.format(altitudeData) + "\n";

            Double speedData = json_data.optDouble("speed");

            if (speedData.isNaN())
            {
                speedData = 0.00;
            }

            historyText += "Speed: " + df.format(speedData) + "\n";

            double latitudeData = json_data.getDouble("latitude");
            historyText += "Latitude: " + df.format(latitudeData) + "\n";

            double longitudeData = json_data.getDouble("longitude");
            historyText += "Longtitude: " + df.format(longitudeData) + "\n\n";

            historyTV.append(historyText);
        }
    }

    catch (JSONException e)
    {
        // TODO Auto-generated catch block
        Log.e("log_tag", "Error parsing data: " + e.toString());
    }

}

void viewLast5Packets()
{
    userDefinedCount = 4;
    prefEditor.putString(lastpacketsPHP, "http://www.wktechnologies.com/shc_android_app/get_last_5_BS_packets.php");
    prefEditor.commit();
    assignInfoToHistoryTextView();
}

void viewLast10Packets()
{
    userDefinedCount = 9;
    prefEditor.putString(lastpacketsPHP, "http://www.wktechnologies.com/shc_android_app/get_last_10_BS_packets.php");
    prefEditor.commit();
    assignInfoToHistoryTextView();
}

void viewLast20Packets()
{
    userDefinedCount = 19;
    prefEditor.putString(lastpacketsPHP, "http://www.wktechnologies.com/shc_android_app/get_last_20_BS_packets.php");
    prefEditor.commit();
    assignInfoToHistoryTextView();
}

public void viewKML()
{
    kml.openKML();
}
}

In the httpPost I’m trying to set it so that it will call whichever PHP file was chosen depending on what option was chosen by the user. I’m doing this by inserting get the value of the preference and putting that in the httpPost. When I run the app in the emulator it crashes immediately and it didn’t happen until I put the preference code in the httpPost so I know my syntax is wrong I just don’t know what I’m doing wrong. Any help will be greatly appreciated.

I get these errors at runtime with the code above:

02-02 13:42:14.973: E/AndroidRuntime(230): Uncaught handler: thread main exiting due to uncaught exception
02-02 13:42:15.213: D/dalvikvm(230): GC freed 3178 objects / 319424 bytes in 131ms
02-02 13:42:15.283: E/AndroidRuntime(230): java.lang.StackOverflowError
02-02 13:42:15.283: E/AndroidRuntime(230):  at java.lang.Thread.currentThread(Thread.java:588)
02-02 13:42:15.283: E/AndroidRuntime(230):  at java.lang.ThreadLocal.get(ThreadLocal.java:59)
02-02 13:42:15.283: E/AndroidRuntime(230):  at android.os.Looper.myLooper(Looper.java:137)
02-02 13:42:15.283: E/AndroidRuntime(230):  at android.os.Handler.<init>(Handler.java:119)
02-02 13:42:15.283: E/AndroidRuntime(230):  at android.app.Activity.<init>(Activity.java:673)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.Shc_BalloonSat_Activity.<init>(Shc_BalloonSat_Activity.java:21)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.httpAPI.<init>(httpAPI.java:20)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.Shc_BalloonSat_Activity.<init>(Shc_BalloonSat_Activity.java:24)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.httpAPI.<init>(httpAPI.java:20)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.Shc_BalloonSat_Activity.<init>(Shc_BalloonSat_Activity.java:24)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.httpAPI.<init>(httpAPI.java:20)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.Shc_BalloonSat_Activity.<init>(Shc_BalloonSat_Activity.java:24)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.httpAPI.<init>(httpAPI.java:20)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.Shc_BalloonSat_Activity.<init>(Shc_BalloonSat_Activity.java:24)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.httpAPI.<init>(httpAPI.java:20)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.Shc_BalloonSat_Activity.<init>(Shc_BalloonSat_Activity.java:24)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.httpAPI.<init>(httpAPI.java:20)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.Shc_BalloonSat_Activity.<init>(Shc_BalloonSat_Activity.java:24)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.httpAPI.<init>(httpAPI.java:20)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.Shc_BalloonSat_Activity.<init>(Shc_BalloonSat_Activity.java:24)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.httpAPI.<init>(httpAPI.java:20)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.Shc_BalloonSat_Activity.<init>(Shc_BalloonSat_Activity.java:24)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.httpAPI.<init>(httpAPI.java:20)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.Shc_BalloonSat_Activity.<init>(Shc_BalloonSat_Activity.java:24)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.httpAPI.<init>(httpAPI.java:20)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.Shc_BalloonSat_Activity.<init>(Shc_BalloonSat_Activity.java:24)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.httpAPI.<init>(httpAPI.java:20)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.Shc_BalloonSat_Activity.<init>(Shc_BalloonSat_Activity.java:24)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.httpAPI.<init>(httpAPI.java:20)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.Shc_BalloonSat_Activity.<init>(Shc_BalloonSat_Activity.java:24)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.httpAPI.<init>(httpAPI.java:20)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.Shc_BalloonSat_Activity.<init>(Shc_BalloonSat_Activity.java:24)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.httpAPI.<init>(httpAPI.java:20)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.Shc_BalloonSat_Activity.<init>(Shc_BalloonSat_Activity.java:24)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.httpAPI.<init>(httpAPI.java:20)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.Shc_BalloonSat_Activity.<init>(Shc_BalloonSat_Activity.java:24)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.httpAPI.<init>(httpAPI.java:20)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.Shc_BalloonSat_Activity.<init>(Shc_BalloonSat_Activity.java:24)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.httpAPI.<init>(httpAPI.java:20)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.Shc_BalloonSat_Activity.<init>(Shc_BalloonSat_Activity.java:24)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.httpAPI.<init>(httpAPI.java:20)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.Shc_BalloonSat_Activity.<init>(Shc_BalloonSat_Activity.java:24)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.httpAPI.<init>(httpAPI.java:20)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.Shc_BalloonSat_Activity.<init>(Shc_BalloonSat_Activity.java:24)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.httpAPI.<init>(httpAPI.java:20)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.Shc_BalloonSat_Activity.<init>(Shc_BalloonSat_Activity.java:24)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.httpAPI.<init>(httpAPI.java:20)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.Shc_BalloonSat_Activity.<init>(Shc_BalloonSat_Activity.java:24)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.httpAPI.<init>(httpAPI.java:20)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.Shc_BalloonSat_Activity.<init>(Shc_BalloonSat_Activity.java:24)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.httpAPI.<init>(httpAPI.java:20)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.Shc_BalloonSat_Activity.<init>(Shc_BalloonSat_Activity.java:24)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.httpAPI.<init>(httpAPI.java:20)
02-02 13:42:15.283: E/AndroidRuntime(230):  at shc_BalloonSat.namespace.Shc_BalloonSat_Activity.<init>(Shc_BalloonSat_Activity.

02-02 13:42:15.373: I/dalvikvm(230): threadid=7: reacting to signal 3
02-02 13:42:15.373: E/dalvikvm(230): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
  • 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-28T20:45:26+00:00Added an answer on May 28, 2026 at 8:45 pm
    public class httpAPI
    {
        Shc_BalloonSat_Activity shc;
    
        ...
    
            httppost = new HttpPost(shc.pref.getString(shc.lastpacketsPHP,
                                    shc.lastpacketsPHP.toString()));
    

    Initially, the trouble was that shc was being used without being initialized. Following up with the question, since the HttpPost object needs a SharedPreferences instance (which is accessible via a context), I’d suggest adding a constructor to the httpAPI class. For example:

    public class httpAPI {
    
        Shc_BalloonSat_Activity shc;
        HttpPost httppost;
    
        ...
    
        public httpAPI(Shc_BalloonSat_Activity aContext) {
            shc = aContext;
        }
    
        ...
    
        public String getData() throws Exception {
            ...
            httppost = new HttpPost(shc.pref.getString(shc.lastpacketsPHP, shc.lastpacketsPHP.toString());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a submenu that list departments. Behind this each department have an action
I have a submenu that has all items linked to the same node, but
I have a menu that contains submenus. Its HTML source looks like this: <ul
I have a nib (winA.xib) that contains a window. My app delegate contains an
I'm attempting to setup a MenuItem that will have a submenu of page numbers
I have an application that contains Menu and sub menus. I have attached Appliocation
I have a wrapper containing an inner wrapper, and that inner wrapper contains 2
I have a menu structure (Drupal) that contains elements representing a menu link. If
I have a horizontal menu that contains buttons. Clicking on the button opens a
I have a pop-up submenu that when you hover your mouse over the parent

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.