Prexx
Prexx

Reputation: 2979

Public variables call in Thread

I got some error when i try to call a public variable in my thread.

First my Code:

public class MyPhoneStateListener extends BroadcastReceiver {
public String number;

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub

        number = "123";

        t.start();

    }
    public Thread t = new Thread(new Runnable() {
        @Override
        public void run() {

            handler.sendMessage(handler.obtainMessage(SET_TEXT, number));

        }
    });
    public Hander handler = new Handler() {
         [blabla...]
    }
}

Error i get: /AndroidRuntime(3737): java.lang.StringIndexOutOfBoundsException: length=0; regionStart=0; regionLength=-1

i believe its a nullpointer exception or something.

what do i wrong?

Thanks, Prexx

Upvotes: 0

Views: 1660

Answers (1)

Argyle
Argyle

Reputation: 3394

It says java.lang.StringIndexOutOfBoundsExeption right there. Chances are you're trying to substring something with an invalid index or similar. At any rate, I doubt the threading is to blame. Unless you can give us more, information about exactly where the error is happening (indicate a line number or something) I doubt you'll get much more than that for help.

Upvotes: 1

Related Questions