我有一个奇怪的问题,我在我的清单中声明了我的FileChooserActivity:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:name="com.lifemate.lmmessenger.LMApplication">
<activity
android:name="com.lifemate.lmmessenger.main.MessengerLOCR"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider android:name="com.lifemate.lmmessenger.database.ContactsProvider"
android:authorities="com.lifemate.lmmessenger.database.provider.contactsprov">
</provider>
<receiver android:name="Receiver" >
<intent-filter>
<action android:name="com.lifemate.lmmessenger.Receiver" />
</intent-filter>
</receiver>
<activity
android:name="com.lifemate.lmmessenger.fileviews.FileChooserActivity"
android:icon="@drawable/ic_chooser"
android:enabled="@bool/use_activity"
android:exported="true"
android:label="@string/choose_file" >
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.OPENABLE" />
<data android:mimeType="*/*" />
</intent-filter>
</activity>
</application>
我确定地址是真的,但是在运行时我收到了ClassNotFoundException,我做错了什么?
班级:
package com.lifemate.lmmessenger.fileviews;
public class FileChooserActivity extends Activity {
String path =null ;
String type = null;
ImageView iv;
private static final String TAG = "FileChooserExampleActivity";
private static final int REQUEST_CODE = 6384; // onActivityResult request
// code
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image_chooser);
iv =(ImageView)findViewById(R.id.imageViewThumb);
// Create a simple button to start the file chooser process
Button button = (Button)findViewById(R.id.buttonChooseImage);
// button.setText(R.string.choose_file);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Display the file chooser dialog
showChooser();
}
});
}
//http://www.rgagnon.com/javadetails/java-0487.html
public void SaveImage(View v){
System.out.println(path);
String Path = path;
if(path!=null){
String extension = MimeTypeMap.getFileExtensionFromUrl(path);
if (extension != null) {
MimeTypeMap mime = MimeTypeMap.getSingleton();
type = mime.getMimeTypeFromExtension(extension);
Log.i("MIME",type);
}
Intent returnIntent = new Intent();
returnIntent.putExtra("result",Path);
setResult(RESULT_OK,returnIntent);
Log.i("Image",path);
finish();
}else{
Toast.makeText(FileChooserActivity.this,"You Havent Chose any Thing Yet...",
Toast.LENGTH_LONG).show();
}
}
public void convertsize(){
File file=new File("storage/sdcard/Pictures/reza22.png");
File file2=new File("storage/sdcard/Pictures/reza2.jpg");
Bitmap bitmap = BitmapFactory.decodeFile("storage/sdcard/Pictures/reza2.jpg");
Bitmap bmpCompressed = Bitmap.createScaledBitmap(bitmap, 635,479, true);
FileOutputStream out = null;
try {
out = new FileOutputStream(file);
bmpCompressed.compress(CompressFormat.JPEG, 100, out);
} catch (Exception e) {
e.printStackTrace();
} finally {
try{
out.close();
} catch(Throwable ignore) {}
}
}
public Bitmap decodeFile(File input){
try {
//Decode image size
File file=new File("storage/sdcard/Pictures/reza22.jpg");
BitmapFactory.Options o11 = new BitmapFactory.Options();
o11.inJustDecodeBounds = true;
BitmapFactory.decodeStream(new FileInputStream(input),null,o11);
//The new size we want to scale to
final int REQUIRED_SIZE=400;
//Find the correct scale value. It should be the power of 2.
int scale=1;
while(o11.outWidth/scale/2>=REQUIRED_SIZE && o11.outHeight/scale/2>=REQUIRED_SIZE)
scale*=2;
//Decode with inSampleSize
BitmapFactory.Options o22 = new BitmapFactory.Options();
o22.inSampleSize=scale;
BitmapFactory.decodeStream(new FileInputStream(input), null, o22);
Bitmap bmpCompressed = BitmapFactory.decodeFile(input.toString(), o22);
FileOutputStream out = null;
try {
out = new FileOutputStream(file);
bmpCompressed.compress(CompressFormat.JPEG, 100, out);
} catch (Exception e) {
e.printStackTrace();
} finally {
try{
out.close();
} catch(Throwable ignore) {}
}
} catch (FileNotFoundException e) {}
return null;
}
private void showChooser() {
// Use the GET_CONTENT intent from the utility class
Intent target = FileUtils.createGetContentIntent();
// Create the chooser Intent
Intent intent = Intent.createChooser(
target, getString(R.string.chooser_title));
try {
startActivityForResult(intent, REQUEST_CODE);
} catch (ActivityNotFoundException e) {
// The reason for the existence of aFileChooser
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case REQUEST_CODE:
// If the file selection was successful
if (resultCode == RESULT_OK) {
if (data != null) {
// Get the URI of the selected file
final Uri uri = data.getData();
Log.i(TAG, "Uri = " + uri.toString());
try {
// Get the file path from the URI
final String path = FileUtils.getPath(this, uri);
this.path=path;
String extension = MimeTypeMap.getFileExtensionFromUrl(path);
if (extension != null) {
MimeTypeMap mime = MimeTypeMap.getSingleton();
type = mime.getMimeTypeFromExtension(extension);
if(type.startsWith("image")){
System.out.println("Loading Image into iv");
Picasso.with(FileChooserActivity.this).load(path).resize(40,
40).centerCrop().into(iv);
}
}
Toast.makeText(FileChooserActivity.this,
"File Selected: " + path, Toast.LENGTH_LONG).show();
} catch (Exception e) {
Log.e("FileSelectorTestActivity", "File select error", e);
}
}
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
}
这里是完整的错误:
07-01 21:35:17.779: E/AndroidRuntime(874): FATAL EXCEPTION: main
07-01 21:35:17.779: E/AndroidRuntime(874): Process: com.lifemate.lmmessenger, PID: 874
07-01 21:35:17.779: E/AndroidRuntime(874): android.content.ActivityNotFoundException:
Unable to find explicit activity class
{com.lifemate.lmmessenger/com.lifemate.lmmessenger.fileviews.FileChooserActivity};
have
you declared this activity in your AndroidManifest.xml?
07-01 21:35:17.779: E/AndroidRuntime(874): at
android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
07-01 21:35:17.779: E/AndroidRuntime(874): at
android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
07-01 21:35:17.779: E/AndroidRuntime(874): at
android.app.Activity.startActivityForResult(Activity.java:3424)
07-01 21:35:17.779: E/AndroidRuntime(874): at
android.app.Activity.startActivityForResult(Activity.java:3385)
07-01 21:35:17.779: E/AndroidRuntime(874): at
android.support.v4.app.FragmentActivity.startActivityFromFragment
(FragmentActivity.java:854 )
07-01 21:35:17.779: E/AndroidRuntime(874): at
android.support.v4.app.Fragment.startActivityForResult(Fragment.java:889)
07-01 21:35:17.779: E/AndroidRuntime(874): at
com.lifemate.lmmessenger.tabs.GamesFragment$1.onClick(GamesFragment.java:380)
答案 0 :(得分:0)
你有包裹问题。
向我们展示你的清单的开始......
应该看起来像:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.your.complete.package"
android:versionCode="104"
android:versionName="3.00.062513">
然后你的活动......
<application
android:name=".YourApp"
android:hardwareAccelerated="true"
android:label="@string/app_name"
android:icon="@drawable/icon"
android:allowBackup="true"
android:theme="@style/YourTheme">
<activity
android:name=".ui.activities.LauncherActivity"
android:label="@string/app_name"
android:theme="@style/NoActionBar">
注意活动的名称:
<强> .ui.activities.LauncherActivity 强>
^看点?
这意味着我的活动位于:
com.your.complete.package.ui.activities.LauncherActivity.java
根据您的清单和错误消息,您似乎拥有完整的路径,因此您的活动正在搜索:
com.lifemate.lmmessenger.com.lifemate.lmmessenger.fileviews.FileChooserActivity
将其更改为
.fileviews.FileChooserActivity