I've got a problem trying to do something in android studio and i'm not getting any progress.
When I try to call a the activity Menu from Main Activity Android studio give me this error message:
31490-31515/com.example.agr.companion E/AndroidRuntime﹕ FATAL EXCEPTION: Thread-48434
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.agr.companion/android.view.Menu}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1556)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1431)
at android.app.Activity.startActivityForResult(Activity.java:3390)
at android.app.Activity.startActivityForResult(Activity.java:3351)
at android.app.Activity.startActivity(Activity.java:3561)
at android.app.Activity.startActivity(Activity.java:3529)
at com.example.agr.companion.MyActivity$1.run(MyActivity.java:26)
This is my manifest:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MyActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Menu"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation" >
</activity>
</application>
</manifest>
And this is how I try to start the new activity:
Intent intent = new Intent(getApplicationContext(), Menu.class);
finish();
startActivity(intent);
I'm very lost, I tried lots of things but I don't find anything helpful. I've made other projects in android studio that have the same code and it work. Recently I upgrade to android studio 0.8.0 and maybe something changes...
Thanks in advance for your help
Your problem is that you try to start the view.Menu class as an activity, probably due to a false import. Take a look at the exception. It states com.example.agr.companion/android.view.Menu.
If you don't use a menu view in your activity, I would remove the false import at the top and add the correct one (of your com.example.agr.companion.Menu activity).
Another option is to rename your Menu.java activity to MenuActivity.java in order to avoid confusion.
The third option is to use:
Intent intent = new Intent(getApplicationContext(), com.example.agr.companion.Menu.class);
Try
<activity
android:name="com.example.agr.companion.MyActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Related
My Android Studio is autocompleting my code and it's going wrong.
What I'm trying to do is:
Intent intent = new Intent(getActivity(), DetailActivity.class);
startActivity(intent);
But it aways becomes:
Intent intent = new Intent(getActivity(), com.example.android.sunshine.app.DetailActivity.class);
startActivity(intent);
And there's an error on the word "sunshine" that make it get red.
If I try to build I get this:
Error:(97, 87) error: cannot find symbol class app<br>
I already saw other codes and they all work fine with the first code. What should I do?
Here is my AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="app.com.example.android.sunshine" >
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".DetailActivity"
android:label="#string/title_activity_detail"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="app.com.example.android.sunshine.MainActivity" />
</activity>
</application>
The Activity name (DetailActivity) in this line, is also red:
android:name=".DetailActivity"
In your second activity <meta-data> you have
android:value="app.com.example.android.sunshine.MainActivity"
Should probably be
android:value="com.example.android.sunshine.app.MainActivity"
And if the red marking on the sunshine word bothers you, hover your cursor over it and see what the Studio complains about -- probably just suspecting you misspelled sun shine (which you obviously didn't)
I renamed my MainActivity class to DataActivity and added a new main activity class with IntelliJ IDEA. I changed the AndroidManifest.xml file to the following:
<application android:label="#string/app_name" android:icon="#drawable/icon">
<activity android:name=".DataActivity"
android:screenOrientation="portrait">
</activity>
<activity android:name=".MainActivity" android:screenOrientation="portrait"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
I uninstalled the app from my phone and deleted the compiler cache. At install, I get the following exception:
Launching application:
com.example.DataTest/com.example.DataTest.DataActivity.
DEVICE SHELL COMMAND: am start -n
"com.example.DataTest/com.example.DataTest.DataActivity"
-a android.intent.action.MAIN -c android.intent.category.LAUNCHER java.lang.SecurityException: Permission Denial: starting Intent {
act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER]
flg=0x10000000 cmp=com.example.DataTest/.DataActivity }
from null (pid=5882, uid=2000) requires null
What else should I do?
This post helped me where to look. In the comments, zeh claims that the SDK holds a refence to the original activity. I checked the launch configuration, and in my IDEA it has been altered from "Launch default activity" to "Launch activity: DataActivity".
It works now okay.
Change it to this to include the intent filters with your new main activity:
<activity android:name=".DataActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".MainActivity" android:screenOrientation="portrait"
android:label="#string/app_name">
</activity>
and remove "MainActivity" if it no longer exists. i.e. delete this:
<activity android:name=".MainActivity" android:screenOrientation="portrait"
android:label="#string/app_name">
</activity>
I have some project as a library named LibProj. It has a lot of activities that I want to use in MainProj project but I'm getting Activity Not Found error.
I have done these steps.
one of them is shown below.
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setComponent(new ComponentName("packagename//ex-com.hello",
"classname//ex-com.hello.ExampleActivity"));
startActivity(intent);
Second one is to add all activities' declarations in manifest of my MainProj project.
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.doocat.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activity.main.IntroActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
</activity>
<activity
android:name=".activity.main.LoginActivity"
android:screenOrientation="portrait"
android:label="#string/app_name" />
<activity
etc...
Both of these ways not working. What I'm doing wrong or what is the solution?
Register Your Library Activity in MainProject manifest file..
I have given action name in intent-filter
com.lib.Example to identify which Activity need to call.
<activity
android:name="YOUR_LIBRARY_ACTIVITY_PACKAGE. ExampleActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.lib.Example" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Now call this Activity from your MainProject
Intent intent = new Intent("com.lib.Example");
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
}
Hope This help you.
Hi I have an activity defined in my Library like so...
<activity
android:name="com.company.application.corelibrary.recording.DesiredActivity"
android:label="#string/title_activity_tracking"
android:screenOrientation="portrait"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I then want to use this library to launch with in another application which I am doing like so...
<activity
android:name="com.company.application.corelibrary.recording.DesiredActivity"
android:label="#string/title_activity_tracking"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
However when I am going to build it it comes back with...
[2013-02-27 12:41:33 - TestApplication] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.company.application/.corelibrary.recording.DesiredActivity }
[2013-02-27 12:41:33 - TestApplication] ActivityManager: Error type 3
[2013-02-27 12:41:33 - TestApplication] ActivityManager: Error: Activity class {com.company.application/com.company.application.corelibrary.recording.DesiredActivity} does not exist.
com.company.application is my project package.
com.company.application.corelibrary is my library package.
I have included the library in my project.
What am I doing wrong?
ADDITION
I just renamed my library project's package name to something different than that of my project as I thought maybe as they were similar the project may look in it own source for the class but this did not work either.
in my application, i have wrote activity in manifest like:
<activity android:name="MainActivity"
android:label="#string/app_name"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
i have also declare another activity (which activity belongs to my library) in the manifest as:
<activity android:name="com.facebook.LoginActivity"
android:label="#string/app_name" />
hope this will help u.
N.B:
u should not use
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
for two activity in a manifest.
I thought I would answer my own question. The other answers may be valid but this is what solved mine.
Before my activity declaration in the new projects manifest I had the following which was causing issues.
<uses-library
android:name="com.corecoders.st.corelibrary"
android:required="true" />
I removed that, cleaned and rebuilt the project and it launched fine.
I have solved this issue by implemeting he solution io.card does in their library. By wrapping with the application tags the activities into your library manifest.
<application>
<activity
android:name="com.eckoh.eckohroute.ActionConsumingActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:theme="#style/Theme.Dialog.ActionActivity" />
</application>
help me to resolve this getting this exception
java.lang.RuntimeException: Unable to instantiate application delhi.roshanara.margapp.MargApp: java.lang.ClassNotFoundException: delhi.roshanara.margapp.MargApp in loader dalvik.system.PathClassLoader[/data/app/delhi.roshanara.margapp-2.apk]
It is searching MargApp Activity to open the project but there is no activity of this name. And I want to start my activity as .LoginActivity. Manifest file structure is given below:-
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:name="MargApp" >
<activity
android:name=".LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".OrderMenuPage" />
<activity
android:name=".PartyOutstanding" />
<activity
android:name=".PartyPDC" />
<activity
android:name=".TakeOrder"></activity>
<activity
android:name=".ShowOutstanding"
android:screenOrientation="landscape" />
<activity
android:name=".ShowPDC"
android:screenOrientation="landscape"></activity>
</application>
I would try removing
android:name="MargApp"
if that didn't work try Cleaning up your project
Project>Clean
Do not use the android:name attribute! It, misleadingly, does not have anything to do with the name of your app and is actually the name of an extra class to load before loading your application. That's why you are getting the ClassNotFoundException. Remove it and it should work:
Replace your application tag with this one...
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >