Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #9281 > unrolled thread

nested class madness

Started bybob <bob@coolgroups.com>
First post2011-10-28 10:40 -0700
Last post2011-10-28 22:49 -0700
Articles 5 — 3 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  nested class madness bob <bob@coolgroups.com> - 2011-10-28 10:40 -0700
    Re: nested class madness Steven Simpson <ss@domain.invalid> - 2011-10-28 19:17 +0100
      Re: nested class madness bob <bob@coolgroups.com> - 2011-10-28 23:25 -0700
      Re: nested class madness Roedy Green <see_website@mindprod.com.invalid> - 2011-10-29 06:38 -0700
    Re: nested class madness Roedy Green <see_website@mindprod.com.invalid> - 2011-10-28 22:49 -0700

#9281 — nested class madness

Frombob <bob@coolgroups.com>
Date2011-10-28 10:40 -0700
Subjectnested class madness
Message-ID<5bee3b28-8226-4c21-92d3-f85db5810d3c@l19g2000yqc.googlegroups.com>
Can someone explain why I get this error?

ProgressThread cannot be resolved to a type

Here's the code:

package com.coolfone.notetest;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class NotificationTestActivity extends Activity {

    static final int PROGRESS_DIALOG = 0;
    Button button;
    ProgressThread progressThread;
    ProgressDialog progressDialog;

    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // Setup the button that starts the progress dialog
        button = (Button) findViewById(R.id.progressDialog);
        button.setOnClickListener(new OnClickListener(){
            public void onClick(View v) {
                showDialog(PROGRESS_DIALOG);
            }
        });
    }

    protected Dialog onCreateDialog(int id) {
        switch(id) {
        case PROGRESS_DIALOG:
            progressDialog = new
ProgressDialog(NotificationTestActivity.this);

progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            progressDialog.setMessage("Loading...");
            return progressDialog;
        default:
            return null;
        }
    }

    @Override
    protected void onPrepareDialog(int id, Dialog dialog) {
        switch(id) {
        case PROGRESS_DIALOG:
            progressDialog.setProgress(0);
            progressThread = new ProgressThread(handler);
            progressThread.start();
    }

    // Define the Handler that receives messages from the thread and
update the progress
    final Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            int total = msg.arg1;
            progressDialog.setProgress(total);
            if (total >= 100){
                dismissDialog(PROGRESS_DIALOG);
                progressThread.setState(ProgressThread.STATE_DONE);
            }
        }
    };

    /** Nested class that performs progress calculations (counting) */
    final class ProgressThread extends Thread {
        Handler mHandler;
        final static int STATE_DONE = 0;
        final static int STATE_RUNNING = 1;
        int mState;
        int total;

        ProgressThread(Handler h) {
            mHandler = h;
        }

        public void run() {
            mState = STATE_RUNNING;
            total = 0;
            while (mState == STATE_RUNNING) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    Log.e("ERROR", "Thread Interrupted");
                }
                Message msg = mHandler.obtainMessage();
                msg.arg1 = total;
                mHandler.sendMessage(msg);
                total++;
            }
        }

        /* sets the current state for the thread,
         * used to stop the thread */
        public void setState(int state) {
            mState = state;
        }
    }

}
}

[toc] | [next] | [standalone]


#9282

FromSteven Simpson <ss@domain.invalid>
Date2011-10-28 19:17 +0100
Message-ID<278rn8-4f2.ln1@news.simpsonst.f2s.com>
In reply to#9281
On 28/10/11 18:40, bob wrote:
> Can someone explain why I get this error?
>
> ProgressThread cannot be resolved to a type

You should indicate where the error appears too.

>      @Override
>      protected void onPrepareDialog(int id, Dialog dialog) {
>          switch(id) {
>          case PROGRESS_DIALOG:
>              progressDialog.setProgress(0);
>              progressThread = new ProgressThread(handler);
>              progressThread.start();
>      }

This looks like the whole of onPrepareDialog, but it's missing a brace.  
Reformat the entire file, and you'll see that ProgressThread is nested 
within this function, and is not a direct member of the enclosing class.

-- 
ss at comp dot lancs dot ac dot uk

[toc] | [prev] | [next] | [standalone]


#9292

Frombob <bob@coolgroups.com>
Date2011-10-28 23:25 -0700
Message-ID<42a910e3-c751-4166-b685-f5e2bdf948d0@t8g2000yql.googlegroups.com>
In reply to#9282
On Oct 28, 11:17 am, Steven Simpson <s...@domain.invalid> wrote:
> On 28/10/11 18:40, bob wrote:
>
> > Can someone explain why I get this error?
>
> > ProgressThread cannot be resolved to a type
>
> You should indicate where the error appears too.
>
> >      @Override
> >      protected void onPrepareDialog(int id, Dialog dialog) {
> >          switch(id) {
> >          case PROGRESS_DIALOG:
> >              progressDialog.setProgress(0);
> >              progressThread = new ProgressThread(handler);
> >              progressThread.start();
> >      }
>
> This looks like the whole of onPrepareDialog, but it's missing a brace.  
> Reformat the entire file, and you'll see that ProgressThread is nested
> within this function, and is not a direct member of the enclosing class.
>
> --
> ss at comp dot lancs dot ac dot uk

You're right.

This is where I got the code from:

http://developer.android.com/guide/topics/ui/dialogs.html

Looks like Google goofed.

[toc] | [prev] | [next] | [standalone]


#9296

FromRoedy Green <see_website@mindprod.com.invalid>
Date2011-10-29 06:38 -0700
Message-ID<jb0oa7h8g5pr3hobtln9da0l2dnq0mr8lm@4ax.com>
In reply to#9282
On Fri, 28 Oct 2011 19:17:38 +0100, Steven Simpson <ss@domain.invalid>
wrote, quoted or indirectly quoted someone who said :

>This looks like the whole of onPrepareDialog, but it's missing a brace
IDEs are good at this.  See http://mindprod.com/jgloss/ide.html

For really intractable cases, use the BraceBalancer. See
http://mindprod.com/products1.html#BRACEBALANCER
-- 
Roedy Green Canadian Mind Products
http://mindprod.com
It's difficult to be rigorous about whether a machine really knows,
thinks, etc., because we’re hard put to define these things. 
We understand human mental processes only slightly better than
a fish understands swimming. 
~ John McCarthy (born: 1927-09-04 died: 2011-10-23 at age: 84).
Inventor of the term AI (Artificial Intelligence), 
the short-circuit OR operator (|| in Java), 
and LISP (LIst Processing Language) that makes EMACS 
(Extensible MACro System) so addictive.

[toc] | [prev] | [next] | [standalone]


#9291

FromRoedy Green <see_website@mindprod.com.invalid>
Date2011-10-28 22:49 -0700
Message-ID<as4na7t1jv1odtpolfhp62jovj9h8mmalb@4ax.com>
In reply to#9281
On Fri, 28 Oct 2011 10:40:14 -0700 (PDT), bob <bob@coolgroups.com>
wrote, quoted or indirectly quoted someone who said :

>Can someone explain why I get this error?

What you need is a fundamental understanding of the various types of
nested classes. see http://mindprod.com/jgloss/nestedclasses.html
http://mindprod.com/jgloss/innerclasses.html
http://mindprod.com/jgloss/anonymousclasses.html
-- 
Roedy Green Canadian Mind Products
http://mindprod.com
It's difficult to be rigorous about whether a machine really knows,
thinks, etc., because we’re hard put to define these things. 
We understand human mental processes only slightly better than
a fish understands swimming. 
~ John McCarthy (born: 1927-09-04 died: 2011-10-23 at age: 84).
Inventor of the term AI (Artificial Intelligence), 
the short-circuit OR operator (|| in Java), 
and LISP (LIst Processing Language) that makes EMACS 
(Extensible MACro System) so addictive.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web