Błąd związany z zapisywaniem zdjęcia do folderu

0

Witam, otóż muszę napisać projekt i zatrzymałem się na etapie zapisywania zdjęcia do folderu. Mianowicie wyskakuje mi błąd, a nawet wiem który wiersz jest jego przyczyną ale nie mam pojęcia dlaczego nie działa. Zacząłem udoskonalać projekt, po dodaniu nowych funkcji do aplikacji, przestała działać i zatrzymuje się na buttonie "Zrób zdjęcie". Teraz wróciłem do stanu poprzedniego w którym wszystko powinno działać, ale jednak nie działa. Proszę was bardzo o pomoc.
Kod:

package com.example.start;

import java.io.File;
import java.io.IOException;
import java.util.Calendar;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.v7.app.ActionBarActivity;

import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

 public class MainActivity extends ActionBarActivity {
    ImageView iv, zdjecie; 
    EditText editText;

    TextView tv2;

    ///// *********** POCZĄTEK FUNKCJI PRZYCISKU ********** \\\\\
    ///// ***********   WYŚWIETLANIA ZDJĘCIA     ********** \\\\\
    public void obslugaButtona(View v){
    String nazwaObrazu=editText.getText().toString();

    wyborZdjecia(nazwaObrazu); // wybiera obraz do wyświetlenia

    }
    //// ******* KONIEC FUNKCJI PRZYCISKU ******* \\\\
    //// *******   WYŚWIETLANIA ZDJĘCIA   ******* \\\\

    public void oblugaRobieniaZdjecia(View w)
    {
        Intent zdjecieIntencja=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        File filezdjecie=null;
        Calendar c= Calendar.getInstance();
        String nazwaPliku="zdj_"+c.get(Calendar.DAY_OF_YEAR)+c.get(Calendar.HOUR_OF_DAY)+c.get(Calendar.MINUTE);
        String rozszerzenie=".jpg";
        String pelnaSciezka="";
        File katalog= Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
        try{
            filezdjecie=File.createTempFile(nazwaPliku, rozszerzenie, katalog);
        }catch(IOException e)
        {
            e.printStackTrace();
        }
        zdjecieIntencja.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(filezdjecie));
        startActivityForResult(zdjecieIntencja, 1);

        pelnaSciezka=katalog.getAbsolutePath()+"/"+nazwaPliku+rozszerzenie;
        Log.d("LOG: ",pelnaSciezka);
        tv2.setText(pelnaSciezka);

    }

///// *********** POCZĄTEK FUNKCJI WYBORU OBRAZU ********** \\\\\ 
    public void wyborZdjecia(String nazwa)
    {
    /*  String nazwaO=nazwa;

        if(nazwaO.equals("a1"))
        {
            iv.setImageResource(R.drawable.a1);
            Toast.makeText(getApplicationContext(),"Obraz a1",Toast.LENGTH_LONG).show();
        }
        if(nazwaO.equals("d1"))
        {
            iv.setImageResource(R.drawable.d1);
            Toast.makeText(getApplicationContext(),"Obraz d1",Toast.LENGTH_LONG).show();
        }
        if(nazwaO.equals("z1"))
        {
            iv.setImageResource(R.drawable.z1);
            Toast.makeText(getApplicationContext(),"Obraz z1",Toast.LENGTH_LONG).show();
        }
        else
            Toast.makeText(getApplicationContext(),"nie ma obrazu o takiej nazwie",Toast.LENGTH_LONG).show();*/
    }
///// *********** KONIEC FUNKCJI WYBORU OBRAZU ********** \\\\\

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

        iv = (ImageView) findViewById(R.id.imageView1);
        editText=(EditText)findViewById(R.id.editText1);
        tv2=(TextView) findViewById(R.id.textView2);

    }

    protected void onActivityResult(int requestCode,int resultCode, Intent data)
    {
        /*if(requestCode==1 && resultCode==RESULT_OK){
            Bundle extras= data.getExtras();
            Bitmap bitmap=(Bitmap) extras.get("data");
            iv.setImageBitmap(bitmap);
            }*/

    }

    @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;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

}
<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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.start.MainActivity" >

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/text1"
        android:layout_marginTop="30dp"
        android:ems="10"
        android:gravity="center"
        android:hint="Wpisz nazwę zdjęcia do wyświetlenia"
        android:textSize="12sp" >

        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/editText1"
        android:layout_alignParentTop="true"
        android:gravity="center"
        android:text=" Witamy w programie rozpoznawania liter"
        android:textSize="20dp"
        android:textStyle="bold" />

    <Button
        android:id="@+id/bPobierzZdjecie"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/editText1"
        android:layout_centerHorizontal="true"
        android:onClick="obslugaButtona"
        android:text="Pokaż zdjęcie" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignRight="@+id/editText1"
        android:text="Test" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/bPobierzZdjecie"
        android:layout_marginTop="18dp"
        android:layout_toRightOf="@+id/bZrobZdjecie"
        android:src="@drawable/ic_launcher" />

    <Button
        android:id="@+id/bZrobZdjecie"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/textView1"
        android:layout_alignParentLeft="true"
        android:onClick="oblugaRobieniaZdjecia"
        android:text="Zrób Zdjęcie" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView1"
        android:layout_alignBottom="@+id/textView1"
        android:layout_alignLeft="@+id/bZrobZdjecie"
        android:text="Ścieżka zdjęcia" />

</RelativeLayout>

Oraz raport z LogCat:

11-06 00:25:19.350: E/Trace(3352): error opening trace file: No such file or directory (2)
11-06 00:25:19.500: W/dalvikvm(3352): VFY: unable to resolve virtual method 11428: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
11-06 00:25:19.500: W/dalvikvm(3352): VFY: unable to resolve virtual method 11434: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
11-06 00:25:19.510: W/dalvikvm(3352): VFY: unable to resolve virtual method 9000: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
11-06 00:25:19.550: W/dalvikvm(3352): VFY: unable to resolve virtual method 11431: Landroid/view/ViewGroup;.onRtlPropertiesChanged (I)V
11-06 00:25:19.560: W/dalvikvm(3352): VFY: unable to resolve virtual method 371: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
11-06 00:25:19.560: W/dalvikvm(3352): VFY: unable to resolve virtual method 393: Landroid/content/res/TypedArray;.getType (I)I
11-06 00:25:19.670: D/dalvikvm(3352): GC_CONCURRENT freed 207K, 6% free 8315K/8775K, paused 12ms+2ms, total 28ms
11-06 00:25:19.700: I/Adreno200-EGL(3352): <qeglDrvAPI_eglInitialize:299>: EGL 1.4 QUALCOMM build: Nondeterministic AU_msm8625_REFS/TAGS/JB_REL_RB5_QRD_D20130228_CL3285357_release_AU (CL3285357)
11-06 00:25:19.700: I/Adreno200-EGL(3352): Build Date: 03/01/13 Fri
11-06 00:25:19.700: I/Adreno200-EGL(3352): Local Branch: 
11-06 00:25:19.700: I/Adreno200-EGL(3352): Remote Branch: m/refs/tags/jb_rel_rb5_qrd_D20130228
11-06 00:25:19.700: I/Adreno200-EGL(3352): Local Patches: NONE
11-06 00:25:19.700: I/Adreno200-EGL(3352): Reconstruct Branch: NOTHING
11-06 00:26:49.050: W/IInputConnectionWrapper(3352): showStatusIcon on inactive InputConnection
11-06 00:27:22.990: W/System.err(3352): java.io.IOException: open failed: EACCES (Permission denied)
11-06 00:27:22.990: W/System.err(3352):     at java.io.File.createNewFile(File.java:940)
11-06 00:27:22.990: W/System.err(3352):     at java.io.File.createTempFile(File.java:1005)
11-06 00:27:22.990: W/System.err(3352):     at com.example.start.MainActivity.oblugaRobieniaZdjecia(MainActivity.java:57)
11-06 00:27:22.990: W/System.err(3352):     at java.lang.reflect.Method.invokeNative(Native Method)
11-06 00:27:23.000: W/System.err(3352):     at java.lang.reflect.Method.invoke(Method.java:511)
11-06 00:27:23.000: W/System.err(3352):     at android.view.View$1.onClick(View.java:3586)
11-06 00:27:23.000: W/System.err(3352):     at android.view.View.performClick(View.java:4084)
11-06 00:27:23.000: W/System.err(3352):     at android.view.View$PerformClick.run(View.java:16987)
11-06 00:27:23.010: W/System.err(3352):     at android.os.Handler.handleCallback(Handler.java:615)
11-06 00:27:23.010: W/System.err(3352):     at android.os.Handler.dispatchMessage(Handler.java:92)
11-06 00:27:23.010: W/System.err(3352):     at android.os.Looper.loop(Looper.java:137)
11-06 00:27:23.010: W/System.err(3352):     at android.app.ActivityThread.main(ActivityThread.java:4794)
11-06 00:27:23.010: W/System.err(3352):     at java.lang.reflect.Method.invokeNative(Native Method)
11-06 00:27:23.010: W/System.err(3352):     at java.lang.reflect.Method.invoke(Method.java:511)
11-06 00:27:23.010: W/System.err(3352):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
11-06 00:27:23.010: W/System.err(3352):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
11-06 00:27:23.010: W/System.err(3352):     at dalvik.system.NativeStart.main(Native Method)
11-06 00:27:23.010: W/System.err(3352): Caused by: libcore.io.ErrnoException: open failed: EACCES (Permission denied)
11-06 00:27:23.010: W/System.err(3352):     at libcore.io.Posix.open(Native Method)
11-06 00:27:23.020: W/System.err(3352):     at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
11-06 00:27:23.020: W/System.err(3352):     at java.io.File.createNewFile(File.java:933)
11-06 00:27:23.020: W/System.err(3352):     ... 16 more
11-06 00:27:23.020: W/dalvikvm(3352): threadid=1: thread exiting with uncaught exception (group=0x40e1f438)
11-06 00:27:23.030: E/AndroidRuntime(3352): FATAL EXCEPTION: main
11-06 00:27:23.030: E/AndroidRuntime(3352): java.lang.IllegalStateException: Could not execute method of the activity
11-06 00:27:23.030: E/AndroidRuntime(3352):     at android.view.View$1.onClick(View.java:3591)
11-06 00:27:23.030: E/AndroidRuntime(3352):     at android.view.View.performClick(View.java:4084)
11-06 00:27:23.030: E/AndroidRuntime(3352):     at android.view.View$PerformClick.run(View.java:16987)
11-06 00:27:23.030: E/AndroidRuntime(3352):     at android.os.Handler.handleCallback(Handler.java:615)
11-06 00:27:23.030: E/AndroidRuntime(3352):     at android.os.Handler.dispatchMessage(Handler.java:92)
11-06 00:27:23.030: E/AndroidRuntime(3352):     at android.os.Looper.loop(Looper.java:137)
11-06 00:27:23.030: E/AndroidRuntime(3352):     at android.app.ActivityThread.main(ActivityThread.java:4794)
11-06 00:27:23.030: E/AndroidRuntime(3352):     at java.lang.reflect.Method.invokeNative(Native Method)
11-06 00:27:23.030: E/AndroidRuntime(3352):     at java.lang.reflect.Method.invoke(Method.java:511)
11-06 00:27:23.030: E/AndroidRuntime(3352):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
11-06 00:27:23.030: E/AndroidRuntime(3352):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
11-06 00:27:23.030: E/AndroidRuntime(3352):     at dalvik.system.NativeStart.main(Native Method)
11-06 00:27:23.030: E/AndroidRuntime(3352): Caused by: java.lang.reflect.InvocationTargetException
11-06 00:27:23.030: E/AndroidRuntime(3352):     at java.lang.reflect.Method.invokeNative(Native Method)
11-06 00:27:23.030: E/AndroidRuntime(3352):     at java.lang.reflect.Method.invoke(Method.java:511)
11-06 00:27:23.030: E/AndroidRuntime(3352):     at android.view.View$1.onClick(View.java:3586)
11-06 00:27:23.030: E/AndroidRuntime(3352):     ... 11 more
11-06 00:27:23.030: E/AndroidRuntime(3352): Caused by: java.lang.NullPointerException: file
11-06 00:27:23.030: E/AndroidRuntime(3352):     at android.net.Uri.fromFile(Uri.java:441)
11-06 00:27:23.030: E/AndroidRuntime(3352):     at com.example.start.MainActivity.oblugaRobieniaZdjecia(MainActivity.java:62)
11-06 00:27:23.030: E/AndroidRuntime(3352):     ... 14 more
11-06 00:27:41.750: E/Trace(3539): error opening trace file: No such file or directory (2)
11-06 00:27:41.840: W/dalvikvm(3539): VFY: unable to resolve virtual method 11428: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
11-06 00:27:41.840: W/dalvikvm(3539): VFY: unable to resolve virtual method 11434: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
11-06 00:27:41.840: W/dalvikvm(3539): VFY: unable to resolve virtual method 9000: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
11-06 00:27:41.890: W/dalvikvm(3539): VFY: unable to resolve virtual method 11431: Landroid/view/ViewGroup;.onRtlPropertiesChanged (I)V
11-06 00:27:41.890: W/dalvikvm(3539): VFY: unable to resolve virtual method 371: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
11-06 00:27:41.890: W/dalvikvm(3539): VFY: unable to resolve virtual method 393: Landroid/content/res/TypedArray;.getType (I)I
11-06 00:27:42.000: D/dalvikvm(3539): GC_CONCURRENT freed 209K, 6% free 8309K/8775K, paused 2ms+12ms, total 33ms
11-06 00:27:42.040: I/Adreno200-EGL(3539): <qeglDrvAPI_eglInitialize:299>: EGL 1.4 QUALCOMM build: Nondeterministic AU_msm8625_REFS/TAGS/JB_REL_RB5_QRD_D20130228_CL3285357_release_AU (CL3285357)
11-06 00:27:42.040: I/Adreno200-EGL(3539): Build Date: 03/01/13 Fri
11-06 00:27:42.040: I/Adreno200-EGL(3539): Local Branch: 
11-06 00:27:42.040: I/Adreno200-EGL(3539): Remote Branch: m/refs/tags/jb_rel_rb5_qrd_D20130228
11-06 00:27:42.040: I/Adreno200-EGL(3539): Local Patches: NONE
11-06 00:27:42.040: I/Adreno200-EGL(3539): Reconstruct Branch: NOTHING
11-06 00:27:43.480: W/System.err(3539): java.io.IOException: open failed: EACCES (Permission denied)
11-06 00:27:43.490: W/System.err(3539):     at java.io.File.createNewFile(File.java:940)
11-06 00:27:43.490: W/System.err(3539):     at java.io.File.createTempFile(File.java:1005)
11-06 00:27:43.490: W/System.err(3539):     at com.example.start.MainActivity.oblugaRobieniaZdjecia(MainActivity.java:57)
11-06 00:27:43.490: W/System.err(3539):     at java.lang.reflect.Method.invokeNative(Native Method)
11-06 00:27:43.490: W/System.err(3539):     at java.lang.reflect.Method.invoke(Method.java:511)
11-06 00:27:43.490: W/System.err(3539):     at android.view.View$1.onClick(View.java:3586)
11-06 00:27:43.490: W/System.err(3539):     at android.view.View.performClick(View.java:4084)
11-06 00:27:43.490: W/System.err(3539):     at android.view.View$PerformClick.run(View.java:16987)
11-06 00:27:43.490: W/System.err(3539):     at android.os.Handler.handleCallback(Handler.java:615)
11-06 00:27:43.490: W/System.err(3539):     at android.os.Handler.dispatchMessage(Handler.java:92)
11-06 00:27:43.490: W/System.err(3539):     at android.os.Looper.loop(Looper.java:137)
11-06 00:27:43.490: W/System.err(3539):     at android.app.ActivityThread.main(ActivityThread.java:4794)
11-06 00:27:43.500: W/System.err(3539):     at java.lang.reflect.Method.invokeNative(Native Method)
11-06 00:27:43.500: W/System.err(3539):     at java.lang.reflect.Method.invoke(Method.java:511)
11-06 00:27:43.500: W/System.err(3539):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
11-06 00:27:43.500: W/System.err(3539):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
11-06 00:27:43.500: W/System.err(3539):     at dalvik.system.NativeStart.main(Native Method)
11-06 00:27:43.500: W/System.err(3539): Caused by: libcore.io.ErrnoException: open failed: EACCES (Permission denied)
11-06 00:27:43.510: W/System.err(3539):     at libcore.io.Posix.open(Native Method)
11-06 00:27:43.510: W/System.err(3539):     at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
11-06 00:27:43.510: W/System.err(3539):     at java.io.File.createNewFile(File.java:933)
11-06 00:27:43.510: W/System.err(3539):     ... 16 more
11-06 00:27:43.510: W/dalvikvm(3539): threadid=1: thread exiting with uncaught exception (group=0x40e1f438)
11-06 00:27:43.520: E/AndroidRuntime(3539): FATAL EXCEPTION: main
11-06 00:27:43.520: E/AndroidRuntime(3539): java.lang.IllegalStateException: Could not execute method of the activity
11-06 00:27:43.520: E/AndroidRuntime(3539):     at android.view.View$1.onClick(View.java:3591)
11-06 00:27:43.520: E/AndroidRuntime(3539):     at android.view.View.performClick(View.java:4084)
11-06 00:27:43.520: E/AndroidRuntime(3539):     at android.view.View$PerformClick.run(View.java:16987)
11-06 00:27:43.520: E/AndroidRuntime(3539):     at android.os.Handler.handleCallback(Handler.java:615)
11-06 00:27:43.520: E/AndroidRuntime(3539):     at android.os.Handler.dispatchMessage(Handler.java:92)
11-06 00:27:43.520: E/AndroidRuntime(3539):     at android.os.Looper.loop(Looper.java:137)
11-06 00:27:43.520: E/AndroidRuntime(3539):     at android.app.ActivityThread.main(ActivityThread.java:4794)
11-06 00:27:43.520: E/AndroidRuntime(3539):     at java.lang.reflect.Method.invokeNative(Native Method)
11-06 00:27:43.520: E/AndroidRuntime(3539):     at java.lang.reflect.Method.invoke(Method.java:511)
11-06 00:27:43.520: E/AndroidRuntime(3539):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
11-06 00:27:43.520: E/AndroidRuntime(3539):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
11-06 00:27:43.520: E/AndroidRuntime(3539):     at dalvik.system.NativeStart.main(Native Method)
11-06 00:27:43.520: E/AndroidRuntime(3539): Caused by: java.lang.reflect.InvocationTargetException
11-06 00:27:43.520: E/AndroidRuntime(3539):     at java.lang.reflect.Method.invokeNative(Native Method)
11-06 00:27:43.520: E/AndroidRuntime(3539):     at java.lang.reflect.Method.invoke(Method.java:511)
11-06 00:27:43.520: E/AndroidRuntime(3539):     at android.view.View$1.onClick(View.java:3586)
11-06 00:27:43.520: E/AndroidRuntime(3539):     ... 11 more
11-06 00:27:43.520: E/AndroidRuntime(3539): Caused by: java.lang.NullPointerException: file
11-06 00:27:43.520: E/AndroidRuntime(3539):     at android.net.Uri.fromFile(Uri.java:441)
11-06 00:27:43.520: E/AndroidRuntime(3539):     at com.example.start.MainActivity.oblugaRobieniaZdjecia(MainActivity.java:62)
11-06 00:27:43.520: E/AndroidRuntime(3539):     ... 14 more

Problem występuje w linijce:

zdjecieIntencja.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(filezdjecie));

Jeszcze raz proszę o pomoc
EDIT: zapomniałam dodać, że "pozwoliłem" programowi na dostęp do kamery i folderu za pomocą kodu w AndroidManifest.xml:

<uses-permission android:name="android.permission.CAMERA" /> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

dodanie znacznika <code class="java"> - @furious programming

0

Rozwiązanie: Tak jak myślałem- wszystko było w porządku w kodzie. Usuwałem ręcznie zdjęcia z telefonu i po tym nastąpiły problemy. Telefon został zresetowany i teraz apllikacja śmiga tak jak powinna.

1 użytkowników online, w tym zalogowanych: 0, gości: 1, botów: 0