Forum » Programiranje » [Android] Aplikacija se zruši
[Android] Aplikacija se zruši
messi ::
Pozdravljeni,
Napaka se pojavi, ko sem spremeniti velikost črte in nato poskusil nekaj narisati, nato se mi je aplikacija sesula. Sicer mi je javil napaka ne tih dveh delih ampak meni ti dve napaki bolj malo povesta:
Napake:
Odsek kode v kateri se skriva napaka1:
Odsek kode v kateri se skriva napaka2:
Napaka se pojavi, ko sem spremeniti velikost črte in nato poskusil nekaj narisati, nato se mi je aplikacija sesula. Sicer mi je javil napaka ne tih dveh delih ampak meni ti dve napaki bolj malo povesta:
_panel.onDraw (c); in Oblika currentGraphicObject graphicobjects.get = (i);
Napake:
09-10 03:23:48.096: W/KeyCharacterMap(4667): No keyboard for id 0 09-10 03:23:48.106: W/KeyCharacterMap(4667): Using default keymap: /system/usr/keychars/qwerty.kcm.bin 09-10 03:25:12.476: W/dalvikvm(4667): threadid=15: thread exiting with uncaught exception (group=0x4001b188) 09-10 03:25:12.486: E/AndroidRuntime(4667): Uncaught handler: thread Thread-8 exiting due to uncaught exception 09-10 03:25:12.486: E/AndroidRuntime(4667): java.lang.IndexOutOfBoundsException: Invalid location 1, size is 1 09-10 03:25:12.486: E/AndroidRuntime(4667): at java.util.ArrayList.get(ArrayList.java:341) 09-10 03:25:12.486: E/AndroidRuntime(4667): at somitsolutions.training.android.androidpaint.AndroidPaint$Panel.onDraw(AndroidPaint.java:641) 09-10 03:25:12.486: E/AndroidRuntime(4667): at somitsolutions.training.android.androidpaint.AndroidPaint$TutorialThread.run(AndroidPaint.java:736) 09-10 03:25:12.496: I/dalvikvm(4667): threadid=7: reacting to signal 3 09-10 03:25:12.496: E/dalvikvm(4667): Unable to open stack trace file '/data/anr/traces.txt': Permission denied 09-10 03:25:14.046: I/Process(4667): Sending signal. PID: 4667 SIG: 9
Odsek kode v kateri se skriva napaka1:
public void onDraw(Canvas canvas) { for(int i = 0; i<number_of_graphicObjects; i++){ Shape currentGraphicObject = graphicobjects.get(i); mPaint.setColor(currentGraphicObject.getrgb()); mPaint.setStrokeWidth(currentGraphicObject.getStrokeWidth()); if(currentGraphicObject instanceof FreeHand){ for (Path path : ((FreeHand)currentGraphicObject).getGraphicsPath()) { canvas.drawPath(path,mPaint); bitmapCanvas.drawPath(path,mPaint); } } else if(currentGraphicObject instanceof Erase){ for (Path path : ((Erase)currentGraphicObject).getGraphicsPath()) { canvas.drawPath(path, mPaint); bitmapCanvas.drawPath(path, mPaint); } } else{ canvas.drawPath(currentGraphicObject.getPath(),mPaint); //Path pathTemp = currentGraphicObject.getPath(); //pathTemp.offset(640,0); bitmapCanvas.drawPath(currentGraphicObject.getPath(),mPaint); //bitmapCanvas.drawPath(path_of_shape_for_WallPaperBitmap, mPaint); } } }
Odsek kode v kateri se skriva napaka2:
class TutorialThread extends Thread { private SurfaceHolder _surfaceHolder; private Panel _panel; private boolean _run =false; public TutorialThread(SurfaceHolder surfaceHolder, Panel panel) { _surfaceHolder = surfaceHolder; _panel = panel; } public void setRunning(boolean run) { _run = run; } public SurfaceHolder getSurfaceHolder() { return _surfaceHolder; } @Override public void run() { Canvas c; while (_run) { c = null; try { c = _surfaceHolder.lockCanvas(null); synchronized (_surfaceHolder) { _panel.onDraw(c); //_panel.saveScreenshot(); } } finally { // do this in a finally so that if an exception is thrown // during the above, we don't leave the Surface in an // inconsistent state if (c != null) { _surfaceHolder.unlockCanvasAndPost(c); } } } //_panel.saveScreenshot(); } } public void colorChanged(int color) { // TODO Auto-generated method stub mPaint.setColor(color); barva=color; } }
messi ::
Vse ideje so so dobrodošle, kaj je narobe itd.. Lepo prosim za kako idejo za kak popravek..
usoban ::
09-10 03:25:12.486: E/AndroidRuntime(4667): at java.util.ArrayList.get(ArrayList.java:341) 09-10 03:25:12.486: E/AndroidRuntime(4667): at somitsolutions.training.android.androidpaint.AndroidPaint$Panel.onDraw(AndroidPaint.java:641) 09-10 03:25:12.486: E/AndroidRuntime(4667): at somitsolutions.training.android.androidpaint.AndroidPaint$TutorialThread.run(AndroidPaint.java:736)
zgleda da v for loopu gres enkrat prevec, poglej kolk je vrednost
number_of_graphicObjects
ker array je dolg 1, ti pa hoces dostopat do drugega elementa (idx 1)
g333kk ::
Zanimivo sva z messijom poskušala povečat števec pa še tam kjer napako javi in pa tukaj
Shape currentGraphicObject = graphicobjects.get(i);
povsod se crasha zadeva ..
Sem prestavil pa je enako.. čudno to..
Shape currentGraphicObject = graphicobjects.get(i);
povsod se crasha zadeva ..
for(int i = 1; i<number_of_graphicObjects; i++){
Sem prestavil pa je enako.. čudno to..
Zgodovina sprememb…
- spremenilo: g333kk ()
usoban ::
postavi breakpoint pa povej kolk je vrednost number_of_graphicObjects in kaksna je vsebina graphicObjects
g333kk ::
Takole number_of_graphicobject je le nek števec, ki za vsakega dodanega oblike,črte karkoli doda 1 številko, ..
Takole dobim graphobjects,number_of graphicobjects, je pa števelka ..
private ArrayList<Shape> graphicobjects; graphicobjects = new ArrayList<Shape>(); int number_of_graphicObjects; public ArrayList<Shape> getGraphicObjects(){ return graphicobjects; } @Override public boolean onTouchEvent(MotionEvent event) { // ShapeObject_to_be_created=5; synchronized (_thread.getSurfaceHolder()) { if(event.getAction() == MotionEvent.ACTION_DOWN){ if(shapemenuclicked == true && erasemenuclicked == false){ if(ShapeObject_to_be_created == ShapeLine){ currentGraphicObject = new Line(); ((Line) currentGraphicObject).getBegin().setX(event.getX()); ((Line) currentGraphicObject).getBegin().setY(event.getY()); } } else if(event.getAction() == MotionEvent.ACTION_MOVE){ if(shapemenuclicked == true && erasemenuclicked == false){ if(ShapeObject_to_be_created == ShapeFreehand){ ((FreeHand)currentGraphicObject).getPath().lineTo(event.getX(), event.getY()); } if(ShapeObject_to_be_created == ShapeLine){ } if(ShapeObject_to_be_created == ShapeRect){ } if(ShapeObject_to_be_created == ShapeCircle){ } if(ShapeObject_to_be_created == ShapeOval){ } } if(shapemenuclicked == false && erasemenuclicked == true){ if(ShapeObject_to_be_created == ShapeErase){ ((Erase)currentGraphicObject).getPath().lineTo(event.getX(), event.getY()); } } } else if(event.getAction() == MotionEvent.ACTION_UP){ if(shapemenuclicked == true && erasemenuclicked == false){ if(ShapeObject_to_be_created == ShapeLine){ ((Line) currentGraphicObject).getEnd().setX(event.getX()); ((Line) currentGraphicObject).getEnd().setY(event.getY()); Point temp_begin = ((Line)currentGraphicObject).getBegin(); Point temp_end = ((Line)currentGraphicObject).getEnd(); ((Line) currentGraphicObject).setBegin(temp_begin); ((Line)currentGraphicObject).getPath().moveTo(temp_begin.getX(), temp_begin.getY()); ((Line)currentGraphicObject).getPath().lineTo(temp_end.getX(), temp_end.getY()); } if(colormenuclicked == false && shapemenuclicked == true){ currentGraphicObject.setrgb(Color.WHITE); //risanje .. } if(colormenuclicked == true && shapemenuclicked == true){ currentGraphicObject.setrgb(barva); } if(erasemenuclicked == true && colormenuclicked == false){ currentGraphicObject.setrgb(Color.BLACK); //brisanje //mPaint.setStrokeWidth(6); } if(brushwidthmenuclicked == true){// || erasemenuclicked == true){ currentGraphicObject.setStrokeWidth(BrushWidth); } else <strong> graphicobjects.add(currentGraphicObject); //path_of_shape_for_WallPaperBitmap = currentGraphicObject.getPath(); //path_of_shape_for_WallPaperBitmap.offset(640, 0); number_of_graphicObjects++;</strong><strong> } } return true; }
Takole dobim graphobjects,number_of graphicobjects, je pa števelka ..
Zgodovina sprememb…
- spremenilo: g333kk ()
g333kk ::
usoban, sem se skoraj požrl ko sem ugotovil da je en else preveč in sta šla 2 dneva v pm, :D Ker sem preveč elsov napisal ;(( Sem tut kekec..
Hvala za pomoč, sedaj dela..
Hvala za pomoč, sedaj dela..
Zgodovina sprememb…
- spremenilo: g333kk ()
Vredno ogleda ...
Tema | Ogledi | Zadnje sporočilo | |
---|---|---|---|
Tema | Ogledi | Zadnje sporočilo | |
» | Programiranje problem androidOddelek: Programiranje | 1187 (952) | g333kk |
» | android črtaOddelek: Programiranje | 2427 (1698) | g333kk |
» | [android] vstavljanje slikeOddelek: Programiranje | 1261 (1158) | messi |
» | [android] crashOddelek: Programiranje | 1355 (1164) | messi |
» | ACTA - več podrobnostiOddelek: Novice / Industrijska lastnina | 5259 (3291) | 3furious |