Cannot Start an Activity - Android - android

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)

Related

Android Studio 0.8.0 - Unable to find explicit activity class

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>

Not finding library activities declarations in the manifest

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.

INSTALL_PARSE_FAILED_MANIFEST_MALFORMED when adding another activity

I am trying to add a second activity to my android manifest file but am receiving a INSTALL_PARSE_FAILED_MANIFEST_MALFORMED error. I have isolated the offending code to this line:
<activity android:name="com.MyPackage.Main.FacebookLoginActivity"
android:label="Facebook"></activity>
When I type it in like this
<activity android:name=".FacebookLoginActivity"
android:label="Facebook"></activity>
it works fine but when I try to start the activity via
this.startActivity(new Intent(this, FacebookLoginActivity.class));
I get an error saying cannot locate "com.MyPackage.Main/com.MyPackage.Main.FacebookLoginActivity".
Is that activity wrong in some way?
Here a portion of my manifest file:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:allowBackup="true">
<activity
android:name=".MainActivity"
android:configChanges="orientation"
android:label="#string/app_name"
android:theme="#style/Theme.NoBackground">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.MyPackage.Main.FacebookLoginActivity" android:label="Facebook"></activity>
<activity android:name="com.facebook.LoginActivity"
android:theme="#android:style/Theme.Translucent.NoTitleBar"
android:label="#string/app_name" />
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id"/>
</application>
Try changing you package declaration to com.mypackage.main.
Your class name would be com.mypackage.main.FacebookLoginActivity

searching unknown activity (java.lang.ClassNotFoundException)

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" >

Android app built in eclipse wont run on phone

I've built an app that runs fine on the emulators, and says that it installs ok on the phone. However, on trying to run it an error pops up saying 'Application is not installed on your phone'. So I tried running the app through eclipse on the phone and I got this error in the console:
[2012-05-01 12:00:02 - MAD Assignment] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.mad.assignment/.MainMenu }
[2012-05-01 12:00:02 - MAD Assignment] ActivityManager: java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.mad.assignment/.MainMenu } from null (pid=8204, uid=2000) requires null
From looking for the solution elsewhere it sounds as though it could be a problem in the manifest file, so here is mine:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mad.assignment"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
>
<activity
android:name="MainMenu"
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=".Diary"></activity>
<activity android:name=".Info"></activity>
<activity android:name=".MapMenu"></activity>
<activity android:name=".RSSMenu"></activity>
<activity android:name=".RSSFeedView"></activity>
<activity android:name=".MainMenu"></activity>
<activity android:name=".RSSDetailed"></activity>
<activity android:name=".DiarySchedule"></activity>
<activity android:name=".DiaryAddEntry"></activity>
<activity android:name=".DiaryEditEntry"></activity>
<activity android:name=".DiaryDetailed"></activity>
<activity android:name=".RSSDetailed"></activity>
<uses-library android:name="com.google.android.maps"/>
<activity android:name=".MapMain"></activity>
<activity android:name=".RSSFeedView"></activity>
<activity android:name=".MapWhatsNearPreferences"></activity>
<activity android:name=".RoutePath"></activity>
</application>
Any ideas what this security exception is pointing to? Thanks!
The java.lang.SecurityException you are seeing is because you may enter two entries pointing to same activity. Remove the second one and you should be good to go.
You may be declared the activity 2 times in the manifest with different properties, like :
<activity android:name=".MainMenu"> </activity>
and
<activity android:name=".MainMenu" android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
You should remove the unwanted one from the manifest
Set android:debuggable="true" under application.
You have an activity named
<activity android:name=".MainMenu"></activity>
Which is the Intent'ed activity from the launcher. But the activity to which you gave permission is "Mainmenu". Remove it. Add the permission and etc to the ".Mainmenu" which is blank now.
ie,
The 'activity' group should be
<activity
android:name=".MainMenu"
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=".Diary"></activity>
<activity android:name=".Info"></activity>
<activity android:name=".MapMenu"></activity>
<activity android:name=".RSSMenu"></activity>
<activity android:name=".DiarySchedule"></activity>
<activity android:name=".DiaryAddEntry"></activity>
<activity android:name=".DiaryEditEntry"></activity>
<activity android:name=".DiaryDetailed"></activity>
<activity android:name=".RSSDetailed"></activity>
<uses-library android:name="com.google.android.maps"/>
<activity android:name=".MapMain"></activity>
<activity android:name=".RSSFeedView"></activity>
<activity android:name=".MapWhatsNearPreferences"></activity>
<activity android:name=".RoutePath"></activity>
And remove the duplicates as well. Why did you add so many duplicate 'activities' ?

Categories

Resources