-2

I'm trying to have my network code run of a thread. I have a class that inherits from Thread. When I try to create a instance of it,

cSecureThread cRun=new cSecureThread(); 

I get the following error: "No enclosing instance of type cBitrex is accessible"

here is the code block

public class cSecureThread extends Thread { 
    String reply=null;
    String url;
    public void run()
    {
    //       GetSecureBitrexApi(url);           
    }

};


static String fn;
static String GetSecureBitrexApiThread( String url)
{

    // Line below creats error    
    cSecureThread cRun=new cSecureThread(); 
    cRun.url=url;
    System.out.println("XXXXXXXXXXXXXXXXX start thread XXXXXXXXXXXXXXXXXXXX");
    cRun.start();
    try {
        // wait 10 seconds to make api call
        cRun.join(1000*30);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    System.out.println("XXXXXXXXXXXXXXXXX end thread XXXXXXXXXXXXXXXXXXXX");
    fn= cRun.reply;
    return fn;    
}
dcsohl
  • 7,186
  • 1
  • 26
  • 44
Ted pottel
  • 6,869
  • 21
  • 75
  • 134
  • Btw FYI: http://stackoverflow.com/questions/541487/implements-runnable-vs-extends-thread – m0skit0 Jan 08 '15 at 19:10
  • Possible duplicate of [Java - No enclosing instance of type Foo is accessible](http://stackoverflow.com/questions/9560600/java-no-enclosing-instance-of-type-foo-is-accessible) – fabian Mar 03 '16 at 23:28

1 Answers1

0

It looks like this whole block of code is embedded in a class called "cBitrex". A non-static class defined inside another class maintains a reference to an instance of that outer class. It thus cannot be used inside a static method of that outer class. See here for more details.

So your fix probably is to declare

public static class cSecureThread extends Thread {
// ...
}

That is, just add the static keyword.

(Note I say "it looks like" and "probably" because you didn't provide a whole lot of context...)

Community
  • 1
  • 1
dcsohl
  • 7,186
  • 1
  • 26
  • 44