当我第一次构建应用程序时,Java编译器无法显示以下错误:
但是第二次一切正常。
我正在做的是在Activity中使用DialogFragment
我创建一个抽象类,声明一个接口,并将通过特定的DialogFragment进行扩展:
public abstract class MyGenericDialogFragment extends DialogFragment {
protected OnCompleteListener mListener;
public static interface OnCompleteListener {
public abstract void onComplete(String time);
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
try {
this.mListener = (OnCompleteListener)context;
}
catch (final ClassCastException e) {}
}
public OnCompleteListener getmListener() {
return mListener;
}
}
创建DialogFragment的Activity实现了抽象类内部声明的接口:
public class MainActivity extends AppCompatActivity implements MyGenericDialogFragment.OnCompleteListener{
...
// Create Dialog that extends MyGenericDialogFragment
MySpecificDialog dial = new MyDialog();
dial.show(getSupportFragmentManager(),"tag");
...
...
@Override
public void onComplete(String text) {
//do something whit text
}
有什么建议吗?
编辑:这是堆栈跟踪
org.gradle.api.internal.tasks.compile.CompilationFailedException:编译失败;有关详细信息,请参见编译器错误输出。 在org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:52) 在org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:37) 在org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.delegateAndHandleErrors(NormalizingJavaCompiler.java:98) 在org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:51) 在org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:37) 在org.gradle.api.internal.tasks.compile.incremental.SelectiveCompiler.execute(SelectiveCompiler.java:73) 在org.gradle.api.internal.tasks.compile.incremental.SelectiveCompiler.execute(SelectiveCompiler.java:34) 在org.gradle.api.internal.tasks.compile.incremental.IncrementalResultStoringDecorator.execute(IncrementalResultStoringDecorator.java:41) 在org.gradle.api.internal.tasks.compile.incremental.IncrementalResultStoringDecorator.execute(IncrementalResultStoringDecorator.java:27) 在org.gradle.api.internal.tasks.compile.incremental.IncrementalAnnotationProcessingCompiler.execute(IncrementalAnnotationProcessingCompiler.java:50) 在org.gradle.api.internal.tasks.compile.incremental.IncrementalAnnotationProcessingCompiler.execute(IncrementalAnnotationProcessingCompiler.java:36) 在org.gradle.api.tasks.compile.JavaCompile.performCompilation(JavaCompile.java:156) 在org.gradle.api.tasks.compile.JavaCompile.compile(JavaCompile.java:126) 在com.android.build.gradle.tasks.factory.AndroidJavaCompile.compile(AndroidJavaCompile.java:92) 在sun.reflect.GeneratedMethodAccessor581.invoke(未知来源) 在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:498) 在org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73) 在org.gradle.api.internal.project.taskfactory.IncrementalTaskAction.doExecute(IncrementalTaskAction.java:50) 在org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39) 在org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26) 在org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter $ 1.run(ExecuteActionsTaskExecuter.java:124) 在org.gradle.internal.progress.DefaultBuildOperationExecutor $ RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)处 在org.gradle.internal.progress.DefaultBuildOperationExecutor $ RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328) 在org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199) 在org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110) 在org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:113)处 在org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:95) 在org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:73) 在org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)处 在org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59) 在org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54) 在org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:59) 在org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:101)处 在org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44) 在org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:91) 在org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62)处 在org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:59) 在org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54) 在org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43) 在org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34) 在org.gradle.execution.taskgraph.DefaultTaskGraphExecuter $ EventFiringTaskWorker $ 1.run(DefaultTaskGraphExecuter.java:256) 在org.gradle.internal.progress.DefaultBuildOperationExecutor $ RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)处 在org.gradle.internal.progress.DefaultBuildOperationExecutor $ RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328) 在org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199) 在org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110) 在org.gradle.execution.taskgraph.DefaultTaskGraphExecuter $ EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:249)处 在org.gradle.execution.taskgraph.DefaultTaskGraphExecuter $ EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:238)处 在org.gradle.execution.taskgraph.DefaultTaskPlanExecutor $ TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:123)处 在org.gradle.execution.taskgraph.DefaultTaskPlanExecutor $ TaskExecutorWorker.access $ 200(DefaultTaskPlanExecutor.java:79) 在org.gradle.execution.taskgraph.DefaultTaskPlanExecutor $ TaskExecutorWorker $ 1.execute(DefaultTaskPlanExecutor.java:104) 在org.gradle.execution.taskgraph.DefaultTaskPlanExecutor $ TaskExecutorWorker $ 1.execute(DefaultTaskPlanExecutor.java:98) 在org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:663)处 在org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:597) 在org.gradle.execution.taskgraph.DefaultTaskPlanExecutor $ TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:98) 在org.gradle.internal.concurrent.ExecutorPolicy $ CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63) 在org.gradle.internal.concurrent.ManagedExecutorImpl $ 1.run(ManagedExecutorImpl.java:46) 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617) 在org.gradle.internal.concurrent.ThreadFactoryImpl $ ManagedThreadRunnable.run(ThreadFactoryImpl.java:55) 在java.lang.Thread.run(Thread.java:745)