デバッグ戦略

  • 2,894 views
Uploaded on

 

More in: Technology , Business
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
2,894
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
28
Comments
0
Likes
3

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. (@v vakame) Android2011 8 25
  • 2. • • • http://www.slideshare.net/vvakame/debugging-strategy2011 8 25
  • 3. 2011 8 25
  • 4. 2011 8 25
  • 5. …2011 8 25
  • 6. • • initA() initB() init() A, B public • 2 • ( ) • • …2011 8 25
  • 7. /** * bitmap . * * @param bitmapArrays */ static void dot1PixelA(Bitmap[][] bitmapArrays) { for (int i = 0; i < bitmapArrays.length; i++) { for for (int j = 0; j < bitmapArrays[i].length; i++) { bitmapArrays[j][i].setPixel(0, 0, Color.RED); } } } /** * bitmap . * * @param bitmapArrays */ static void dot1PixelB(Bitmap[][] bitmapArrays) { for (Bitmap[] bitmapArray : bitmapArrays) { for (Bitmap bitmap : bitmapArray) { for-each bitmap.setPixel(0, 0, Color.RED); } } }2011 8 25
  • 8. /** * bitmap . * * @param bitmapArrays */ static void dot1PixelA(Bitmap[][] bitmapArrays) { for (int i = 0; i < bitmapArrays.length; i++) { for for (int j = 0; j < bitmapArrays[i].length; i++) { bitmapArrays[j][i].setPixel(0, 0, Color.RED); } } } /** * bitmap . * * @param bitmapArrays */ static void dot1PixelB(Bitmap[][] bitmapArrays) { for (Bitmap[] bitmapArray : bitmapArrays) { for (Bitmap bitmap : bitmapArray) { for-each bitmap.setPixel(0, 0, Color.RED); } } }2011 8 25
  • 9. Bitmap[][] bitmapArrays = new Bitmap[10][10]; for (int i = 0; i < bitmapArrays.length; i++) { for (int j = 0; j < bitmapArrays[i].length; j++) { bitmapArrays[i][j] = Bitmap.createBitmap(3, 3, Config.ARGB_8888); } } …2011 8 25
  • 10. ADT 2011/08/25 rev122011 8 25
  • 11. 2011 8 25
  • 12. • • • • null2011 8 25
  • 13. • LogCat2011 8 25
  • 14. • L07 @Override L08 public void onCreate(Bundle savedInstanceState) { L09 super.onCreate(savedInstanceState); L10 setContentView(R.layout.main); L11 L12 try { L13 throw new NullPointerException(); L14 } catch (Exception e1) { L15 try { L16 throw new IllegalArgumentException(e1); L17 } catch (Exception e2) { L18 try { L19 throw new IllegalStateException(e2); L20 } catch (Exception e3) { L21 throw new RuntimeException(e3); L22 } L23 } L24 } L25 } Caused2011 8 25
  • 15. • L08 @Override L09 public void onCreate(Bundle savedInstanceState) { L10 super.onCreate(savedInstanceState); L11 setContentView(R.layout.main); L12 requestWindowFeature(Window.FEATURE_NO_TITLE); L13 } L11 L122011 8 25
  • 16. L22 … L09 @Override L10 public void onCreate(Bundle savedInstanceState) { L11 super.onCreate(savedInstanceState); L12 L13 LinearLayout layout1 = new LinearLayout(this); L14 LinearLayout layout2 = new LinearLayout(this); L15 LinearLayout layout3 = new LinearLayout(this); L16 Button button = new Button(this); L17 L18 layout1.addView(layout2); L19 L20 layout2.addView(layout1); layout3.addView(button); layout1 → layout2 → layout1 L21 L22 setContentView(layout1); layout1 → layout2 → layout3 … L23 }2011 8 25
  • 17. “ ” • ( ω ´) • • • ← • …… …… • … orz ←2011 8 25
  • 18. “ ” • • • • … •2011 8 25
  • 19. void sort() { List<String> list = new ArrayList<String>(); list.add("cupcake"); list.add(null); list.add("donuts"); list.add(null); list.add("froyo"); Collections.sort(list, new Comparator<String>() { @Override public int compare(String str1, String str2) { if (str1 == null) { return -1; } return str1.compareTo(str2); } }); Log.d("Debug", list.toString()); } NullPointerException … LogCat …2011 8 25
  • 20. 2011 8 25
  • 21. str2 null String#compareTo(String) null …2011 8 25
  • 22. NPE(NullPointerException)2011 8 25
  • 23. 2011 8 25
  • 24. … public class Util { /** * 2 1 . * @param list1 1 * @param list2 2 * @return 1 */ public static List<Object> merge(List<Object> list1, List<Object> list2) { list1.addAll(list2); return list1; } /** * 1 . * @param lists * @return 1 */ public static List<Object> merge(List<?>... lists) { List<Object> result = new ArrayList<Object>(); for (List<?> list : lists) { result.addAll(list); } return result; } }2011 8 25
  • 25. public void test() { List<Object> list1 = new ArrayList<Object>(); list1.add("a"); list1.add("b"); List<Object> list2 = new ArrayList<Object>(); list2.add(1); list2.add(2); List<Object> list3 = new ArrayList<Object>(); list3.add(1.25); list3.add(2.5); List<Object> merged1 = Util.merge(list1, list2); List<Object> merged2 = Util.merge(list1, list2, list3); assertEquals(merged1.size(), 4); assertEquals(merged1.get(0), "a"); assertEquals(merged1.get(1), "b"); assertEquals(merged1.get(2), 1); assertEquals(merged1.get(3), 2); assertEquals(merged2.size(), 6); assertEquals(merged2.get(0), "a"); assertEquals(merged2.get(1), "b"); assertEquals(merged2.get(2), 1); assertEquals(merged2.get(3), 2); assertEquals(merged2.get(4), 1.25); assertEquals(merged2.get(5), 2.5); }2011 8 25
  • 26. public void test() { List<Object> list1 = new ArrayList<Object>(); list1.add("a"); list1.add("b"); List<Object> list2 = new ArrayList<Object>(); list2.add(1); list2.add(2); List<Object> list3 = new ArrayList<Object>(); list3.add(1.25); list3.add(2.5); List<Object> merged1 = Util.merge(list1, list2); List<Object> merged2 = Util.merge(list1, list2, list3); assertEquals(merged1.size(), 4); assertEquals(merged1.get(0), "a"); assertEquals(merged1.get(1), "b"); assertEquals(merged1.get(2), 1); assertEquals(merged1.get(3), 2); size 8 assertEquals(merged2.size(), 6); assertEquals(merged2.get(0), "a"); assertEquals(merged2.get(1), "b"); assertEquals(merged2.get(2), 1); assertEquals(merged2.get(3), 2); assertEquals(merged2.get(4), 1.25); assertEquals(merged2.get(5), 2.5); }2011 8 25
  • 27. Debug As ...2011 8 25
  • 28. • F8 • F5 1 ( ) • F6 1 ( ) • F72011 8 25
  • 29. 8 …2011 8 25
  • 30. ( )2011 8 25
  • 31. • • , , • Variables • •2011 8 25
  • 32. … ¨ ¨ ¨ ¨ ¨ ¨ ¨ ¨...2011 8 25
  • 33. →Inspect2011 8 25
  • 34. 2011 8 25
  • 35. • • • • • •2011 8 25
  • 36. 2011 8 25
  • 37. OpenGL2011 8 25
  • 38. OpenGL http://t.co/bet40512011 8 25
  • 39. 2011 8 25