Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,025

HOME > Mobile > Mobile Forum > Android เกิดปัญหาทำไมเกิดอาการ ERROR ในการใส่ Code นับเวลาถอยหลัง



 

Android เกิดปัญหาทำไมเกิดอาการ ERROR ในการใส่ Code นับเวลาถอยหลัง

 



Topic : 089677

Guest




สงสัยครับว่าทำไมผมใส่โค้ดนับเวลาถอยหลังแล้วเกิดการ ERROR ครับ
แล้วต้องแก้อย่างไรครับ

Code (Android-Java)
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.CountDownTimer;
import android.util.Log;
import android.view.Display;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;

public class DrawView extends View 
       {
        mTextField = (TextView)findViewById(R.id.showCount);

        public int[] ball = new int[] 
    		{ 
                   R.drawable.icebagg, R.drawable.icebagh, R.drawable.ball_green 
                };
        public int[][] ball_position = new int[][] 
    		{
                   { 400, 50 }, { 500, 50 }, { 600, 50 }
                };
    
         public Bitmap bm[] = new Bitmap[ball.length];
    
         public boolean[] goal = new boolean[ball.length];
    
         public int screen_width, screen_height;

         int goal_line = 200;
         int ball_id = -1;
         int score = 0;
    
    
    
    
          public DrawView(Context context, Display display)
                 {
                 super(context);
                 this.setBackgroundResource(R.drawable.fa9);
                 screen_width = display.getWidth();
                 screen_height = display.getHeight();
                           for(int i = 0 ; i < ball.length ; i++)
                                 {
                                  bm[i] = BitmapFactory.decodeResource(getResources(), ball[i]);
                                     goal[i] = false;
                                  }



                //นับถอยหลัง
                 new CountDownTimer(30000, 1000) 
                     {	
                             public void onTick(long millisUntilFinished) 
                             {
                                     mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
                              }
                              public void onFinish() 
                              {
                                     mTextField.setText("done!");
                               }
                      }.start();
                  }
                                 //นับถอยหลัง



    	protected void onDraw1(Canvas canvas) {
    	    super.onDraw(canvas);
    	    canvas.drawColor(Color.RED);

    	    Paint circle = new Paint();
    	    circle.setColor(Color.BLUE);
    	    if (isPop){
    	        canvas.drawCircle(100, 100, 40, circle);
    	    }
    	    invalidate();
        	}
   
    protected void onDraw(Canvas canvas) {

    	Paint p = new Paint();
       p.setColor(Color.rgb(0x3e, 0x9c, 0xbc));
    p.setAntiAlias(true);
    	
    	canvas.drawRect(0, screen_height - goal_line
    		, screen_width, screen_height, p);

       p.setTextSize(50);
       p.setColor(Color.WHITE);
       canvas.drawText("Drag to Here", (screen_width / 2) - 140
        		, screen_height - (( goal_line / 2) - 10), p);
       canvas.drawColor(0xFFFFFF);
        
      canvas.drawText("ข้อความ", 123, 100, p);
        
        p.setTextSize(70);
        p.setColor(Color.rgb(0x3e, 0x9c, 0xbc));
        canvas.drawText(String.valueOf(score), 50, 100, p);

        for(int i = 0 ; i < ball.length ; i++) {
        	if(!goal[i]) {
        		canvas.drawBitmap(bm[i], ball_position[i][0] - (bm[i].getWidth() / 2)
        				, ball_position[i][1] - (bm[i].getHeight() / 2), null);
        	}
        	
        }
        
    }
    
    
    public boolean onTouchEvent(MotionEvent event) {
        int eventaction = event.getAction(); 
        int X = (int)event.getX(); 
        int Y = (int)event.getY(); 

        switch (eventaction ) { 

        case MotionEvent.ACTION_DOWN: // touch down so check if the finger is on a ball
        	ball_id = -1;
        	for(int i = 0 ; i < ball.length ; i++) {
        		double radCircle  = Math.sqrt( Math.pow(Math.abs(X - ball_position[i][0]), 2) 
        				+ Math.pow(Math.abs(Y - ball_position[i][1]), 2) );
        		if(radCircle < bm[i].getWidth() / 2 && !goal[i]) {
        			ball_id = i;
        		}
        	}
        
        case MotionEvent.ACTION_MOVE:
        	
        	if(ball_id != -1 && !goal[ball_id]  ) {
	        	ball_position[ball_id][0] = X;
	        	ball_position[ball_id][1] = Y;
        	}
            break; 

        case MotionEvent.ACTION_UP: 
        	if(ball_id != -1 && !goal[ball_id]  ) {
	        	if(Y > screen_height - goal_line) {
	        		goal[ball_id] = true;
	        		score++;
	        	}
        	}
        	break; 
        	
        
        } 

        invalidate(); 
        
        return true;
    }
    
}




Tag : Mobile, Android







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-01-23 20:35:50 By : man View : 1173 Reply : 5
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Error อะไรครับ ? ลอง Capture LogCat มาให้ดูหน่อยครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-01-23 22:03:13 By : mr.win
 


 

No. 2

Guest


log
แบบนี้อะครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-01-24 12:40:34 By : man
 

 

No. 3



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

เหมือนกับว่าตำแหน่งของ Array มันเกิน Index ของ Array น่ะครับ อาจจะต้องใช้การ Debug ดูครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-01-24 13:29:01 By : mr.win
 


 

No. 4

Guest


ถามต่อครับ

Code (Android-Java)
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.CountDownTimer;
import android.util.Log;
import android.view.Display;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;
import android.content.Intent;

public class DrawView extends View 
       {
        mTextField = (TextView)findViewById(R.id.showCount);

        public int[] ball = new int[] 
    		{ 
                   R.drawable.icebagg, R.drawable.icebagh, R.drawable.ball_green 
                };
        public int[][] ball_position = new int[][] 
    		{
                   { 400, 50 }, { 500, 50 }, { 600, 50 }
                };
    
         public Bitmap bm[] = new Bitmap[ball.length];
    
         public boolean[] goal = new boolean[ball.length];
    
         public int screen_width, screen_height;

         int goal_line = 200;
         int ball_id = -1;
         int score = 0;
    
    
    
    
          public DrawView(Context context, Display display)
                 {
                 super(context);
                 this.setBackgroundResource(R.drawable.fa9);
                 screen_width = display.getWidth();
                 screen_height = display.getHeight();
                           for(int i = 0 ; i < ball.length ; i++)
                                 {
                                  bm[i] = BitmapFactory.decodeResource(getResources(), ball[i]);
                                     goal[i] = false;
                                  }
   
    	protected void onDraw(Canvas canvas) {
    	    super.onDraw(canvas);
    	    canvas.drawColor(Color.RED);

    	    Paint circle = new Paint();
    	    circle.setColor(Color.BLUE);
    	    if (isPop){
    	        canvas.drawCircle(100, 100, 40, circle);
    	    }
    	    invalidate();
        	}
   
    protected void onDraw(Canvas canvas) {

        for(int i = 0 ; i < ball.length ; i++) {
        	if(!goal[i]) {
        		canvas.drawBitmap(bm[i], ball_position[i][0] - (bm[i].getWidth() / 2)
        				, ball_position[i][1] - (bm[i].getHeight() / 2), null);
        	}
        	
        }
        
    }
    
    
    public boolean onTouchEvent(MotionEvent event) {
        int eventaction = event.getAction(); 
        int X = (int)event.getX(); 
        int Y = (int)event.getY(); 

        switch (eventaction ) { 

        case MotionEvent.ACTION_DOWN: // touch down so check if the finger is on a ball
        	ball_id = -1;
        	for(int i = 0 ; i < ball.length ; i++) {
        		double radCircle  = Math.sqrt( Math.pow(Math.abs(X - ball_position[i][0]), 2) 
        				+ Math.pow(Math.abs(Y - ball_position[i][1]), 2) );
        		if(radCircle < bm[i].getWidth() / 2 && !goal[i]) {
        			ball_id = i;
        		}
        	}
        
        case MotionEvent.ACTION_MOVE:
        	
        	if(ball_id != -1 && !goal[ball_id]  ) {
	        	ball_position[ball_id][0] = X;
	        	ball_position[ball_id][1] = Y;
        	}
            break; 

        case MotionEvent.ACTION_UP: 
        	if(ball_id != -1 && !goal[ball_id]  ) {
	        	if(Y > screen_height - goal_line) {
	        		goal[ball_id] = true;
	        		score++;

                                     Intent newActivity = new Intent(DrawView.this,Main1.class);  <<<<<มัน ERROR ครับ เป็นเพราะอะไร
                                     startActivity(newActivity);                                                       <<<<< มันมีเส้นสีแดงตลอดเลย
	        	}
        	}
        	break; 
        	
        
        } 

        invalidate(); 
        
        return true;
    }
    
}

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-01-24 18:46:40 By : man
 


 

No. 5



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Go to : Android กับ Intent ควบคุมการแสดงและซ่อน (Show/Hide) ของ Activity form ต่าง ๆ

ประกาศ Class ใน Manifest หรือยังครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-01-25 06:20:25 By : mr.win
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : Android เกิดปัญหาทำไมเกิดอาการ ERROR ในการใส่ Code นับเวลาถอยหลัง
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 03
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่