gpt4 book ai didi

java - 错误 :Execution failed for task ':app:transformClassesWithDexForDebug' .

转载 作者:行者123 更新时间:2023-11-30 01:25:15 24 4
gpt4 key购买 nike

出于某种原因,当我在 Android studio 中运行该应用程序时,它给了我这个:

Error:Could not create the Java Virtual Machine.

Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
Error:A fatal exception has occurred. Program will exit.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files (x86)\Java\jdk1.7.0_80\bin\java.exe'' finished with non-zero exit value 1
Information:BUILD FAILED

这发生在 android studio 中。这是我的应用程序:

主要 Activity .java:

package com.example.amanuel.webview;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

private Button button;
private WebView webView;
private EditText editText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
OnClickEvent();
}

public void OnClickEvent(){
button = (Button) findViewById(R.id.Url_Button);
webView = (WebView) findViewById(R.id.webView);
editText = (EditText) findViewById(R.id.Edit_Text_Url);

button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String url = editText.getText().toString();
webView.getSettings().setLoadsImagesAutomatically(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
webView.loadUrl(url);
}
});
}
}

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.example.amanuel.webview.MainActivity">

<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="URL"
android:id="@+id/Url_Button"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />

<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/webView"
android:layout_below="@+id/Edit_Text_Url"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/Edit_Text_Url"
android:layout_below="@+id/Url_Button"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="https://google.com" />
</RelativeLayout>

和AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.amanuel.webview" >

<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>

非常感谢您的帮助!

最佳答案

您可能有多个具有相同签名的 dex 文件来修复此问题,将其添加到您的应用级 gradle 文件中。

 defaultConfig {
multiDexEnabled true
}

关于java - 错误 :Execution failed for task ':app:transformClassesWithDexForDebug' .,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36497973/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com