# Android Studio trouble w/ declaration in Main Activity

**URL:** <https://discourse.processing.org/t/android-studio-trouble-w-declaration-in-main-activity/15336>\
**Category:** Processing for Android\
**Created:** [November 8, 2019, 3:07pm UTC](https://discourse.processing.org/t/android-studio-trouble-w-declaration-in-main-activity/15336 "2019-11-08T15:07:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lve0200](https://avatars.discourse-cdn.com/v4/letter/l/aeb1de/32.png) [@lve0200](https://discourse.processing.org/u/lve0200)\
**Post date:** [November 8, 2019, 3:07pm UTC](https://discourse.processing.org/t/android-studio-trouble-w-declaration-in-main-activity/15336/1 "2019-11-08T15:07:58Z")

</div>

Hi,  
I’m still troubled w/ declarations other than the pure ported/created Processing stuff.  
I have a running ported App, which I wanted to extend w/ a Background Network task, because networking in the main thread is prohibited.  
I created a background task, wich I believe is OK.

```auto
public class listen {

   public AsyncTask async_client;

    @SuppressLint("StaticFieldLeak")
    public void receive() {

        async_client = new AsyncTask<Void, Void, Void>() {

            protected Void doInBackground(Void... params) {
                boolean run = true;
                try {
            ...some code here
                    }
                } catch (IOException e) {
                    ... and here
                    run = false;

                }
                return null;
            }
        };
        if (Build.VERSION.SDK_INT >= 11) async_client.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        else async_client.execute();
    }

```

I tried to activate this background thread in my main activity like this

```auto
public class MainActivity extends AppCompatActivity {
  private PApplet sketch;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FrameLayout frame = new FrameLayout(this);
    frame.setId(CompatUtils.getUniqueViewId());
    setContentView(frame, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                                                     ViewGroup.LayoutParams.MATCH_PARENT));

    sketch = new MiniEFIS();

    PFragment fragment = new PFragment(sketch);
    fragment.setView(frame, this);
    
    listen client = new listen();
    client.receive();
  }

```

Is this the right place? There are no errors at compile time!  
I am receiving a runtime exception (and crash) wIth the error  
java.lang.ClassCastException: java.lang.Object[] cannot be cast to java.lang.Void[]  
and I don’t know, if the declaration is wrong, or in a wrong place, or what ??  
Any help welcome.  
Thank you in advance  
hk

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [November 10, 2019, 4:34pm UTC](https://discourse.processing.org/t/android-studio-trouble-w-declaration-in-main-activity/15336/2 "2019-11-10T16:34:11Z")

</div>

@lve0200 ====  
That is very simple; your Listen class is not good; with android varArgs (used in the asynkTask)are waiting for an array, (String or what you want for the first one) and you are only creating an object.If you want i can put code.

---

<div class="post-metadata">

**Author:** ![lve0200](https://avatars.discourse-cdn.com/v4/letter/l/aeb1de/32.png) [@lve0200](https://discourse.processing.org/u/lve0200)\
**Post date:** [November 10, 2019, 5:26pm UTC](https://discourse.processing.org/t/android-studio-trouble-w-declaration-in-main-activity/15336/3 "2019-11-10T17:26:42Z")

</div>

Hi,  
thanks anyway, but after taking another deep dive into the dev docu, I found it, myself. Its just about replicating other peoples code, thinking it would be easier…  
hk
