ActivityNotFoundException甚至为Fragment声明的操作

时间:2014-12-29 02:19:05

标签: android fragment android-fragmentactivity activitynotfoundexception

我有以下代码:

public class Fragment1 extends Fragment implements View.OnClickListener {

    Button button;

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        if(container == null )
            return null;

        View view = (LinearLayout)inflater.inflate(R.layout.fragment1_layout, container, false);
        button = (Button) view.findViewById(R.id.button);
        button.setOnClickListener(this);
        return view;
    }

    @Override
    public void onClick(View v) {

        if(v.getId() == R.id.button) {
            startActivity(new Intent(getActivity().getApplicationContext(), Fragment3.class));
        }
    }
}

我是从Android开始的,我甚至在manifestxt.xml中声明了一个活动:

活动android:name =" pachage ... destiny_fragment"

连续展示

E/AndroidRuntime﹕ FATAL EXCEPTION: main
    android.content.ActivityNotFoundException: Unable to find explicit activity class {eguias.delogic.com.br.eguiasmobile/eguias.delogic.com.br.eguiasmobile.Fragment3}; have you declared this activity in your AndroidManifest.xml?
            at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1541)
            at android.app.Instrumentation.execStartActivity(Instrumentation.java:1416)
            at android.app.Activity.startActivityForResult(Activity.java:3351)
            at android.app.Activity.startActivityForResult(Activity.java:3312)
            at android.support.v4.app.FragmentActivity.startActivityFromFragment(FragmentActivity.java:826)
            at android.support.v4.app.Fragment.startActivity(Fragment.java:896)
            at eguias.delogic.com.br.eguiasmobile.Fragment1.onClick(Fragment1.java:37)
            at android.view.View.performClick(View.java:4084)
            at android.view.View$PerformClick.run(View.java:16966)
            at android.os.Handler.handleCallback(Handler.java:615)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4745)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)

应用程序正常运行但错误" android.content.ActivityNotFoundException"总是在logcat中显示。

感谢。

2 个答案:

答案 0 :(得分:0)

您的Fragment3.class应该延长Activity,这应该在AndroidManifest.xml中声明。

答案 1 :(得分:0)

主要

/** Receives UpdateEvent */
const changes$ = new Subject<FileChangesEvent>();

/** mock for 'this' */
const context = {
    notify: (...args) => console.log('[CONTEXT.NOTIFY]: ', ...args),
    processAdds: (input) => of(input).pipe(delay(input.debounce || 1), map(i => Object.assign(i, ...fetch(i.url)))),
    processUpdates: (input) => of(input).pipe(delay(input.debounce || 1), map(i => Object.assign(i, ...fetch(i.url)))),
    processDeletes: (input) => of(input).pipe(delay(input.debounce || 1), map(i => Object.assign(i, { modified: 'fetchUpdates' }))),
};

/** Process FilesChange event */
const stream$ = changes$
    .pipe(
        /** Side effect for log current step */
        tap(event => console.log('onFileChanges trigged, event data: ', event.changes)),
        /** Fetching array of changes */
        map(event => event.changes),
        /** Use it for wait all 'forked' observables */
        flatMap(
            /** Process each record in parallel */
            changes => forkJoin(
                changes.map(change =>
                    /** Update processing */
                    of(change)
                        .pipe(
                            tap(input => console.log('Validating the file Type: ', input)),
                            /** fetching data based on update type */
                            flatMap(input =>
                                input.type === FileChangeType.ADDED
                                    ? context.processAdds(input)
                                    : context.processUpdates(input),
                            ),
                            /** remove large files from update */
                            map(input => (
                                input.type === FileChangeType.UPDATED && input.size < CONTENT_SIZE_LIMIT
                                    ? Object.assign(input, { value: '' })
                                    : input
                            )),
                            /** side effect for pubsub notifications */
                            tap(updates => context.notify(updates)),
                        ),
                ),
            ),
        ),
    );

/** When updates stream was finished */
stream$.subscribe(
    (...args) => console.log('[TICK]: ', ...args), // When all event updates was processed
    (...args) => console.log('[ERROR]: ', ...args),
    (...args) => console.log('[DONE]: ', ...args),
);

export const updateEventsStream = (event) => changes$.next(event);