Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

デバッグ戦略

3,929 views

Published on

Published in: Technology, Business
  • Be the first to comment

デバッグ戦略

  1. 1. (@v vakame) Android2011 8 25
  2. 2. • • • http://www.slideshare.net/vvakame/debugging-strategy2011 8 25
  3. 3. 2011 8 25
  4. 4. 2011 8 25
  5. 5. …2011 8 25
  6. 6. • • initA() initB() init() A, B public • 2 • ( ) • • …2011 8 25
  7. 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. 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. 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. 10. ADT 2011/08/25 rev122011 8 25
  11. 11. 2011 8 25
  12. 12. • • • • null2011 8 25
  13. 13. • LogCat2011 8 25
  14. 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. 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. 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. 17. “ ” • ( ω ´) • • • ← • …… …… • … orz ←2011 8 25
  18. 18. “ ” • • • • … •2011 8 25
  19. 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. 20. 2011 8 25
  21. 21. str2 null String#compareTo(String) null …2011 8 25
  22. 22. NPE(NullPointerException)2011 8 25
  23. 23. 2011 8 25
  24. 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. 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. 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. 27. Debug As ...2011 8 25
  28. 28. • F8 • F5 1 ( ) • F6 1 ( ) • F72011 8 25
  29. 29. 8 …2011 8 25
  30. 30. ( )2011 8 25
  31. 31. • • , , • Variables • •2011 8 25
  32. 32. … ¨ ¨ ¨ ¨ ¨ ¨ ¨ ¨...2011 8 25
  33. 33. →Inspect2011 8 25
  34. 34. 2011 8 25
  35. 35. • • • • • •2011 8 25
  36. 36. 2011 8 25
  37. 37. OpenGL2011 8 25
  38. 38. OpenGL http://t.co/bet40512011 8 25
  39. 39. 2011 8 25

×