- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
您好,我使用 android studio,想要将图像上传到 RoR 服务器。但是,当我按下上传按钮时,我收到此错误:
FATAL EXCEPTION: AsyncTask #1
Process: com.example.myapplicationcamera, PID: 11616
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:309)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/entity/ContentType;
at org.apache.http.entity.mime.content.FileBody.<init>(FileBody.java:89)
at com.example.myapplicationcamera.UploadActivity$UploadFileToServer.uploadFile(UploadActivity.java:176)
at com.example.myapplicationcamera.UploadActivity$UploadFileToServer.doInBackground(UploadActivity.java:153)
at com.example.myapplicationcamera.UploadActivity$UploadFileToServer.doInBackground(UploadActivity.java:131)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.http.entity.ContentType" on path: DexPathList[[dex file "/data/data/com.example.myapplicationcamera/files/instant-run/dex/slice-support-annotations-23.4.0_eb978a40b695cbacc3760b03a82ff4d263be66cd-classes.dex", dex file "/data/data/com.example.myapplicationcamera/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/com.example.myapplicationcamera/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/com.example.myapplicationcamera/files/instant-run/dex/slice-slice_7-classes.dex", dex file "/data/data/com.example.myapplicationcamera/files/instant-run/dex/slice-slice_6-classes.dex", dex file "/data/data/com.example.myapplicationcamera/files/instant-run/dex/slice-slice_5-classes.dex", dex file "/data/data/com.example.myapplicationcamera/files/instant-run/dex/slice-slice_4-classes.dex", dex file "/data/data/com.example.myapplicationcamera/files/instant-run/dex/slice-slice_3-classes.dex", dex file "/data/data/com.example.myapplicationcamera/files/instant-run/dex/slice-slice_2-classes.dex", dex file "/data/data/com.example.myapplicationcamera/files/instant-run/dex/slice-slice_1-classes.dex", dex file "/data/data/com.example.myapplicationcamera/files/instant-run/dex/slice-slice_0-classes.dex", dex file "/data/data/com.example.myapplicationcamera/files/instant-run/dex/slice-internal_impl-23.4.0_b87f1f72ec1c9dcbc144d1d0504d45070305661a-classes.dex", dex file "/data/data/com.example.myapplicationcamera/files/instant-run/dex/slice-httpmime-4.3.5_e1f92e9669775764ad0bd3fef73fa0c37469b115-classes.dex", dex file "/data/data/com.example.myapplicationcamera/files/instant-run/dex/slice-com.android.support-support-vector-drawable-23.4.0_6c8fdbed5ab41e288837ace225df060c2da9979a-classes.dex", dex file "/data/data/com.example.myapplicationcamera/files/instant-run/dex/slice-com.android.support-support-v4-23.4.0_31bc06bad02045a071c034877ff069663b43a147-classes.dex", dex file "/data/data/com.example.myapplicationcamera/files/instant-run/dex/slice-com.android.support-appcompat-v7-23.4.0_85f3ceda35b43aaa8f8d9ba7878a3e38fde53a74-classes.dex", dex file "/data/data/com.example.myapplicationcamera/files/instant-run/dex/slice-com.android.support-animated-vector-drawable-23.4.0_03c3e23d10520277fe339d24e7aea8b4848d806b-classes.dex"],nativeLibraryDirectories=[/data/app/com.example.myapplicationcamera-1/lib/arm64, /vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at com.android.tools.fd.runtime.IncrementalClassLoader$DelegateClassLoader.findClass(IncrementalClassLoader.java:90)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.
这是我的 Activity 代码
import android.Manifest;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.VideoView;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.apache.http.entity.ContentType;
import java.io.File;
import java.io.IOException;
import com.example.myapplicationcamera.AndroidMultiPartEntity.ProgressListener;
public class UploadActivity extends Activity {
// LogCat tag
private static final String TAG = MainActivity.class.getSimpleName();
private ProgressBar progressBar;
private String filePath = null;
private TextView txtPercentage;
private ImageView imgPreview;
private VideoView vidPreview;
private Button btnUpload;
long totalSize = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_upload);
txtPercentage = (TextView) findViewById(R.id.txtPercentage);
btnUpload = (Button) findViewById(R.id.btnUpload);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
imgPreview = (ImageView) findViewById(R.id.imgPreview);
vidPreview = (VideoView) findViewById(R.id.videoPreview);
// Changing action bar background color
// getActionBar().setBackgroundDrawable(
// new ColorDrawable(Color.parseColor(getResources().getString(
// R.string.ColorRed))));
// Receiving the data from previous activity
Intent i = getIntent();
// image or video path that is captured in previous activity
filePath = i.getStringExtra("filePath");
// boolean flag to identify the media type, image or video
boolean isImage = i.getBooleanExtra("isImage", true);
if (filePath != null) {
// Displaying the image or video on the screen
previewMedia(isImage);
} else {
Toast.makeText(getApplicationContext(),
"Sorry, file path is missing!", Toast.LENGTH_LONG).show();
}
btnUpload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// uploading the file to server
new UploadFileToServer().execute();
}
});
}
/**
* Displaying captured image/video on the screen
* */
private void previewMedia(boolean isImage) {
// Checking whether captured media is image or video
if (isImage) {
imgPreview.setVisibility(View.VISIBLE);
vidPreview.setVisibility(View.GONE);
// bimatp factory
BitmapFactory.Options options = new BitmapFactory.Options();
// down sizing image as it throws OutOfMemory Exception for larger
// images
options.inSampleSize = 8;
final Bitmap bitmap = BitmapFactory.decodeFile(filePath, options);
imgPreview.setImageBitmap(bitmap);
} else {
imgPreview.setVisibility(View.GONE);
vidPreview.setVisibility(View.VISIBLE);
vidPreview.setVideoPath(filePath);
// start playing
vidPreview.start();
}
}
/**
* Uploading the file to server
* */
private class UploadFileToServer extends AsyncTask<Void, Integer, String> {
@Override
protected void onPreExecute() {
// setting progress bar to zero
progressBar.setProgress(0);
super.onPreExecute();
}
@Override
protected void onProgressUpdate(Integer... progress) {
// Making progress bar visible
progressBar.setVisibility(View.VISIBLE);
// updating progress bar value
progressBar.setProgress(progress[0]);
// updating percentage value
txtPercentage.setText(String.valueOf(progress[0]) + "%");
}
@Override
protected String doInBackground(Void... params) {
return uploadFile();
}
@SuppressWarnings("deprecation")
private String uploadFile() {
String responseString = null;
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(Config.FILE_UPLOAD_URL);
try {
AndroidMultiPartEntity entity = new AndroidMultiPartEntity(
new ProgressListener() {
@Override
public void transferred(long num) {
publishProgress((int) ((num / (float) totalSize) * 100));
}
});
File sourceFile = new File(filePath);
// Adding file data to http body
entity.addPart("image", new FileBody(sourceFile));
// Extra parameters if you want to pass to server
entity.addPart("website",
new StringBody("www.androidhive.info"));
entity.addPart("email", new StringBody("abc@gmail.com"));
totalSize = entity.getContentLength();
httppost.setEntity(entity);
// Making server call
HttpResponse response = httpclient.execute(httppost);
HttpEntity r_entity = response.getEntity();
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == 200) {
// Server response
responseString = EntityUtils.toString(r_entity);
} else {
responseString = "Error occurred! Http Status Code: "
+ statusCode;
}
} catch (ClientProtocolException e) {
responseString = e.toString();
} catch (IOException e) {
responseString = e.toString();
}
return responseString;
}
@Override
protected void onPostExecute(String result) {
Log.e(TAG, "Response from server: " + result);
// showing the server response in an alert dialog
showAlert(result);
super.onPostExecute(result);
}
}
/**
* Method to show alert dialog
* */
private void showAlert(String message) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(message).setTitle("Response from Servers")
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// do nothing
}
});
AlertDialog alert = builder.create();
alert.show();
}
}
这是我的 gradle 导入:
android {
compileSdkVersion 23
buildToolsVersion "24.0.2"
useLibrary 'org.apache.http.legacy'
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
}
defaultConfig {
applicationId "com.example.myapplicationcamera"
minSdkVersion 22
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
// compile('org.apache.httpcomponents:httpcore:4.3')
compile files('libs/commons-io-2.4.jar')
compile files('libs/fluent-hc-4.3.1.jar')
compile files('libs/httpcore-4.3.jar')
compile files('libs/httpmime-4.3.1.jar')
compile files('libs/picasso-2.1.1.jar')
}
我在这个问题上坐了几个小时,但互联网上没有解决方案。有人有想法吗?
最佳答案
这确实正如异常所说,类加载器找不到该类。我可以建议几件事:
关闭项目,关闭工作室,打开并重试。
看看你的 Android 安装中是否确实有 org/apache 等。如果您有 jar 文件,则可以使用 jar tvfwhatever.jar 列出内容。将是一个很长的列表,所以 jar tvfwhatever.jar | grep apache
关于android - Java.lang.NoClassDefFoundError : Failed resolution of: Lorg/apache/http/entity/ContentType;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39415076/
val jobConf = new JobConf(hbaseConf) jobConf.setOutputFormat(classOf[TableOutputFormat]) jobConf.s
我为我的项目创建了一个新模块来添加一些额外的功能。在该模块中,我在模块的 Gradle 文件 implementation 'org.jsoup:jsoup:1.10.2' 中添加了 Jsoup 依赖
我已经能够使用出色的任务 appStartWar 或 tomcatStartWar 成功地在tomcat上部署我的Web应用程序 war 文件,但是当我尝试使用 appStart 或到位部署同一Web
我正在使用具有 Maven 支持的 Intellij 启动 tomcat。一旦我添加以下 tomcat maven 依赖项: org.apache.tomc
请帮忙。我正在尝试使用 Jboss 8.1.0 缓存功能做一个简单的缓存机制。这就是我实现项目结构的方式: pomn 文件: 4.0.0 org.jboss
我正在使用 Espresso 进行仪器测试,但在堆栈跟踪中出现此错误: 错误是由缺少的类引起的,如下所示: Caused by: java.lang.ClassNotFoundException: D
早些时候,我的 Android 项目运行良好。但是在更新客户端提供的 .aar 库后,我收到了这个错误。 在我们的项目中,我们没有在任何地方使用 jacoco 依赖项 java.lang.NoClas
我正在尝试使用 wildfly-8 在本地计算机上运行的 Web 应用程序中显示图形报告,但遇到了下一个错误。 java.lang.NoClassDefFoundError: Lorg/jfree/c
我遇到了应用程序崩溃和提供此堆栈跟踪的问题 java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/commons/code
我在进行插桩测试时遇到了以下运行时错误。 Unknown source file : UNEXPECTED TOP-LEVEL EXCEPTION: Unknown source file : com
这个问题在这里已经有了答案: Android Studio : Error injecting while Appengine backend generation (1 个回答) 关闭 8 年前。
httpPost 在所有 8.1 及以下版本的 android 设备中运行,但在 android 9.0 中运行时出现如下错误, Failed resolution of: Lorg/apache/h
从昨天开始我就有麻烦了。在我的实习中,我遇到了以下构建错误,但我不明白为什么: $ cordova build android [...] FAILURE: Build failed with an
有人可以告诉我如何解决这个问题吗?我试图创建一个新的 Maven 项目,但由于某种原因失败了 描述资源路径位置类型目标 org.apache.maven.plugins:maven-resources
我正在从 Tomcat 6.0.24 升级到 7.0.23。我有一个 maven 2.2.1 项目,它使用 jspc maven 插件预编译 JSP。 当我为我的应用程序部署 WAR 文件并尝试访问
我收到以下错误: Process: com.project.publiko, PID: 27061 java.lang.NoSuchFieldError: No static field INSTAN
错误: E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1 Process: com.azail.cart.debug, PID: 2403
每当我尝试为我的项目构建 APK 时,都会收到以下错误: Error:Error converting bytecode to dex: Cause: com.android.dex.DexExcep
我是用java创建一个strut项目但是报错。我认为此错误是由于缺少 jar 文件造成的,我不知道要下载哪个版本。 这是我的 lib 文件夹中的 jar 文件: commons-digester-2.
我想使用最新的 JUnit 版本: org.junit.jupiter junit-jupiter-engine
我是一名优秀的程序员,十分优秀!