Note that there are some explanatory texts on larger screens.

plurals
  1. POandroid - for loop drawing circles not working?
    primarykey
    data
    text
    <p>I am trying to draw multiple circles from an array and it is throwing a "force close" when I try to run the code. Any ideas here?</p> <pre><code>package com.adam.PlaySound; import android.app.Activity; import android.media.MediaPlayer; import android.net.Uri; import android.os.Bundle; import android.util.DisplayMetrics; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.widget.Button; import android.widget.LinearLayout; import android.widget.TextView; public class ButtonPress extends Activity { /** Called when the activity is first created. */ int numPlayers = 3; boolean toggle = true; LinearLayout parent; Button button; TextView text; TextView text2; DisplayMetrics dm = new DisplayMetrics(); MediaPlayer mediaPlayer[] = new MediaPlayer[numPlayers]; //this array is a placeholder for the loops in a cluster //essentially this array will be populated through a database //based on which cluster someone is within //and the region arrays will be populated by the same database String soundFiles[] = {"drums_1.mp3", "lead.mp3", "strings.mp3"}; public LoopRegion region[] = new LoopRegion[numPlayers]; float regionX[] = {20, 80, 150}; float regionY[] = {20, 200, 350}; int regionR[] = {50, 80, 100}; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //setContentView(R.id.view1); parent = (LinearLayout) findViewById(R.id.parent); button = (Button) findViewById(R.id.button1); text = (TextView) findViewById(R.id.text); text2 = (TextView) findViewById(R.id.text2); parent.setOnTouchListener(Motion); button.setOnClickListener(on_off); for (int i = 0; i &lt; numPlayers; i++){ String path = "http://soundclusters.adamlaskowitz.com/uploads/" + soundFiles[i]; mediaPlayer[i] = new MediaPlayer(); //mediaPlayer[i] = MediaPlayer.create(ButtonPress.this, R.raw.drums_2); mediaPlayer[i] = MediaPlayer.create(ButtonPress.this, Uri.parse(path)); mediaPlayer[i].setLooping(true); } for (int i = 0; i &lt; numPlayers; i++){ region[i] = new LoopRegion(this,regionX[i],regionY[i],regionR[i]); parent.addView(region[i]); } getWindowManager().getDefaultDisplay().getMetrics(dm); } </code></pre> <p>This is the LoopRegion class.</p> <pre><code>package com.adam.PlaySound; import android.content.Context; import android.graphics.Canvas; import android.graphics.Paint; import android.view.View; /*This class will create a circle region for *each loop within a cluster */ public class LoopRegion extends View { private float x; private float y; private int r; private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); public LoopRegion(Context context, float x, float y, int r) { super(context); mPaint.setColor(0xFFFF0000); this.x = x; this.y = y; this.r = r; } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawCircle(x, y, r, mPaint); } public void setCoordinate(float mx, float my){ this.x = mx; this.y = my; //this.r = 300; } } </code></pre> <p>And this is the XML</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/parent" &gt; &lt;TextView android:id="@+id/text" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Not Playing" /&gt; &lt;TextView android:id="@+id/text2" android:layout_height="wrap_content" android:text="Location" android:layout_width="wrap_content" /&gt; &lt;Button android:text="Sound On/Off" android:id="@+id/button1" android:layout_width="fill_parent" android:layout_height="wrap_content"&gt; &lt;/Button&gt; &lt;!-- &lt;View android:id="@+id/view1" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;/View&gt;--&gt; &lt;/LinearLayout&gt; </code></pre> <p>Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload