FTP客户端noClassDefFound错误:org.apache.commons.net.ftp.FTPClient [英] noClassDefFound error on ftp client: org.apache.commons.net.ftp.FTPClient
问题描述
我的工作是将文件发送到一个URL数据库的应用程序。我开始只是想发送图片。目前,我在我的Java得到一个noclassDefFound错误。我曾尝试更新Java中,删除和重新添加的jar文件,我双重检查我的清单了适当的权限,所以我来这里寻求帮助。我张贴的LogCat中,但我将问题范围缩小到两行code的:在FTP类24和82在uploadmedia类。我还包括有问题的类和我的清单。
LogCat中
11月10日至4日:33:36.028:E / AndroidRuntime(5013):致命异常:主要
11月10日至4日:33:36.028:E / AndroidRuntime(5013):java.lang.NoClassDefFoundError的:org.apache.commons.net.ftp.FTPClient
11月10日至4日:33:36.028:E / AndroidRuntime(5013):在com.cameratest.UploadFTP.FTPUpload(UploadFTP.java:23)
11月10日至4日:33:36.028:E / AndroidRuntime(5013):在com.cameratest.UploadMedia.onActivityResult(UploadMedia.java:80)
11月10日至4日:33:36.028:E / AndroidRuntime(5013):在android.app.Activity.dispatchActivityResult(Activity.java:5192)
11月10日至4日:33:36.028:E / AndroidRuntime(5013):在android.app.ActivityThread.deliverResults(ActivityThread.java:3137)
11月10日至4日:33:36.028:E / AndroidRuntime(5013):在android.app.ActivityThread.handleSendResult(ActivityThread.java:3184)
11月10日至4日:33:36.028:E / AndroidRuntime(5013):在android.app.ActivityThread.access $ 1100(ActivityThread.java:130)
11月10日至4日:33:36.028:E / AndroidRuntime(5013):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1243)
11月10日至4日:33:36.028:E / AndroidRuntime(5013):在android.os.Handler.dispatchMessage(Handler.java:99)
11月10日至4日:33:36.028:E / AndroidRuntime(5013):在android.os.Looper.loop(Looper.java:137)
11月10日至4日:33:36.028:E / AndroidRuntime(5013):在android.app.ActivityThread.main(ActivityThread.java:4745)
11月10日至4日:33:36.028:E / AndroidRuntime(5013):在java.lang.reflect.Method.invokeNative(本机方法)
11月10日至4日:33:36.028:E / AndroidRuntime(5013):在java.lang.reflect.Method.invoke(Method.java:511)
11月10日至4日:33:36.028:E / AndroidRuntime(5013):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:786)
11月10日至4日:33:36.028:E / AndroidRuntime(5013):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11月10日至4日:33:36.028:E / AndroidRuntime(5013):在dalvik.system.NativeStart.main(本机方法)
清单
<清单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=com.cameratest
安卓版code =1
机器人:=的versionName1.0> <用途-SDK
安卓的minSdkVersion =8
机器人:targetSdkVersion =15/> <使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAGE/>
<使用许可权的android:NAME =android.permission.ACCESS_FINE_LOCATION/>
<使用许可权的android:NAME =android.permission.INTERNET对/>
<使用许可权的android:NAME =android.permission.RECORD_AUDIO/>
<使用许可权的android:NAME =android.permission.CAMERA/>
<使用许可权的android:NAME =android.permission.RECORD_VIDEO/>
<使用许可权的android:NAME =android.permission.READ_PHONE_STATE/> <使用特征的android:NAME =android.hardware.camera/>
<使用特征的android:NAME =android.hardware.camera.autofocus/> <应用
机器人:图标=@绘制/ ic_launcher
机器人:标签=@字符串/ APP_NAME
机器人:主题=@风格/ AppTheme>
<活动
机器人:主NAME =
机器人:标签=@字符串/ title_activity_main>
&所述;意图滤光器>
<作用机器人:名字=android.intent.action.MAIN/> <类机器人:名字=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
< /活性GT;
<活动
机器人:名字=sate2012.avatar.android.UploadMedia
机器人:标签=@字符串/ APP_NAME
机器人:screenOrientation =风景>
< /活性GT;
<活动
机器人:名字=sate2012.avatar.android.MailSenderActivity
机器人:标签=上传数据点>
&所述;意图滤光器>
<作用机器人:名字=android.intent.action.MAILSENDERACTIVITY/> <类机器人:名字=android.intent.category.DEFAULT/>
&所述; /意图滤光器>
< /活性GT;
<活动
机器人:名字=sate2012.avatar.android.GMailSender
机器人:标签=@字符串/ title_mail_sender_activity
机器人:screenOrientation =风景>
&所述;意图滤光器>
<作用机器人:名字=sate2012.avatar.android.GMAILSENDER/> <类机器人:名字=android.intent.category.DEFAULT/>
&所述; /意图滤光器>
< /活性GT;
<活动
机器人:名字=sate2012.avatar.android.UploadData
机器人:标签=UploadData>
&所述;意图滤光器>
<作用机器人:名字=sate2012.avatar.android.UPLOADDATA/> <类机器人:名字=android.intent.category.DEFAULT/>
&所述; /意图滤光器>
< /活性GT;
<活动
机器人:名字=。UploadMedia
机器人:标签=@字符串/ APP_NAME>
&所述;意图滤光器>
<作用机器人:名字=android.intent.action.UPLOAD_MEDIA/> <类机器人:名字=android.intent.category.DEFAULT/>
&所述; /意图滤光器>
< /活性GT;
<活动
机器人:名字=摄影师
机器人:标签=photoclass>
&所述;意图滤光器>
<作用机器人:名字=android.intent.action.PHOTOGRAPHER/> <类机器人:名字=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
< /活性GT;
<活动
机器人:名字=。UploadFTP
机器人:标签=photoclass>
&所述;意图滤光器>
<作用机器人:名字=android.intent.action.UPLOAD_FTP/> <类机器人:名字=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
< /活性GT;
< /用途>< /清单>
FTP类
包com.cameratest;进口android.os.Bundle;
进口android.os.Handler;
进口android.app.Activity;
进口android.content.Context;
进口java.io.IOException异常;
进口java.io.BufferedInputStream中;
进口java.io.FileInputStream中;
进口java.net.InetAddress中;
进口org.apache.commons.net.ftp.FTPClient;
公共类UploadFTP延伸活动{ / **当第一次创建活动调用。 * /
@覆盖
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
} 公共静态字符串FTPUpload(字符串文件路径,字符串扩展,上下文thisContext){
FTPClient ftpClient =新FTPClient();
长的时间=(System.currentTimeMillis的());
字符串文件名=T+时间;
尝试{
ftpClient.connect(InetAddress.getByName(24.123.68.146));
ftpClient.login(的OpenSim,widdlyscuds);
ftpClient.changeWorkingDirectory(../../无功/网络/头像/上传);
如果(ftpClient.getReplyString()。包含(250)){
处理器progressHandler =新的处理程序();
ftpClient.setFileType(org.apache.commons.net.ftp.FTP.BINARY_FILE_TYPE);
的BufferedInputStream buffIn = NULL;
buffIn =新的BufferedInputStream(新的FileInputStream(文件路径));
ftpClient.enterLocalPassiveMode();
ProgressInputStream progressInput =新ProgressInputStream(buffIn,progressHandler);
ftpClient.storeFile(文件名+扩展名,progressInput);
buffIn.close();
ftpClient.logout();
ftpClient.disconnect();
}
}赶上(IOException异常五){
}
返回文件名+扩展名;
}
}
上传媒体:称FTP类
包com.cameratest;
进口的java.io.File;进口android.app.Activity;
进口android.content.Context;
进口android.content.Intent;
进口android.content.pm.ActivityInfo;
进口android.os.Bundle;
进口android.os.Environment;
进口android.view.View;
进口android.view.View.OnClickListener;
进口android.widget.ImageButton;/ **
*上传菜单允许用户选择不同的媒体类型上传到
*服务器
* /
公共类UploadMedia扩展活动实现OnClickListener {
私人文件SD;
私人文件storageFolder;
私人文件mediaFolder;
私人的ImageButton pictureB;
私人string数据类型;
私人字符串media_filepath;
私人字符串media_filename;
私人字符串media_extension;
私人静态字符串image_filepath;
公共静态语境thisContext; / **
*当第一次创建活动调用。
* /
@覆盖
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
thisContext = getApplicationContext();
的setContentView(R.layout.upload_menu);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
createStorageDirectory();
pictureB =(的ImageButton)findViewById(R.id.cameraButton);
pictureB.setOnClickListener(本); } / **
*回应到任何按钮pressed
*
* @参数查看
* V - 按钮点击
* /
公共无效的onClick(视图v){
我的意图;
开关(v.getId()){
案例(R.id.cameraButton):
。的dataType = getResources()的getString(R.string.type_picture);
I =新意图(UploadMedia.this,Photographer.class);
startActivityForResult(ⅰ,Globals.CAMERA_REQUEST);
打破;
}
} 公共无效onBack pressed(){
完();
} / **
*调用当个人活动(图片,视频,音频)完成。
* /
@覆盖
公共无效的onActivityResult(INT申请code,INT结果code,意图数据){
// super.onActivityResult(要求code,结果code,数据);
如果(结果code == Activity.RESULT_OK){ 如果(要求code == Globals.CAMERA_REQUEST){
media_filepath = getImage_filepath();
media_extension =_P.png;
}
media_filename = UploadFTP.FTPUpload(media_filepath,
media_extension,thisContext);
意图MailIntent =新意图(getApplicationContext()
MailSenderActivity.class);
MailIntent.putExtra(类型,dataType的);
MailIntent.putExtra(文件名,media_filename);
startActivity(MailIntent);
完();
}
} 公共静态无效setImage_filepath(字符串FP){
image_filepath = FP;
} 公共字符串getImage_filepath(){
返回image_filepath;
} @覆盖
公共无效的onDestroy(){
完();
super.onDestroy();
} 公共无效createStorageDirectory(){
SD = Environment.getExternalStorageDirectory();
storageFolder =新的文件(SD,Globals.STORAGE_DIRECTORY);
如果(sd.canWrite()){
如果(!storageFolder.exists())
storageFolder.mkdir();
mediaFolder =新的文件(SD,Globals.STORAGE_DIRECTORY
+ Globals.MEDIA_DIRECTORY);
如果(!mediaFolder.exists())
mediaFolder.mkdir();
}
}
}
添加公共净3.1.jar文件在你的应用程序的。点击这里
I am working on an app that sends files to a url database. I am starting with just trying to send a picture. Currently I am getting a noclassDefFound error in my java. I have tried updating java, deleting and adding the jar files again, and I double checked my manifest for the proper permissions so I am coming here for help. I am posting the LogCat but I narrowed the problem to two lines of code: 24 in the FTP class and 82 in the uploadmedia class. I am also including the classes in question and my manifest.
LogCat
10-04 11:33:36.028: E/AndroidRuntime(5013): FATAL EXCEPTION: main
10-04 11:33:36.028: E/AndroidRuntime(5013): java.lang.NoClassDefFoundError: org.apache.commons.net.ftp.FTPClient
10-04 11:33:36.028: E/AndroidRuntime(5013): at com.cameratest.UploadFTP.FTPUpload(UploadFTP.java:23)
10-04 11:33:36.028: E/AndroidRuntime(5013): at com.cameratest.UploadMedia.onActivityResult(UploadMedia.java:80)
10-04 11:33:36.028: E/AndroidRuntime(5013): at android.app.Activity.dispatchActivityResult(Activity.java:5192)
10-04 11:33:36.028: E/AndroidRuntime(5013): at android.app.ActivityThread.deliverResults(ActivityThread.java:3137)
10-04 11:33:36.028: E/AndroidRuntime(5013): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3184)
10-04 11:33:36.028: E/AndroidRuntime(5013): at android.app.ActivityThread.access$1100(ActivityThread.java:130)
10-04 11:33:36.028: E/AndroidRuntime(5013): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1243)
10-04 11:33:36.028: E/AndroidRuntime(5013): at android.os.Handler.dispatchMessage(Handler.java:99)
10-04 11:33:36.028: E/AndroidRuntime(5013): at android.os.Looper.loop(Looper.java:137)
10-04 11:33:36.028: E/AndroidRuntime(5013): at android.app.ActivityThread.main(ActivityThread.java:4745)
10-04 11:33:36.028: E/AndroidRuntime(5013): at java.lang.reflect.Method.invokeNative(Native Method)
10-04 11:33:36.028: E/AndroidRuntime(5013): at java.lang.reflect.Method.invoke(Method.java:511)
10-04 11:33:36.028: E/AndroidRuntime(5013): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
10-04 11:33:36.028: E/AndroidRuntime(5013): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-04 11:33:36.028: E/AndroidRuntime(5013): at dalvik.system.NativeStart.main(Native Method)
Manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cameratest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_VIDEO" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".Main"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="sate2012.avatar.android.UploadMedia"
android:label="@string/app_name"
android:screenOrientation="landscape" >
</activity>
<activity
android:name="sate2012.avatar.android.MailSenderActivity"
android:label="Upload Data Point" >
<intent-filter>
<action android:name="android.intent.action.MAILSENDERACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="sate2012.avatar.android.GMailSender"
android:label="@string/title_mail_sender_activity"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="sate2012.avatar.android.GMAILSENDER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="sate2012.avatar.android.UploadData"
android:label="UploadData" >
<intent-filter>
<action android:name="sate2012.avatar.android.UPLOADDATA" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".UploadMedia"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.UPLOAD_MEDIA" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Photographer"
android:label="photoclass" >
<intent-filter>
<action android:name="android.intent.action.PHOTOGRAPHER" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".UploadFTP"
android:label="photoclass" >
<intent-filter>
<action android:name="android.intent.action.UPLOAD_FTP" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
FTP class
package com.cameratest;
import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.content.Context;
import java.io.IOException;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.net.InetAddress;
import org.apache.commons.net.ftp.FTPClient;
public class UploadFTP extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public static String FTPUpload(String filepath, String extension, Context thisContext) {
FTPClient ftpClient = new FTPClient();
long time = (System.currentTimeMillis());
String filename = "T" + time;
try {
ftpClient.connect(InetAddress.getByName("24.123.68.146"));
ftpClient.login("opensim", "widdlyscuds");
ftpClient.changeWorkingDirectory("../../var/www/avatar/Uploaded");
if (ftpClient.getReplyString().contains("250")) {
Handler progressHandler = new Handler();
ftpClient.setFileType(org.apache.commons.net.ftp.FTP.BINARY_FILE_TYPE);
BufferedInputStream buffIn = null;
buffIn = new BufferedInputStream(new FileInputStream(filepath));
ftpClient.enterLocalPassiveMode();
ProgressInputStream progressInput = new ProgressInputStream(buffIn, progressHandler);
ftpClient.storeFile(filename + extension, progressInput);
buffIn.close();
ftpClient.logout();
ftpClient.disconnect();
}
} catch (IOException e) {
}
return filename + extension;
}
}
upload media: calls ftp class
package com.cameratest;
import java.io.File;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
/**
* The Upload Menu Allows the user to select different media types to upload to
* the server
*/
public class UploadMedia extends Activity implements OnClickListener {
private File sd;
private File storageFolder;
private File mediaFolder;
private ImageButton pictureB;
private String dataType;
private String media_filepath;
private String media_filename;
private String media_extension;
private static String image_filepath;
public static Context thisContext;
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
thisContext = getApplicationContext();
setContentView(R.layout.upload_menu);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
createStorageDirectory();
pictureB = (ImageButton) findViewById(R.id.cameraButton);
pictureB.setOnClickListener(this);
}
/**
* Responds to whatever button is pressed
*
* @param View
* v - the button clicked
*/
public void onClick(View v) {
Intent i;
switch (v.getId()) {
case (R.id.cameraButton):
dataType = getResources().getString(R.string.type_picture);
i = new Intent(UploadMedia.this, Photographer.class);
startActivityForResult(i, Globals.CAMERA_REQUEST);
break;
}
}
public void onBackPressed() {
finish();
}
/**
* Called when the individual activities (picture, video, audio) finish.
*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
// super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
if (requestCode == Globals.CAMERA_REQUEST) {
media_filepath = getImage_filepath();
media_extension = "_P.png";
}
media_filename = UploadFTP.FTPUpload(media_filepath,
media_extension, thisContext);
Intent MailIntent = new Intent(getApplicationContext(),
MailSenderActivity.class);
MailIntent.putExtra("Type", dataType);
MailIntent.putExtra("Filename", media_filename);
startActivity(MailIntent);
finish();
}
}
public static void setImage_filepath(String fp) {
image_filepath = fp;
}
public String getImage_filepath() {
return image_filepath;
}
@Override
public void onDestroy() {
finish();
super.onDestroy();
}
public void createStorageDirectory() {
sd = Environment.getExternalStorageDirectory();
storageFolder = new File(sd, Globals.STORAGE_DIRECTORY);
if (sd.canWrite()) {
if (!storageFolder.exists())
storageFolder.mkdir();
mediaFolder = new File(sd, Globals.STORAGE_DIRECTORY
+ Globals.MEDIA_DIRECTORY);
if (!mediaFolder.exists())
mediaFolder.mkdir();
}
}
}
Add commons-net-3.1.jar File in the libs folder of your Application. click here
这篇关于FTP客户端noClassDefFound错误:org.apache.commons.net.ftp.FTPClient的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!