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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:56:59+00:00 2026-05-30T19:56:59+00:00

i have Target.java(it is the main activity) and Layout.java. When user clicks a button

  • 0

i have Target.java(it is the main activity) and Layout.java.
When user clicks a button a url opens.
The button click is handled in Layout.java.

    deleteButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
             DebugLog.LOGD("Within onClick event of 'GO' button ");
            Target.openURL();

        }
    });

Target.java has a static function openURL

    public static void openURL() {
     Uri uri = Uri.parse("http://www.thecinema.in");
     Intent intent = new Intent(Intent.ACTION_VIEW, uri);
     startActivity(intent);

     }

I’d like to know how i can make this code work, since the error im getting now is “Cannot make a static reference to the non-static method startActivity(Intent) from the type Activity” . I can understand startActivity will not work within a static function, but please suggest me how i could acheive the objective ..Im a newbie to android.FYI ..Thanks guys

-Updated code :
Layout.java

    deleteButton.setOnClickListener(new View.OnClickListener() {
      public void onClick(View v) {
             DebugLog.LOGD("Within onClick event of 'GO' button ");
            Target iA = new Target();
            iA.openURL();


        }
    });

Target.java

     public void openURL() {    //removed static keyword
     DebugLog.LOGD("Within nDelete event of GO button ");

     Uri uri = Uri.parse("http://www.thecinema.in");
     Intent intent = new Intent(Intent.ACTION_VIEW, uri);
     intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
     startActivity(intent);

 }

Exception thrown:

    03-02 10:10:28.351: D/QCAR(6820): Within onClick event of 'GO' button 
    03-02 10:10:28.351: W/dalvikvm(6820): threadid=1: thread exiting with uncaught exception (group=0x400207d8)
    03-02 10:10:28.361: E/AndroidRuntime(6820): FATAL EXCEPTION: main
    03-02 10:10:28.361: E/AndroidRuntime(6820): java.lang.NullPointerException
    03-02 10:10:28.361: E/AndroidRuntime(6820):     at android.app.Activity.startActivityForResult(Activity.java:2817)
    03-02 10:10:28.361: E/AndroidRuntime(6820):     at android.app.Activity.startActivity(Activity.java:2923)
    03-02 10:10:28.361: E/AndroidRuntime(6820):     at com.ingage.pocs.phonegap.Layout$4.onClick(Layout.java:124)
    03-02 10:10:28.361: E/AndroidRuntime(6820):     at android.view.View.performClick(View.java:2408)
    03-02 10:10:28.361: E/AndroidRuntime(6820):     at android.view.View$PerformClick.run(View.java:8816)
    03-02 10:10:28.361: E/AndroidRuntime(6820):     at android.os.Handler.handleCallback(Handler.java:587)
    03-02 10:10:28.361: E/AndroidRuntime(6820):     at  android.os.Handler.dispatchMessage(Handler.java:92)
    03-02 10:10:28.361: E/AndroidRuntime(6820):     at android.os.Looper.loop(Looper.java:123)
    03-02 10:10:28.361: E/AndroidRuntime(6820):     at android.app.ActivityThread.main(ActivityThread.java:4633)

Guys what went wrong in here..

  • 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-30T19:57:00+00:00Added an answer on May 30, 2026 at 7:57 pm

    i was able to come up with a solution for this question.
    Under Target.java i created openURL() as:

         public void openURL(Context context) 
        {
         Intent intent = new Intent("com.ingage.pocs.phonegap.URL");
         intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         context.startActivity(intent);
         }
    

    I created a new Activity OpenURL.java and associated the intent “com.ingage.pocs.phonegap.URL” with it:

        package com.ingage.pocs.phonegap;
    
        import android.app.Activity;
        import android.content.Intent;
        import android.net.Uri;
        import android.os.Bundle;
    
        public class OpenURL extends Activity{
    
            @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        DebugLog.LOGD("Within BookTicketsActivity Activity GO button ");
    
        Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.thecinema.in"));
        startActivity(browserIntent);
    
    }
    

    }

    Layout.java:

        private Context applicationContext;
    
        deleteButton.setOnClickListener(new View.OnClickListener() {
          public void onClick(View v) {
             DebugLog.LOGD("Within onClick event of 'GO' button ");
            ImageTargets ia =new ImageTargets();
                 ia.openURL(applicationContext);
            iA.openURL();
    
    
        }
    });
    

    The best thing is, it worked 🙂 If you guys come up with a better or more sensible solution , pls do post here.thank you

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

Sidebar

Related Questions

I have written a java annotation that looks like this: @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) // can
I have a Maven Java project, imported using m2eclipse . The target/ directory is
Let's consider the below example. There, I have: target MAIN calls target t and
I have java class files and property files in the same directory. src/main/java/com/berlin/Test.class src/main/java/com/berlin/Test.properties
I have a web application with a following structure: src + main +-+ java
I have following target in mz ant script to build my java application <target
I have written two simple Java classes (one of them containing main(), and the
I have a java project with class having main method in package com.nik.mypackage. Only
I have the Target Framework set to 2.0 on my windows application, yet when
I have set the target of the pic_form to a div (pic_target). The form

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.