开发者

The application has stopped unexpectedly. Please try again

The application will run fine unless I add the following code.

public class TFView extends View{
  private Paint p;
  private ArrayList<Orb> O1;

  /** Called when the activity is first created. */
  public TFView (Context context){
    super(context);
    O1=new ArrayList<Orb>();
    p = new Paint();
    int Orby=0; 
    for(int j=0; j<3; j++){
      int Orbx= 0;

      for(int i=0; i<4; i++)
      {
        O1.add(new Orb(Orbx,Orby,true));
        Orbx+= 40;
      }
      Orby+= 40;
    }
  }


  @Override
  protected void onDraw(Canvas canvas) {

    for(Orb t:O1){
      canvas.drawOval(t.drawOrb(), p);

    }
    p.setColor(Color.BLUE);
    canvas.drawText(String.valueOf(main.getx()), 50, 50, p);
    canvas.drawText(String.valueOf(main.gety()), 50, 80, p);
    canvas.drawText(String.valueOf(O1.size()), 50, 110, p);

    try {  
      Thread.sleep(30);  
    } catch (InterruptedException e) { }

    invalidate(); 
  }
}

So, I believe that my problem has something to do with the android not accepting my Arraylist. I have run a very similar code to this on my computer, but something about Android doesn't seem to want to accept it. Here is my Orb class that is used in my Arraylist.

import android.graphics.RectF;

public class Orb {
  static int orbx;
  static int orby;
  public int size;
  static RectF button;

  boolean display;
  public Orb(){
    orbx=0;
    orby=0;
    display=false;
  }
  public Orb(int x, int y, boolean d){
    orbx=x;
    orby=y;
    display=true;

  }
  public RectF drawOrb(){
    button.set(orbx, orby,orbx+30, orby+30);
    return button;
  }
}

So, why doesn't the android accept my Arraylist drawings? Thank you for your help.

Edit: So, I fixed my problem with button being null with the following code public RectF drawOrb(){

button.set(orbx, orby,orbx+30, orby+30);
if(button!=null)
return button;
else
    return b;
}

Now I receive multiple null pointer exceptions that look like this

[2011-04-23 22:31:25 - ddms]null
java.lang.NullPointerException
    at com.android.ddmlib.JdwpPacket.writeAndConsume(JdwpPacket.java:213)
    at com.android.ddmlib.Client.sendAndConsume(Client.java:574)
 开发者_如何学C   at com.android.ddmlib.HandleHello.sendHELO(HandleHello.java:142)
    at com.android.ddmlib.HandleHello.sendHelloCommands(HandleHello.java:65)
    at com.android.ddmlib.Client.getJdwpPacket(Client.java:671)
    at com.android.ddmlib.MonitorThread.processClientActivity(MonitorThread.java:317)
    at com.android.ddmlib.MonitorThread.run(MonitorThread.java:263)

Thanks again


E/AndroidRuntime(  312): java.lang.NullPointerException
E/AndroidRuntime(  312):        at com.djrobotfreak.Think_Fast.Orb.drawOrb(Orb.java:26)

You have a NullPointerException on line 26 of Orb.java. Based on your listings, that would appear to be:

button.set(orbx, orby,orbx+30, orby+30);

If so, button is null.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜