I m trying to write some basic junit test but I get the following:
java.lang.RuntimeException: Unable to resolve activity for: Intent { action=android.intent.action.MAIN flags=0x10000000 comp={michaels.pack.POI/michaels.pack.POI} }
at android.app.Instrumentation.startActivitySync(Instrumentation.java:447)
at android.test.InstrumentationTestCase.launchActivityWithIntent(InstrumentationTestCase.java:106)
at android.test.InstrumentationTestCase.launchActivity(InstrumentationTestCase.java:84)
at android.test.ActivityInstrumentationTestCase2.getActivity(ActivityInstrumentationTestCase2.java:87)
at michaels.pack.test.POITest.setUp(POITest.java:21)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:164)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:151)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:418)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1520)
Now the class that should be tested is called POI and its in the michaels.pack package!
My test class is:
package michaels.pack.test;
import michaels.pack.POI;
import android.test.ActivityInstrumentationTestCase2;
import android.widget.TextView;
public class POITest extends ActivityInstrumentationTestCase2<POI> {
private TextView mView;
private POI mActivity;
private String resourceString;
public POITest()
{
super("michaels.pack.POI", POI.class);
}
#Override
protected void setUp() throws Exception {
super.setUp();
mActivity = (POI)this.getActivity();
mView = (TextView) mActivity.findViewById(michaels.pack.R.id.username);
resourceString= mActivity.getString(michaels.pack.R.id.username);
}
public void testPreconditions()
{
assertNotNull(mView);
}
public void testText() {
assertEquals(resourceString,(String)mView.getText());
}
}
Can anyone see whats wrong with that?
Does it have anything to do with the fact that the project is called POIapp and my "main" class (POI)?
Just to point out that they are in fact two different projects!
Here are the manifests:
Tests manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="michaels.pack.test"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="3" />
<instrumentation android:targetPackage="michaels.pack" android:name="android.test.InstrumentationTestRunner" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<uses-library android:name="android.test.runner" />
</application>
</manifest>
Apps manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="michaels.pack" android:versionCode="1" android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name"
android:debuggable="true">
<uses-library android:name="com.google.android.maps" />
<activity android:name=".POI" android:label="#string/app_name"
android:windowSoftInputMode="adjustPan" 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=".Register" android:label="#string/app_name"
android:windowSoftInputMode="adjustPan" android:configChanges="keyboardHidden|orientation"/>
<activity android:name=".MainMenu" android:label="#string/app_name"
android:windowSoftInputMode="adjustPan" android:configChanges="keyboardHidden|orientation"/>
<activity android:name=".ManagePOIsList" android:label="#string/app_name"
android:windowSoftInputMode="adjustPan" android:configChanges="keyboardHidden|orientation"/>
<activity android:name=".MapViewClass" android:label="#string/app_name"
android:windowSoftInputMode="adjustPan" android:configChanges="keyboardHidden|orientation"/>
<activity android:name=".NewPOIForm" android:label="#string/app_name"
android:windowSoftInputMode="adjustPan" android:configChanges="keyboardHidden|orientation"/>
<activity android:name=".ShowPOIsDetails" android:label="#string/app_name"
android:windowSoftInputMode="adjustPan" android:configChanges="keyboardHidden|orientation"/>
<activity android:name=".CreatePoiCoordinates" android:label="#string/app_name"
android:windowSoftInputMode="adjustPan" android:configChanges="keyboardHidden|orientation"/>
<activity android:name=".PreferenceClass" android:label="#string/app_name"
android:windowSoftInputMode="adjustPan" android:configChanges="keyboardHidden|orientation"/>
<service android:enabled="true" android:name=".MyServiceClass" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.VIBRATE" />
Thanks in advance!
Mike
It seems to work on an actual device! For some reason it was failing in the emulator!
I guess the problem is in your manifest files, that's why in the log appears comp={michaels.pack.POI/michaels.pack.POI} and I think it should be comp={michaels.pack/michaels.pack.POI}.
You also need two different projects, one for your application and one for your tests, something that you haven't mentioned either.
Use this constructor:
public POITest()
{
super(POI.class);
}
the other is deprecated since API level 8.
My guess is that you don't have 'use mock location' set up on your emulator, but you have it set up on your device. That's why this error tends to pop up when you have the permission set in the manifest.
Related
I have just created my first Android Automotive project:
when I run AndroidAutoDemo.mobile module it works fine:
Unfortunately when I switch to AndroidAutoDemo.automotive module I get:
Could not identify launch activity: Default Activity not found
Error while Launching activity
Failed to launch an application on all devices
This is the Android Manifest file in AndroidAutoDemo.automotive module (left as default):
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.androidautodemo">
<uses-feature
android:name="android.hardware.type.automotive"
android:required="true" />
<application
android:allowBackup="true"
android:appCategory="audio"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.AndroidAutoDemo" />
</manifest>
This is my mobile emulator:
How can I fix?
To run automotive app you need Automotive emulator and Automotive flavor with Manifest like below. Also there is no Automotive emulator provided by Google yet but you can get other open source emulator from like Polestar https://developer.polestar.com/sdk/polestar2-sys-img.xml
and Volvo https://developer.volvocars.com/sdk/volvo-sys-img.xml
You don't have to add new activity
if want to understand you can go through example source code
https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:car/app/app-samples/helloworld/
`
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="androidx.car.app.sample.helloworld"
android:versionCode="1"
android:versionName="1.0">
<!-- Various required feature settings for an automotive app. -->
<uses-feature
android:name="android.hardware.type.automotive"
android:required="true" />
<uses-feature
android:name="android.software.car.templates_host"
android:required="true" />
<uses-feature
android:name="android.hardware.wifi"
android:required="false" />
<uses-feature
android:name="android.hardware.screen.portrait"
android:required="false" />
<uses-feature
android:name="android.hardware.screen.landscape"
android:required="false" />
<application
android:label="#string/app_name"
android:icon="#drawable/ic_launcher"
android:extractNativeLibs="false">
<meta-data
android:name="com.android.automotive"
android:resource="#xml/automotive_app_desc"
tools:ignore="MetadataTagInsideApplicationTag" />
<meta-data android:name="androidx.car.app.minCarApiLevel"
android:value="1"
tools:ignore="MetadataTagInsideApplicationTag" />
<service
android:name="androidx.car.app.sample.helloworld.common.HelloWorldService"
android:exported="true">
<intent-filter>
<action android:name="androidx.car.app.CarAppService" />
</intent-filter>
</service>
<activity
android:name="androidx.car.app.activity.CarAppActivity"
android:theme="#android:style/Theme.DeviceDefault.NoActionBar"
android:exported="true"
android:launchMode="singleTask"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="distractionOptimized" android:value="true"/>
</activity>
</application>
</manifest>
`
Each Manifest file should include information about available activities and launcher activity. Launcher activity needs to be defined with some additional Intent filters, for example:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.car">
<uses-permission android:name="android.car.permission.CAR_POWERTRAIN" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.DeviceDefault.NoActionBar">
<activity android:name="com.example.car.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
here is the project I got from my tutor, I got the error after running it on my test phone. I tried the answers on stackovetflow but nothing helps. The logcat and manifest.xml are as follows
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.imagerecognition"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="22" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".TakeBusinessCardActivity"
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=".HistoryActivity" android:label="拍摄历史"/>
<activity android:name=".DecodeActivity" android:label="解码"/>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
try to change your
android:name=".MainActivity"
to fully specified name
android:name="com.imagerecognition.MainActivity"
sometime eclipse act weird.
if it does not work you can try this
unable to find activity
This following method worked for me. Right click on your project and select properties. The "Properties for " panel will open. From the menu on the left go to Java Build Path -> Order and Export . From the list below uncheck the box next to Android Dependencies. Finally clean your project and run.
Reference : Link
Try removing the imports and importing them manually again.
Have a problem with an already-published application on Google Play.
The application is in the store, but no one can download, because of an error Supported devices 0.
I did refactor the project, removed all unnecessary with the manifest. Compiled a new apk, and again "Supported devices 0".
I use pdfbox-android-1.8.8.jar.
If I remove the pdfbox from project, then are "Supported devices 7700".
I build project with Eclipse.
What does this mean?
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.firm.project"
android:versionCode="3"
android:versionName="1.01" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="21"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA"/>
<application
android:name=".App"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity
android:name=".StartActivity"
android:label="#string/app_name"
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=".OneActivity" android:screenOrientation="portrait">
</activity>
</application>
</manifest>
I have copied my Manifest XML File. I am just not able to figure out the error. The application is running on my Redmi 1S but it is not running on my Micromax Canvas A110 I have already tried all the solutions which are already there on Stackoverflow related to this.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gilpix.am"
android:versionCode="1"
android:versionName="1.0" android:installLocation="auto">
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
<uses-configuration
android:reqTouchScreen="finger" android:reqKeyboardType="undefined"/>
<uses-feature
android:name="android.hardware.touchscreen" />
<uses-permission
android:name="android.permission.INTERNET" />
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true" android:xlargeScreens="true" android:resizeable="true"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" android:uiOptions="splitActionBarWhenNarrow">
<!-- Splash screen -->
<activity android:name="com.gilpix.am.Splash"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Black.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.gilpix.am.Login"
android:label="#string/app_name"
>
</activity>
<activity android:name="com.gilpix.am.Logind"
android:label="#string/logind_name"
android:uiOptions="splitActionBarWhenNarrow"
>
</activity>
<activity android:name="com.gilpix.am.U_home"
android:label="#string/app_name"
android:uiOptions="splitActionBarWhenNarrow" >
</activity>
</application>
</manifest>
clean your project and if it doesn't work than close
the project and restart, create new apk and install
This error is come due to different android version of your both android phones.
Please check the configuration for both the phones and change according to that in manifest.xml file
android:minSdkVersion="11"
android:targetSdkVersion="19"
Thanks
I am busy with an Android project with the android-support-v7-appcompat library for ActionBar, I have followed the description on Android Developer
but I have got every time NoClassDefFoundError: eu.definecontent.fazilet.HomeFragment.
I can not find where is wrong in the code or configuration, maybe you can find it, I would be glad if you could help me:
MainActivity:
public class MainActivity extends ActionBarActivity {
...
Fragment fragment = new HomeFragment();
...
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="eu.definecontent.fazilet"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" >
</uses-permission>
<application
android:name=".FaziletApplication"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat" >
<activity
android:name="eu.definecontent.fazilet.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>
<service android:name=".service.FillDailyTimetableService" />
<activity
android:name=".helper.DownloadManager"
android:theme="#android:style/Theme.Dialog" />
<activity android:name=".CitySettingActivity" />
<activity android:name=".LocationSettingActivity" />
</application>
and configuration are:
Thanks to G V have Finally fixed that!
just added a try catch statement to initialize a static class and everythings works now!
for more info plz see this article:
javareferencegv.blogspot.com