当应用程序运行时,Sweet Alert崩溃

时间:2019-03-23 09:35:50

标签: android sweetalert

我想对我的应用程序使用甜蜜警报,因此我正在基于turtorial创建一个演示。起初,我陷入了“ android:icon”问题,但设法解决了这个问题,现在每当使用SweetAlert时我的应用程序就会崩溃。我尝试使用xmlns:tools =“ http://schemas.android.com/tools”,tools:replace =“ android:icon”或将甜蜜警报降级为1.2版本,但仍然崩溃。这是我的代码。

activity_main.xml

<Button
        android:id="@+id/btnButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="add new"
        android:layout_gravity="center"
        />

MainActivity.java

public class MainActivity extends AppCompatActivity {
    Button b;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        b = (Button) findViewById(R.id.btnButton);
        b.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new SweetAlertDialog(MainActivity.this).setTitleText("Hello Man!")
                        .setContentText("Welcome").show();
            }
        });
    }
}

我的错误

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: day10.silverboy.sweetalert, PID: 3135
    java.lang.RuntimeException: Unknown animation name: cn.pedant.SweetAlert.Rotate3dAnimation error:null
        at cn.pedant.SweetAlert.OptAnimationLoader.createAnimationFromXml(OptAnimationLoader.java:77)
        at cn.pedant.SweetAlert.OptAnimationLoader.createAnimationFromXml(OptAnimationLoader.java:64)
        at cn.pedant.SweetAlert.OptAnimationLoader.createAnimationFromXml(OptAnimationLoader.java:41)
        at cn.pedant.SweetAlert.OptAnimationLoader.loadAnimation(OptAnimationLoader.java:22)
        at cn.pedant.SweetAlert.SweetAlertDialog.<init>(SweetAlertDialog.java:73)
        at cn.pedant.SweetAlert.SweetAlertDialog.<init>(SweetAlertDialog.java:65)
        at day10.silverboy.sweetalert.MainActivity$1.onClick(MainActivity.java:20)
        at android.view.View.performClick(View.java:4780)
        at android.view.View$PerformClick.run(View.java:19866)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5254)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

1 个答案:

答案 0 :(得分:0)

SweetAlertDialog pDialog = new SweetAlertDialog(this, 
SweetAlertDialog.PROGRESS_TYPE);
pDialog.getProgressHelper().setBarColor(Color.parseColor("#A5DC86"));
pDialog.setTitleText("Loading");
pDialog.setCancelable(false);

b.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
           pDialog.show();`enter code here`
        }
    });