我正在尝试在我的应用程序中扩展FloatingActionButton。当我尝试构建时,我收到编译器错误。如果我删除扩展FloatingActionButton的类,那么我的应用程序将编译
:app:transformClassesWithDexForDebug
UNEXPECTED TOP-LEVEL EXCEPTION:
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2
错误似乎只发生在我向extend类添加方法时。
此编译
public class TriedFAB extends FloatingActionButton {
public TriedFAB(Context context) {
super(context);
}
public TriedFAB(Context context, AttributeSet attrs) {
super(context, attrs);
}
public TriedFAB(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
// private void failCompile(){
//
// }
}
这会导致编译器错误
public class TriedFAB extends FloatingActionButton {
public TriedFAB(Context context) {
super(context);
}
public TriedFAB(Context context, AttributeSet attrs) {
super(context, attrs);
}
public TriedFAB(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
private void failCompile(){
}
}
编辑3:
看起来我的应用程序太大了,达到了dex限制
答案 0 :(得分:1)
尝试这样。在xml中声明
<android.support.design.widget.FloatingActionButton
android:id="@+id/myfloatingbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/ic_dialog_email"
/>
然后使用
floatingActionButton=(FloatingActionButton)findViewById(R.id.myfloatingbutton);
//handle FloatingActionButton Click
floatingActionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(),"FloatingActionButton is Clicked",Toast.LENGTH_SHORT).show();
}
});
答案 1 :(得分:0)
点击dex限制,请参阅消息,而不是gradle控制台
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:484)
at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:261)
at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:473)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:161)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:504)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
at com.android.dx.command.dexer.Main.run(Main.java:277)
at com.android.dx.command.dexer.Main.main(Main.java:245)
at com.android.dx.command.Main.main(Main.java:106)