Reputation: 180
I spent a very long time trying to locate the error but I can't seem to find an answer that works online. The situation is that LogCat produces this error every time I click on an option in the list: android.content.ActivityNotFoundException: Unable to find explicit activity class.
Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.capture.ProcessCapture"
android:versionCode="1"
android:versionName="1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk android:minSdkVersion="7" /><uses-permission android:name="android.permission.GET_TASKS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name">
<activity android:label="@string/app_name" android:name=".ProcessCaptureActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".FileData" android:label="@string/app_name">
</activity>
<service android:name=".BackgroundCapture" android:enabled="true" android:process=":Background" android:permission="android.permission.WAKE_LOCK" android:label="@string/app_name"></service>
<receiver android:name=".BootReceiver" android:label="@string/app_name" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
</manifest>
ProcessCaptureActivity.java (Main class):
package com.capture.ProcessCapture;
... (all the imports)
public class ProcessCaptureActivity extends ListActivity {
private File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/ProcessCapture/data");
private String accessedFile;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
onResume();
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, capturedFiles()));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// Get file name:
accessedFile = ((TextView) view).getText().toString();
Intent newIntent = new Intent(view.getContext(), FileData.class);
newIntent.putExtra("filename", accessedFile);
startActivity(newIntent);
}
});
}
public void onResume() {
super.onResume();
//Timeout for 30min (Using AlarmManager)
Intent myIntent = new Intent(this, BackgroundCapture.class);
PendingIntent pendingIntent = PendingIntent.getService(this, 0, myIntent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.cancel(pendingIntent);
alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, 0, AlarmManager.INTERVAL_HALF_HOUR, pendingIntent);
}
private String[] capturedFiles() {
return dir.list();
}
}
FileData.java
package com.capture.ProcessCapture;
... (all the imports)
public class FileData extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
File sdcard = Environment.getExternalStorageDirectory();
Bundle bundle = this.getIntent().getExtras();
String filename = bundle.getString("filename");
File file = new File(sdcard+"/ProcessCapture/data", filename);
StringBuilder text = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while((line = br.readLine()) != null) {
text.append(line);
text.append('\n');
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
TextView tv = (TextView) findViewById(R.id.file_data);
tv.setText(text);
setContentView(R.layout.file_data);
}
}
Full LogCat: (Which only shows error when a list item is clicked)
11-05 10:45:28.743: E/AndroidRuntime(907): FATAL EXCEPTION: main
11-05 10:45:28.743: E/AndroidRuntime(907): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.capture.ProcessCapture/com.capture.ProcessCapture.FileData}; have you declared this activity in your AndroidManifest.xml?
11-05 10:45:28.743: E/AndroidRuntime(907): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
11-05 10:45:28.743: E/AndroidRuntime(907): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
11-05 10:45:28.743: E/AndroidRuntime(907): at android.app.Activity.startActivityForResult(Activity.java:2827)
11-05 10:45:28.743: E/AndroidRuntime(907): at android.app.Activity.startActivity(Activity.java:2933)
11-05 10:45:28.743: E/AndroidRuntime(907): at com.capture.ProcessCapture.ProcessCaptureActivity$1.onItemClick(ProcessCaptureActivity.java:37)
11-05 10:45:28.743: E/AndroidRuntime(907): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
11-05 10:45:28.743: E/AndroidRuntime(907): at android.widget.ListView.performItemClick(ListView.java:3513)
11-05 10:45:28.743: E/AndroidRuntime(907): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1812)
11-05 10:45:28.743: E/AndroidRuntime(907): at android.os.Handler.handleCallback(Handler.java:587)
11-05 10:45:28.743: E/AndroidRuntime(907): at android.os.Handler.dispatchMessage(Handler.java:92)
11-05 10:45:28.743: E/AndroidRuntime(907): at android.os.Looper.loop(Looper.java:123)
11-05 10:45:28.743: E/AndroidRuntime(907): at android.app.ActivityThread.main(ActivityThread.java:3683)
11-05 10:45:28.743: E/AndroidRuntime(907): at java.lang.reflect.Method.invokeNative(Native Method)
11-05 10:45:28.743: E/AndroidRuntime(907): at java.lang.reflect.Method.invoke(Method.java:507)
11-05 10:45:28.743: E/AndroidRuntime(907): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-05 10:45:28.743: E/AndroidRuntime(907): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-05 10:45:28.743: E/AndroidRuntime(907): at dalvik.system.NativeStart.main(Native Method)
Thanks in advance! Sorry for the long question =)
Upvotes: 3
Views: 740
Reputation: 180
(Copy from my comment above) The problem was 'solved' when I used ubuntu instead of windows =/ The root problem was in FileData.java, where the setContentView(R.layout.file_data) had to be called before setting text to it's TextView (tv).
The new code for FileData.java is:
package com.capture.ProcessCapture;
... (all the imports)
public class FileData extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
File sdcard = Environment.getExternalStorageDirectory();
Bundle bundle = this.getIntent().getExtras();
String filename = bundle.getString("filename");
File file = new File(sdcard+"/ProcessCapture/data", filename);
StringBuilder text = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while((line = br.readLine()) != null) {
text.append(line);
text.append('\n');
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
setContentView(R.layout.file_data);
TextView tv = (TextView) findViewById(R.id.file_data);
tv.setText(text);
}
}
Upvotes: 1
Reputation: 4958
Please have a look at this question and the first answer, which suggests putting a try/catch block around the code that tries to start the activity, as sometimes it's not actually that the activity is indeed undeclared but another underlying problem.
If that doesn't work, you can always try cleaning and rebuilding the project, then getting Eclipse to resync (right-click on project, "Android Tools" -> "Fix Project Properties").
Upvotes: 0