Autore Topic: start intent in una classe interna  (Letto 372 volte)

Offline broke31

  • Nuovo arrivato
  • *
  • Post: 36
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    galaxy s6
  • Sistema operativo:
    windows
start intent in una classe interna
« il: 17 Marzo 2016, 18:28:29 CET »
0
Salve Ragazzi, ho un problema nella gestione nella gestione corretta di una intent chiamata all'interno di una classe interna, in pratica ho una imageView(che viene visualizzata in circa metà schermo) che quando subisce un doppio tap deve chiamare una nuova classe che mostra l'imageView a schermo intero, ma quando provo ad eseguire il doppio tap l'applicazione va in crash, credo che il problema sia la chiamata della intent non fatta in maniera corretta.
Vi linko il codice della classe:
Codice (Java): [Seleziona]
package it.broke31.calen;

import android.content.Intent;
import android.graphics.Matrix;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.NumberPicker;
import android.widget.TextView;
import android.widget.Toast;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Calendar;

public class SchedaActivity extends AppCompatActivity {
    private ImageButton backScheda, salveButton;
    private ImageView imageScheda;
    private TextView oggiAlleaniamo;
    private NumberPicker schedaNumberPicker;
    private GestureDetector  gestureDetector;
    private Matrix matrix = new Matrix();
    Intent i;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scheda);
        backScheda = (ImageButton) findViewById(R.id.BackImageScheda);
        imageScheda = (ImageView) findViewById(R.id.schedaImageView);
        oggiAlleaniamo = (TextView) findViewById(R.id.oggiAlleniamoTextView);
        schedaNumberPicker = (NumberPicker) findViewById(R.id.schedaNumberPicker);
        salveButton = (ImageButton) findViewById(R.id.salvaSerieFatte);
        Calendar calendar = Calendar.getInstance();
        int day = calendar.get(Calendar.DAY_OF_WEEK);

        if (day <= 7) {
            if (day == Calendar.WEDNESDAY)
                oggiAlleaniamo.setText(String.format("%sGAMBE", oggiAlleaniamo.getText()));
            imageScheda.setImageResource(R.drawable.allenamentogambe);
        }
        schedaNumberPicker.setMaxValue(10);
        schedaNumberPicker.setMinValue(0);
        schedaNumberPicker.setWrapSelectorWheel(true);
        gestureDetector = new GestureDetector(getApplicationContext(), new GestureListener());
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        gestureDetector.onTouchEvent(ev);
        return true;
    }
     //classe interna
    private class GestureListener extends GestureDetector.SimpleOnGestureListener {

        @Override
        public boolean onDown(MotionEvent e) {
            return true;
        }
        @Override
        public boolean onDoubleTap(MotionEvent e) {
            //questo è il metodo non funzionante
            i= new Intent( SchedaActivity.this,PhotoWithZoom.class);
            i.putExtra("nomeScheda",1);
            SchedaActivity.this.startActivity(i);

            return true;
        }
    }

    public void onBackVideo(View v) {
        super.onBackPressed();
    }

    public void onSaveButton(View v) {
        if (schedaNumberPicker.getValue() == 0) {
            Toast.makeText(getApplicationContext(), "non sono presenti serie da salvare", Toast.LENGTH_SHORT).show();
        } else {
            Calendar c = Calendar.getInstance();
            String filename = String.valueOf(c.get(Calendar.YEAR));
            String allenamentoStringa = "" + c.get(Calendar.YEAR) + "/" + (c.get(Calendar.MONTH)+1)+ "/" + c.get(Calendar.DAY_OF_MONTH) + " serie:" + schedaNumberPicker.getValue();
            if(canWriteOnExternalStorage()){
                writeToFile(allenamentoStringa,filename);
                Toast.makeText(getApplicationContext(),"ok..salvataggio dati eseguito con successo!",Toast.LENGTH_LONG).show();
            }
            else{
                Toast.makeText(getApplicationContext(),"sd non trovata",Toast.LENGTH_LONG).show();
            }
        }
    }

    private synchronized void writeToFile(String msg, String fileName) {
        try {
            File Root= Environment.getExternalStorageDirectory();
            File dir =new File(Root.getAbsolutePath()+"/calendarioPersonale");

            if (!dir.exists()){
                    dir.mkdir();
            }
            File file =new File(dir,fileName+".txt");
            BufferedWriter bufferedWriter= new BufferedWriter(new FileWriter(file,true));
            bufferedWriter.append(msg);
            bufferedWriter.newLine();
            bufferedWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
    public static boolean canWriteOnExternalStorage() {
        String state = Environment.getExternalStorageState();
        return Environment.MEDIA_MOUNTED.equals(state);
    }

}

il logCat è il seguente:
Off-Topic:
7040/it.broke31.calen E/InputEventReceiver: Exception dispatching input event.
03-17 18:25:15.181 27040-27040/it.broke31.calen E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI: android.content.ActivityNotFoundException: Unable to find explicit activity class {it.broke31.calen/it.broke31.calen.PhotoWithZoom}; have you declared this activity in your AndroidManifest.xml?
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1854)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1545)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at android.app.Activity.startActivityForResult(Activity.java:4283)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at android.app.Activity.startActivityForResult(Activity.java:4230)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:784)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at android.app.Activity.startActivity(Activity.java:4567)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at android.app.Activity.startActivity(Activity.java:4535)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at it.broke31.calen.SchedaActivity$GestureListener.onDoubleTap(SchedaActivity.java:71)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at android.view.GestureDetector.onTouchEvent(GestureDetector.java:576)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at it.broke31.calen.SchedaActivity.onTouchEvent(SchedaActivity.java:56)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at android.app.Activity.dispatchTouchEvent(Activity.java:3049)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at android.support.v7.internal.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:60)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at com.android.internal.policy.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2792)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at android.view.View.dispatchPointerEvent(View.java:10228)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5344)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:5180)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4620)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4673)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4639)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4781)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4647)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4838)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4620)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4673)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4639)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4647)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4620)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:7306)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:7184)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:7145)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:7416)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at android.os.MessageQueue.nativePollOnce(Native Method)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at android.os.MessageQueue.next(MessageQueue.java:323)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at android.os.Looper.loop(Looper.java:143)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at android.app.ActivityThread.main(ActivityThread.java:7224)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at java.lang.reflect.Method.invoke(Native Method)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/MessageQueue-JNI:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
03-17 18:25:15.191 27040-27040/it.broke31.calen D/AndroidRuntime: Shutting down VM
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime: FATAL EXCEPTION: main
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime: Process: it.broke31.calen, PID: 27040
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime: android.content.ActivityNotFoundException: Unable to find explicit activity class {it.broke31.calen/it.broke31.calen.PhotoWithZoom}; have you declared this activity in your AndroidManifest.xml?
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1854)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1545)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at android.app.Activity.startActivityForResult(Activity.java:4283)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at android.app.Activity.startActivityForResult(Activity.java:4230)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:784)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at android.app.Activity.startActivity(Activity.java:4567)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at android.app.Activity.startActivity(Activity.java:4535)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at it.broke31.calen.SchedaActivity$GestureListener.onDoubleTap(SchedaActivity.java:71)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at android.view.GestureDetector.onTouchEvent(GestureDetector.java:576)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at it.broke31.calen.SchedaActivity.onTouchEvent(SchedaActivity.java:56)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at android.app.Activity.dispatchTouchEvent(Activity.java:3049)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at android.support.v7.internal.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:60)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at com.android.internal.policy.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2792)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at android.view.View.dispatchPointerEvent(View.java:10228)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5344)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:5180)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4620)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4673)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4639)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4781)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4647)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4838)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4620)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4673)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4639)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4647)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4620)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:7306)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:7184)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:7145)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:7416)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at android.os.MessageQueue.nativePollOnce(Native Method)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at android.os.MessageQueue.next(MessageQueue.java:323)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:143)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:7224)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
03-17 18:25:15.191 27040-27040/it.broke31.calen E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

questo invece è il mio manifest:
Codice (XML): [Seleziona]
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="it.broke31.calen" >

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_CALENDAR" />
    <uses-permission android:name="android.permission.WRITE_CALENDAR" />

    <application
       android:allowBackup="true"
       android:icon="@mipmap/ic_launcher"
       android:label="@string/app_name"
       android:supportsRtl="true"
       android:theme="@style/AppTheme" >
        <activity android:name=".ActivityMain">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".SchedaActivity">
        </activity>
        <activity android:name=".CalendarActivity" >
        </activity>
        <activity android:name=".infoActivity" >
        </activity>
        <activity android:name=".MesiActivity" >
        </activity>
        <activity android:name=".PrincipalActivity" >
        </activity>

    </application>

</manifest>
grazie mille:-)

Offline zezzo

  • Nuovo arrivato
  • *
  • Post: 33
  • Respect: +3
    • Mostra profilo
Re:start intent in una classe interna
« Risposta #1 il: 17 Marzo 2016, 18:33:12 CET »
+1
manca l'activity nel manifest

android.content.ActivityNotFoundException: Unable to find explicit activity class {it.broke31.calen/it.broke31.calen.PhotoWithZoom}; have you declared this activity in your AndroidManifest.xml?

Offline broke31

  • Nuovo arrivato
  • *
  • Post: 36
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    galaxy s6
  • Sistema operativo:
    windows
Re:start intent in una classe interna
« Risposta #2 il: 17 Marzo 2016, 18:38:09 CET »
0
Grazie mille, era più semplice di quanto credessi..:-)