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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:29:15+00:00 2026-06-16T04:29:15+00:00

I have a problem with accessing activity’s method from fragment. Or anything int the

  • 0

I have a problem with accessing activity’s method from fragment.
Or anything int the activity from the fragment.

Here’s fragment code:

public class MainFragment extends Fragment {

private MainActivity ma = (MainActivity) getActivity();
public SipAudioCall call = null;
public SipManager mSipManager = null;
public SipProfile mSipProfile = null;



public MainFragment() {
    // TODO Auto-generated constructor stub

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    // Create a new TextView and set its text to the fragment's section
    // number argument value.
    LinearLayout mLinearLayout = (LinearLayout) inflater.inflate(R.layout.main_layout, container, false);

    final Button callbtn = (Button) mLinearLayout.findViewById(R.id.callbtn);
    final Button endbtn = (Button) mLinearLayout.findViewById(R.id.endbtn);



    callbtn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            callbtn.setVisibility(View.GONE);
            endbtn.setVisibility(View.VISIBLE);
            ma.initiateCall();    
        }
    });

Maybe casting the activity is wrong?
Thx in advance

  • 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-16T04:29:17+00:00Added an answer on June 16, 2026 at 4:29 am

    I’m guessing that the fragment is not attached to the activity when u call getActivity(). Try to initialize the activity reference in the fragment method onAttach().

    So something like this:

    @Override
        public void onAttach(Activity activity) {
            super.onAttach(activity);
            try {
                ma = (MainActivity) activity;
            } catch (ClassCastException e) {
                throw new ClassCastException(activity.toString() + " Not MainActivity class instance");
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with accessing parents (non-static) property in child class static method.
I have problem accessing content from an Illustrator SWF(I create the swf using illustrator,
I have a problem accessing the 'event' in Firefox. The following code works fine
I have problem on accessing the form data from a formset. I attached the
I have the following code for my fragment. I pretty much took this from
I have a problem accessing JSON data. I'm new to JSON and jquery so
i have problem with libhid . i found that there 2 way 4 accessing
I am having a problem accessing the ViewData object through javascript. I have set
I have problem with UIWebView delay when the load image from url. In my
I have a strange problem when accessing android sqlite datbase. I have a line

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.