0

私は Android 開発に不慣れで、描画アプリに取り組んでいます。activity_main.xml のインターフェイスの変更を開始した昨日まで、アプリは機能していました。

誰かが問題がどこにあるかを理解するのを手伝ってくれたり、将来これらの問題を見つける方法を教えてくれたりしたら、大歓迎です!

キャットログ:

 0-25 02:51:33.967: E/AndroidRuntime(853): FATAL EXCEPTION: Thread-84
    10-25 02:51:33.967: E/AndroidRuntime(853): android.database.sqlite.SQLiteException:  unknown error (code 14): Could not open database
    10-25 02:51:33.967: E/AndroidRuntime(853):  at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:181)
    10-25 02:51:33.967: E/AndroidRuntime(853):  at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
    10-25 02:51:33.967: E/AndroidRuntime(853):  at android.content.ContentProviderProxy.query(ContentProviderNative.java:385)
    10-25 02:51:33.967: E/AndroidRuntime(853):  at android.content.ContentResolver.query(ContentResolver.java:414)
    10-25 02:51:33.967: E/AndroidRuntime(853):  at android.content.ContentResolver.query(ContentResolver.java:357)
    10-25 02:51:33.967: E/AndroidRuntime(853):  at com.android.inputmethod.latin.UserBinaryDictionary.loadDictionaryAsync(UserBinaryDictionary.java:189)
    10-25 02:51:33.967: E/AndroidRuntime(853):  at com.android.inputmethod.latin.ExpandableBinaryDictionary.generateBinaryDictionary(ExpandableBinaryDictionary.java:313)
    10-25 02:51:33.967: E/AndroidRuntime(853):  at com.android.inputmethod.latin.ExpandableBinaryDictionary.syncReloadDictionaryInternal(ExpandableBinaryDictionary.java:403)
    10-25 02:51:33.967: E/AndroidRuntime(853):  at com.android.inputmethod.latin.ExpandableBinaryDictionary.access$500(ExpandableBinaryDictionary.java:47)
    10-25 02:51:33.967: E/AndroidRuntime(853):  at com.android.inputmethod.latin.ExpandableBinaryDictionary$AsyncReloadDictionaryTask.run(ExpandableBinaryDictionary.java:435)

MainActivity.java:

package com.example.strip;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import java.util.UUID;
import android.provider.MediaStore;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.view.View.OnClickListener;
import android.widget.Toast;


public class MainActivity extends Activity implements OnClickListener{
    //custom drawing view
private DrawingView drawView;
//paint color
private ImageButton currPaint, drawBtn, eraseBtn, newBtn, saveBtn;
//brush size
private float smallBrush, mediumBrush, largeBrush;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //get drawing view
    drawView = (DrawingView)findViewById(R.id.drawing);

    //get palette and first color button
    LinearLayout paintLayout = (LinearLayout)findViewById(R.id.paint_colors);
    currPaint = (ImageButton)paintLayout.getChildAt(0);
    currPaint.setImageDrawable(getResources().getDrawable(R.drawable.paint_pressed));

    //get brush sizes
    smallBrush = getResources().getInteger(R.integer.small_size);
    mediumBrush = getResources().getInteger(R.integer.medium_size);
    largeBrush = getResources().getInteger(R.integer.large_size);

    //draw button
    drawBtn = (ImageButton)findViewById(R.id.draw_btn);
    drawBtn.setOnClickListener(this);

    //set initial brush size
    drawView.setBrushSize(mediumBrush);

    //set erase button, listen for click
    eraseBtn = (ImageButton)findViewById(R.id.erase_btn);
    eraseBtn.setOnClickListener(this);

    //set NEW button, listen for click
    newBtn = (ImageButton)findViewById(R.id.new_btn);
    newBtn.setOnClickListener(this);


    //set SAVEIMAGE button and listen for click
    saveBtn = (ImageButton)findViewById(R.id.save_btn);
    saveBtn.setOnClickListener(this);

}//end of onCreate


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

//user clicked paint
public void paintClicked(View view){
    //use chosen color, set erase to false, and use last brush size 
    if(view!=currPaint){
        drawView.setErase(false);
        drawView.setBrushSize(drawView.getLastBrushSize());
        ImageButton imgView = (ImageButton)view;
        String color = view.getTag().toString();
        drawView.setColor(color);
        //update ui
        imgView.setImageDrawable(getResources().getDrawable(R.drawable.paint_pressed));
        currPaint.setImageDrawable(getResources().getDrawable(R.drawable.paint));
        currPaint=(ImageButton)view;
    }
}

@Override
public void onClick(View view)
{
    if(view.getId()==R.id.draw_btn){
        //draw button clicked
        final Dialog brushDialog = new Dialog(this);
        brushDialog.setTitle("Brush Size:");
        brushDialog.setContentView(R.layout.brush_chooser);
        //listen for clicks on size buttons
        ImageButton smallBtn = (ImageButton)brushDialog.findViewById(R.id.small_brush);
        smallBtn.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View v) {
                drawView.setErase(false);
                drawView.setBrushSize(smallBrush);
                drawView.setLastBrushSize(smallBrush);
                brushDialog.dismiss();
            }
        });
        ImageButton mediumBtn = (ImageButton)brushDialog.findViewById(R.id.medium_brush);
        mediumBtn.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View v) {
                drawView.setErase(false);
                drawView.setBrushSize(mediumBrush);
                drawView.setLastBrushSize(mediumBrush);
                brushDialog.dismiss();
            }
        });
        ImageButton largeBtn = (ImageButton)brushDialog.findViewById(R.id.large_brush);
        largeBtn.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View v) {
                drawView.setErase(false);
                drawView.setBrushSize(largeBrush);
                drawView.setLastBrushSize(largeBrush);
                brushDialog.dismiss();
            }
        });
        brushDialog.show();
    }
    else if(view.getId()==R.id.erase_btn){
        //switch to erase, choose size
        final Dialog brushDialog = new Dialog(this);
        brushDialog.setTitle("Eraser Size:");
        brushDialog.setContentView(R.layout.brush_chooser);
        //listen for clicks on size buttons
        ImageButton smallBtn = (ImageButton)brushDialog.findViewById(R.id.small_brush);
        smallBtn.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View v) {
                drawView.setErase(true);
                drawView.setBrushSize(smallBrush);
                brushDialog.dismiss();
            }
        }); 
        ImageButton mediumBtn = (ImageButton)brushDialog.findViewById(R.id.medium_brush);
        mediumBtn.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View v) {
                drawView.setErase(true);
                drawView.setBrushSize(mediumBrush);
                brushDialog.dismiss();
            }
        });
        ImageButton largeBtn = (ImageButton)brushDialog.findViewById(R.id.large_brush);
        largeBtn.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View v) {
                drawView.setErase(true);
                drawView.setBrushSize(largeBrush);
                brushDialog.dismiss();
            }
        }); 
        brushDialog.show();
    }
    else if(view.getId()==R.id.new_btn){
        //NEW button
         //verify user wants new drawing
        AlertDialog.Builder newDialog = new AlertDialog.Builder(this);
        newDialog.setTitle("New drawing");
        newDialog.setMessage("Start new drawing? (You will lose your current drawing)");
        newDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener(){
            public void onClick(DialogInterface dialog, int which){
                drawView.startNew();
                dialog.dismiss();
            }
        });
        newDialog.setNegativeButton("Canvel", new DialogInterface.OnClickListener(){
            public void onClick(DialogInterface dialog, int which){
                dialog.cancel();
            }
        });
        newDialog.show();
    }
    else if(view.getId()==R.id.save_btn){
        //save drawing
        AlertDialog.Builder saveDialog = new AlertDialog.Builder(this);
        saveDialog.setTitle("Save drawing");
        saveDialog.setMessage("Save drawing to device Gallery?");
        saveDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener(){
            public void onClick(DialogInterface dialog, int which){
                //save drawing
                drawView.setDrawingCacheEnabled(true);
                String imgSaved = MediaStore.Images.Media.insertImage(
                        getContentResolver(), drawView.getDrawingCache(),
                        UUID.randomUUID().toString()+".png", "drawing");

                if(imgSaved!=null){
                    Toast savedToast = Toast.makeText(getApplicationContext(),
                            "Drawing saved to Gallery!", Toast.LENGTH_SHORT);
                    savedToast.show();
                }
                else{
                    Toast unsavedToast = Toast.makeText(getApplicationContext(),
                            "Oops! Image could not be saved.", Toast.LENGTH_SHORT);
                    unsavedToast.show();
                }
                drawView.destroyDrawingCache();
            }
            });
            saveDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener(){
                public void onClick(DialogInterface dialog, int which){
                    dialog.cancel();
                }
            });

        saveDialog.show();
    }

}
}

DrawingView.java:

 package com.example.strip;
    import android.view.View;
    import android.content.Context;
    import android.util.AttributeSet;
    import android.graphics.Bitmap;
    import android.graphics.Canvas;
    import android.graphics.Color;
    import android.graphics.Paint;
    import android.graphics.Path;
    import android.view.MotionEvent;
    import android.graphics.PorterDuff;
    import android.graphics.PorterDuffXfermode;
    import android.util.TypedValue;
    import android.util.Log;




    public class DrawingView extends View 
    {   
        //drawing path
        private Path drawPath;
        //drawing and canvas paint
        private Paint drawPaint, canvasPaint;
        //initial color
        private int paintColor = 0xFF660000;
        //canvas
        private Canvas drawCanvas;
        //canvas bitmap
        private Bitmap canvasBitmap;
        //erase flag
        private boolean erase=false;

        public void startNew(){
            drawCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
            invalidate();
        }

        public void setErase(boolean isErase){
            //set erase true or false
            erase=isErase;
            if(erase) drawPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
            else drawPaint.setXfermode(null);
        }

        public DrawingView(Context context, AttributeSet attrs)
        {
            super(context, attrs);
            setupDrawing();
        }
        private void setupDrawing(){
            //get drawing area setup for interaction

            drawPath = new Path();
            drawPaint = new Paint();
            drawPaint.setColor(paintColor);
            drawPaint.setAntiAlias(true);
            drawPaint.setStrokeWidth(brushSize);
            drawPaint.setStyle(Paint.Style.STROKE);
            drawPaint.setStrokeJoin(Paint.Join.ROUND);
            drawPaint.setStrokeCap(Paint.Cap.ROUND);
            canvasPaint = new Paint(Paint.DITHER_FLAG);
            brushSize = getResources().getInteger(R.integer.medium_size);
            lastBrushSize = brushSize;


            }

        public void setBrushSize(float newSize){
            //update size
            float pixelAmount = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
                    newSize, getResources().getDisplayMetrics());
            brushSize=pixelAmount;
            drawPaint.setStrokeWidth(brushSize);
        }

        public void setLastBrushSize(float lastSize){
            lastBrushSize=lastSize;
        }
        public float getLastBrushSize(){
            return lastBrushSize;
        }

        @Override
        protected void onSizeChanged(int w, int h, int oldw, int oldh){
            //view given size
            super.onSizeChanged(w, h, oldw, oldh);
            canvasBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
            drawCanvas = new Canvas(canvasBitmap);
        }

        @Override
        protected void onDraw(Canvas canvas){
            //draw view
            canvas.drawBitmap(canvasBitmap, 0, 0, canvasPaint);
            canvas.drawPath(drawPath, drawPaint);
        }

        @Override
        public boolean onTouchEvent(MotionEvent event){
            //detect user touch
            float touchX = event.getX();
            float touchY = event.getY();
            //respond to down, move and up events
            switch(event.getAction()){
            case MotionEvent.ACTION_DOWN:
                drawPath.moveTo(touchX, touchY);
                break;
            case MotionEvent.ACTION_MOVE:
                drawPath.lineTo(touchX, touchY);
                break;
            case MotionEvent.ACTION_UP:
                drawPath.lineTo(touchX, touchY);
                drawCanvas.drawPath(drawPath,  drawPaint);
                drawPath.reset();
                break;
            default:
                return false;
            }
            //redraw
            invalidate();
            return true;
        }

        public void setColor(String newColor){
            //set color
            invalidate();
            paintColor = Color.parseColor(newColor);
            drawPaint.setColor(paintColor);
            }

        private float brushSize, lastBrushSize;

        int squareDim = 1000000000;

        @Override
        public void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);


            int h = this.getMeasuredHeight();
            int w = this.getMeasuredWidth();
            int curSquareDim = Math.min(w,h);

            if(curSquareDim < squareDim)
            {
                squareDim = curSquareDim;
            }

            Log.d("MyApp", "h "+h+"w "+w+"squareDim "+squareDim);


            setMeasuredDimension(squareDim, squareDim);

        }

    }

Activity_Main.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".DemoActivity">
    <com.sothree.slidinguppanel.SlidingUpPanelLayout

                android:id="@+id/sliding_layout"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >

                <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical"
                    tools:context=".MainActivity" >

                    <!-- Top Buttons -->
                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="50dp"
                        android:layout_gravity="center"
                        android:orientation="horizontal" >
                        <TableLayout 
                            android:layout_width="match_parent" 
                            android:layout_height="match_parent" 
                            android:shrinkColumns="*"  android:stretchColumns="*" android:background="#ffffff"> 

                             <TableRow 
                                android:layout_height="50dp" 
                                android:layout_width="fill_parent" 
                                android:gravity="center_horizontal"> 
                                <TextView 
                                    android:layout_height="50dp"
                                    android:text="Last Panel"
                                    android:layout_weight="1" android:background="#FFD3D3D3"
                                    android:textColor="#FFF"
                                    android:padding="10dp" android:gravity="center"/>

                                <TextView 
                                    android:layout_height="50dp"
                                    android:text="Current Panel"
                                    android:layout_weight="1" android:background="#FFAA213A"
                                    android:textColor="#FFF"
                                    android:padding="10dp" android:gravity="center"/> 
                            </TableRow>  
                        </TableLayout>
                    </LinearLayout> 

                    <!-- Custom View -->
                    <com.example.strip.DrawingView
                        android:id="@+id/drawing"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="5dp"
                        android:layout_marginRight="5dp"
                        android:layout_marginTop="3dp"
                        android:background="#FFFFFFFF"
                        android:scaleType="centerInside" />

                </LinearLayout>
                <!-- Color Palette -->
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" 
                    android:orientation="horizontal">
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" 
                        android:orientation="horizontal">

                        <ImageButton
                            android:layout_width="45dp"
                            android:layout_height="45dp"
                            android:layout_marginTop="18dp"
                            android:layout_marginLeft="10dp"
                            android:gravity="center_vertical"
                            android:background = "@drawable/palettebutton"
                            android:contentDescription="@string/paint"
                            android:onClick="paintClicked"
                            android:src="@drawable/palettebutton"
                            android:tag="#FFE21A1A" />   

                        <TableLayout 
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:gravity="center_vertical"
                            android:layout_marginTop="3dp"
                            android:layout_marginRight="4dp"
                            android:layout_marginLeft="6dp">
                            <TableRow 
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content">
                                <ImageButton
                                    android:layout_width="@dimen/large_brush"
                                    android:layout_height="@dimen/large_brush"
                                    android:layout_margin="4dp"
                                    android:background = "@drawable/colorbutton1"
                                    android:contentDescription="@string/paint"
                                    android:onClick="paintClicked"
                                    android:src="@drawable/colorbutton1"
                                    android:tag="#FFE21A1A" />
                                <ImageButton
                                    android:layout_width="@dimen/large_brush"
                                    android:layout_height="@dimen/large_brush"
                                    android:layout_margin="4dp"
                                    android:background="@drawable/colorbutton2"
                                    android:contentDescription="@string/paint"
                                    android:onClick="paintClicked"
                                    android:src="@drawable/colorbutton2"
                                    android:tag="#FFF2D820" />
                                <ImageButton
                                    android:layout_width="@dimen/large_brush"
                                    android:layout_height="@dimen/large_brush"
                                    android:layout_margin="4dp"
                                    android:background="@drawable/colorbutton3"
                                    android:contentDescription="@string/paint"
                                    android:onClick="paintClicked"
                                    android:src="@drawable/colorbutton3"
                                    android:tag="#FF35EF22" />
                                <ImageButton
                                    android:layout_width="@dimen/large_brush"
                                    android:layout_height="@dimen/large_brush"
                                    android:layout_margin="4dp"
                                    android:background="@drawable/colorbutton4"
                                    android:contentDescription="@string/paint"
                                    android:onClick="paintClicked"
                                    android:src="@drawable/colorbutton4"
                                    android:tag="#FF26D3EA" />
                                <ImageButton
                                    android:layout_width="@dimen/large_brush"
                                    android:layout_height="@dimen/large_brush"
                                    android:layout_margin="4dp"
                                    android:background="@drawable/colorbutton5"
                                    android:contentDescription="@string/paint"
                                    android:onClick="paintClicked"
                                    android:src="@drawable/colorbutton5"
                                    android:tag="#FFF73E9B" />
                                <ImageButton
                                    android:layout_width="@dimen/large_brush"
                                    android:layout_height="@dimen/large_brush"
                                    android:layout_margin="4dp"
                                    android:background="@drawable/colorbutton6"
                                    android:contentDescription="@string/paint"
                                    android:onClick="paintClicked"
                                    android:src="@drawable/colorbutton6"
                                    android:tag="#FFFFFFFF" />
                            </TableRow>
                            <TableRow 
                               android:layout_width="wrap_content"
                               android:layout_height="wrap_content"
                               android:paddingBottom="6dp">
                               <ImageButton
                                    android:layout_width="@dimen/large_brush"
                                    android:layout_height="@dimen/large_brush"
                                    android:layout_margin="4dp"
                                    android:background="@drawable/colorbutton7"
                                    android:contentDescription="@string/paint"
                                    android:onClick="paintClicked"
                                    android:src="@drawable/colorbutton7"
                                    android:tag="#FF7A4426"/>
                               <ImageButton
                                    android:layout_width="@dimen/large_brush"
                                    android:layout_height="@dimen/large_brush"
                                    android:layout_margin="4dp"
                                    android:background="@drawable/colorbutton8"
                                    android:contentDescription="@string/paint"
                                    android:onClick="paintClicked"
                                    android:src="@drawable/colorbutton8"
                                    android:tag="#FFF74F1C"/>
                               <ImageButton
                                    android:layout_width="@dimen/large_brush"
                                    android:layout_height="@dimen/large_brush"
                                    android:layout_margin="4dp"
                                    android:background="@drawable/colorbutton9"
                                    android:contentDescription="@string/paint"
                                    android:onClick="paintClicked"
                                    android:src="@drawable/colorbutton9"
                                    android:tag="#FF217C14" />
                               <ImageButton
                                    android:layout_width="@dimen/large_brush"
                                    android:layout_height="@dimen/large_brush"
                                    android:layout_margin="4dp"
                                    android:background="@drawable/colorbutton10"
                                    android:contentDescription="@string/paint"
                                    android:onClick="paintClicked"
                                    android:src="@drawable/colorbutton10"
                                    android:tag="#FF312EBC"/>
                               <ImageButton
                                    android:layout_width="@dimen/large_brush"
                                    android:layout_height="@dimen/large_brush"
                                    android:layout_margin="4dp"
                                    android:background="@drawable/colorbutton11"
                                    android:contentDescription="@string/paint"
                                    android:onClick="paintClicked"
                                    android:src="@drawable/colorbutton11"
                                    android:tag="#FF5D1F93" />
                               <ImageButton
                                    android:layout_width="@dimen/large_brush"
                                    android:layout_height="@dimen/large_brush"
                                    android:layout_margin="4dp"
                                    android:background="@drawable/colorbutton12"
                                    android:contentDescription="@string/paint"
                                    android:onClick="paintClicked"
                                    android:src="@drawable/colorbutton12"
                                    android:tag="#FF000000"/>               
                            </TableRow>
                        </TableLayout>
                        <ImageButton
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_marginLeft="8dp"
                            android:gravity="center_horizontal"
                            android:background = "@drawable/sendbutton"
                            android:contentDescription="@string/paint"
                            android:onClick="paintClicked"
                            android:src="@drawable/sendbutton"
                            android:tag="#FFE21A1A" />  
                    </LinearLayout>
                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="50dp"
                        android:layout_gravity="center"
                        android:orientation="horizontal" >

                        <ImageButton
                            android:id="@+id/new_btn"
                            android:layout_width="wrap_content"
                            android:layout_height="fill_parent"
                            android:contentDescription="@string/start_new"
                            android:src="@drawable/new_pic" />
                        <ImageButton
                            android:id="@+id/draw_btn"
                            android:layout_width="wrap_content"
                            android:layout_height="fill_parent"
                            android:contentDescription="@string/brush"
                            android:src="@drawable/brush" />
                        <ImageButton
                            android:id="@+id/erase_btn"
                            android:layout_width="wrap_content"
                            android:layout_height="fill_parent"
                            android:contentDescription="@string/erase"
                            android:src="@drawable/eraser" />
                        <ImageButton
                            android:id="@+id/save_btn"
                            android:layout_width="wrap_content"
                            android:layout_height="fill_parent"
                            android:contentDescription="@string/save"
                            android:src="@drawable/save" /> 
                    </LinearLayout>
                </LinearLayout>
        </com.sothree.slidinguppanel.SlidingUpPanelLayout>
    </RelativeLayout>

他に提供できることがあれば、お知らせください。お手伝いありがとう!

4

1 に答える 1

0

10-25 02:51:33.967: E/AndroidRuntime(853): android.database.sqlite.SQLiteException: 不明なエラー (コード 14): データベースを開けませんでした

これは、プログラムがデータベースにアクセスできないというエラーを示しています。DB 接続を確認し、デバッグを試みます。問題はそこにあります。

于 2013-10-25T07:17:26.153 に答える