弓背霞明剑照霜,秋风走马出咸阳。这篇文章主要讲述onClick按钮导致Android崩溃相关的知识,希望能为你提供帮助。
我已经克隆了this git depo,这是一个允许您捕获或选择图像并将其保存在pdf文档中的应用程序。
它工作正常,但是当我尝试集成到我的应用程序模块(新项目)中并单击该按钮以开始活动时,它崩溃了。我也没有更改Logcat也没有帮助的任何内容...
任何想法?
注意:我已经在清单中添加了活动。
编辑:我在下面添加了样式和布局
样式
<
style name="MyAppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<
item name="colorPrimary">
@color/colorPrimary<
/item>
<
item name="colorPrimaryDark">
@color/colorPrimaryDark<
/item>
<
item name="colorAccent">
@color/colorAccent<
/item>
<
item name="windowActionBar">
false<
/item>
<
item name="windowNoTitle">
true<
/item>
<
/style>
activity_pdf
<
LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.nabeeltech.capturedoc.imgtopdf.PdfActivity">
<
Button
android:id="@+id/btnPdf"
android:layout_width="match_parent"
android:layout_margin="16dp"
android:text="Generate Document"
android:layout_height="wrap_content" />
<
/LinearLayout>
PdfActivity
Button btn_Pdf = findViewById(R.id.btnPdf);
activity = this;
filename=new Date().toString();
btn_Pdf.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
getImages();
}
});
}private void getImages() {
Config config = new Config();
config.setToolbarTitleRes(R.string.str_bar_tool);
ImagePickerActivity.setConfig(config);
Intent intent = new Intent(this, ImagePickerActivity.class);
startActivityForResult(intent, INTENT_REQUEST_GET_IMAGES);
}@Override
protected void onActivityResult(int requestCode, int resuleCode, Intent intent) {
super.onActivityResult(requestCode, resuleCode, intent);
if (requestCode == INTENT_REQUEST_GET_IMAGES &
&
resuleCode == Activity.RESULT_OK) {
ArrayList<
Uri>
image_uris = intent.getParcelableArrayListExtra(ImagePickerActivity.EXTRA_IMAGE_URIS);
if(image_uris.size()!=0){
ArrayList<
String>
tempUris = new ArrayList<
>
();
for (Uri uri : image_uris) {
tempUris.add(uri.getPath());
}CallBackCreatePdf callBackCreatePdf = new CallBackCreatePdf() {
@Override
public void OnCallBackCreatePdf(String tPath) {
if(tPath!=""){
Toast.makeText(getBaseContext(),"Pdf Created", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(getBaseContext(),"Error creating PDF", Toast.LENGTH_LONG).show();
}}
};
MaterialDialog.Builder builder = new MaterialDialog.Builder(activity)
.title("Creating PDF")
.content("just a moment ...")
.cancelable(false)
.progress(true, 0);
MaterialDialog dialog = builder.build();
AsynCreatePdf asynCreatePdf = new AsynCreatePdf(activity,callBackCreatePdf,dialog,tempUris,"1",("pdf"+(new Date()).getSeconds()));
asynCreatePdf.execute();
}Log.d(LOG_ACTIVITY, "onActivityResult");
}
}
这里是堆栈跟踪
2020-02-05 16:44:36.884 17311-17311/com.nabeeltech.capturedoc E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.nabeeltech.capturedoc, PID: 17311
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nabeeltech.capturedoc/com.gun0912.tedpicker.ImagePickerActivity}: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
at androidx.appcompat.app.AppCompatDelegateImpl.setSupportActionBar(AppCompatDelegateImpl.java:421)
at androidx.appcompat.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:150)
at com.gun0912.tedpicker.ImagePickerActivity.initView(ImagePickerActivity.java:95)
at com.gun0912.tedpicker.ImagePickerActivity.onCreate(ImagePickerActivity.java:82)
at android.app.Activity.performCreate(Activity.java:7802)
at android.app.Activity.performCreate(Activity.java:7791)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
答案
此活动已经具有窗口装饰提供的操作栏。不要请求Window.FEATURE_SUPPORT_ACTION_BAR并进行设置在主题中将windowActionBar设置为false可以改用工具栏。在androidx.appcompat.app.AppCompatDelegateImpl.setSupportActionBar(AppCompatDelegateImpl.java:421)需要另一个主题。首先转到清单
<
activity android:name=".ImagePickerActivity"
android:theme="@style/CustomTheme"
android:screenOrientation="portrait"
/>
然后转到res / values / styles.xml部分。创建主题。您的主题将是
<
style name="CustomTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<
!-- Customize your theme here. -->
<
item name="colorPrimary">
@color/colorPrimary<
/item>
<
item name="colorPrimaryDark">
@color/colorPrimaryDark<
/item>
<
item name="colorAccent">
@color/colorAccent<
/item>
<
item name="windowActionBar">
false<
/item>
<
item name="windowNoTitle">
true<
/item>
<
/style>
另一答案已修复。感谢@ intellij-amiya
我想念另一种风格。我在用
<
activity android:name="com.nabeeltech.capturedoc.imgtopdf.PdfActivity"
android:label="@string/title_activity_pdf"
android:theme="@style/MyAppTheme"/>
<
activity android:name="com.gun0912.tedpicker.ImagePickerActivity"
android:theme="@style/Theme.AppCompat.Light.DarkActionBar"
android:screenOrientation="portrait"
/>
所以我用[]替换了[C0
ImagePickerActivity
【onClick按钮导致Android崩溃】现在可以使用。
推荐阅读
- 如何在Unity3d游戏中检索Android安装引荐来源网址
- Word = win32.Dispatch(“ Word.Application”)不管Word.Visible = False命令,每隔一次显示打开的文件
- Mean stack web app的基于角色的访问控制
- 发送的广播数据报在Android中无法通过EACCES
- Android中的动画ProgressBar更新
- 在SQL连接期间Xamarin Android应用程序中缺少dll System.Net.Security.Native
- 如何将bottomAppBar放置在布局中
- 带有“ 307临时重定向”的Android VideoView播放URL
- Android Amazon S3文件上传不起作用