No activity found to handle intent while using ant - android

I was trying to using ZXing as an external library for my project.
I follow the step of this site
It runs well on Eclipse, but, the APK created by Ant
stops and show the following message in Logcat:
FATAL EXCEPTION: main
09-23 16:54:44.816: E/AndroidRuntime(7570): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.google.zxing.client.android.SCAN pkg=remote.iWatchDVR (has extras) }
09-23 16:54:44.816: E/AndroidRuntime(7570): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1580)
09-23 16:54:44.816: E/AndroidRuntime(7570): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1431)
Manifest:
<activity android:name="com.google.zxing.client.android.CaptureActivity"
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="com.google.zxing.client.android.SCAN"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
Intent:
Button qrcode = (Button) findViewById(R.id.button_qrcode);
qrcode.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.setPackage(v.getContext().getResources().getString(R.string.rootPackName));
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, REQUEST_QRCODE);
}
});
I followed the steps explained in Class not found when using zxing, but the ant build failed after I copied zxing2.1.jar into /libs
[dx]
[dx] UNEXPECTED TOP-LEVEL EXCEPTION:
[dx] com.android.dex.DexException: Multiple dex files define Lcom/google/zxing/client/android/BeepManager$1;
[dx] at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594)
[dx] at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)
[dx] at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533)
I'm confused about configuring paths or settings for Ant.

The last build error shows that com.google.zxing.client.android referenced more than twice. Check on your build.grandle file on the compile and you will see two references of zxing package

Related

Android Aviary Library Error

I am working on an Image filter application, in this I have to apply some filters like pencil sketch, crop etc. for that I am using aviary library for android but when I call startActivityForResult() application get force close. Here are the logcats:
11-23 13:31:03.290: E/AndroidRuntime(4367): FATAL EXCEPTION: main
11-23 13:31:03.290: E/AndroidRuntime(4367): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jai.imagedemo/com.aviary.android.feather.FeatherActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class android.widget.RelativeLayout
Any help in resolving this problem ?
Here is my code:
Intent newIntent = new Intent( this, FeatherActivity.class );
newIntent.setData(Uri.parse(imageFilePath));
newIntent.putExtra( Constants.EXTRA_OUTPUT_FORMAT, Bitmap.CompressFormat.JPEG.name() );
String mSessionId = StringUtils.getSha256( System.currentTimeMillis() + "pv1frfq8o76siqy" );
newIntent.putExtra( Constants.EXTRA_OUTPUT_HIRES_SESSION_ID, mSessionId );
newIntent.putExtra( Constants.EXTRA_IN_SAVE_ON_NO_CHANGES, true );
startActivityForResult( newIntent, 2 );
And here is content of Manifest (for aviary library)
<activity
android:name="com.aviary.android.feather.FeatherActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:hardwareAccelerated="true"
android:largeHeap="true"
android:process=":standalone"
android:screenOrientation="unspecified" />
<provider
android:name="com.aviary.android.feather.library.providers.FeatherContentProvider"
android:authorities="com.aviary.launcher.HiResProvider"
android:exported="false" >
</provider>
Got the solution of your answer. Just add this line in your manifest :-
android:theme="#style/AviaryTheme"
Like that :-
<activity
android:name="com.aviary.android.feather.FeatherActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:finishOnTaskLaunch="true"
android:hardwareAccelerated="true"
android:process=":standalone"
android:screenOrientation="unspecified"
android:uiOptions="splitActionBarWhenNarrow"
android:theme="#style/AviaryTheme"/>
It will resolve Binary inflate problem. You must add aviary theme.

Integrate ZXing in Android Studio

I'll start explaining all the steps I have done and in the end what is the problem.
Download ZXing-2.2 https://code.google.com/p/zxing/downloads/list
Extrac all in zxing-2.2.
Download and install Apache Ant http://www.youtube.com/watch?v=XJmndRfb1TU
With the use of Windows Commandline (Run->CMD) navigate to the extracted directory
In the commandline window - Type 'ant -f core/build.xml' press enter and let Apache work it's magic
At this moment is like Integrating the ZXing library directly into my Android application
But Wooops, "Buildfile: core\build.xml does not exists! Build failed. ok.
6. Importing ZXing - missing core/build.xml
Now yes, i have my core.jar.
Open Android Studio, File -> Import Project -> Select /android/ in /zxing-2.2/ -> Create project from existing sources -> Project name: andoid -> Source files for... all checked Next -> Libraries (cant do nothing) Next -> Modules (android checked) Next -> SDK 1.7 Next -> Finish
With Project Open -> Build -> Rebuild project
100 errors
19 warnings
File -> project Structure -> Libraries -> Add -> Java -> Select core.jar that i create before and OK -> Library 'core' will be added to the selected modules. (android) OK -> And OK in the Project Structure Dialog.
Build -> Rebuild Project
15 errors
20 warnings
All errors are error: constant expression required and
I see Error in Switch cases of ZXing project in android
I change all switchs for if elses.
0 errors
20 warnings
Ok, now continue:
File -> New project -> zxing_demo Next -> Next -> Blank Activity Next -> Finish
In new project -> File -> Import module -> Search and select /android/ OK -> Create module from existing sources Next -> Next -> Next -> Next -> Finish
Now I can see in the explorer /android/ /zging_demoProject/ and External Libraries
Now i change my code tu scan QR
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.zxing_demo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" />
<uses-feature
android:name="android.hardware.camera.autofocus"
android:required="false" />
<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.zxing_demo.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:clearTaskOnLaunch="true"
android:stateNotNeeded="true"
android:configChanges="orientation|keyboardHidden"
android:name="com.google.zxing.client.android.CaptureActivity"
android:screenOrientation="landscape"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter >
<action android:name="com.google.zxing.client.android.SCAN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
MainActivity.java
package com.example.zxing_demo;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
// Handle successful scan
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}
}
Now test, Run -> Debug
And CRASH.
Logcat
08-31 02:58:28.085 20665-20665/com.example.zxing_demo E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.zxing_demo/com.google.zxing.client.android.CaptureActivity}: java.lang.ClassNotFoundException: com.google.zxing.client.android.CaptureActivity
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1891)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
at android.app.ActivityThread.access$600(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4448)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.google.zxing.client.android.CaptureActivity
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1882)
... 11 more
I can see in AndroidManifest.xml in this line
android:name="com.google.zxing.client.android.CaptureActivity"
"CaptureActivity" in red and the error say: Cannot resolve symbol 'CaptureActivity'
File -> Project Structure -> Modules -> zxing_demo -> Dependencies -> Add -> Module dependency -> android OK -> Apply and OK
Now CaptureActivity looks good
Debug again
08-31 03:06:58.513 21740-21740/com.example.zxing_demo E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.zxing_demo/com.google.zxing.client.android.CaptureActivity}: java.lang.ClassNotFoundException: com.google.zxing.client.android.CaptureActivity
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1891)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
at android.app.ActivityThread.access$600(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4448)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.google.zxing.client.android.CaptureActivity
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1882)
... 11 more
I think I will use the application and intents, but now I want do this work, if someone now whats happen tell me please.
I was integrating ZXING into an Android application and there were no good sources for the input all over, I will give you a hint on what worked for me - because it turned out to be very easy.
There is a real handy git repository that provides the zxing android library project as an AAR archive.
https://github.com/journeyapps/zxing-android-embedded
All you have to do is add this to your build.gradle
repositories {
jcenter()
}
dependencies {
implementation 'com.journeyapps:zxing-android-embedded:3.0.2#aar'
implementation 'com.google.zxing:core:3.2.0'
}
and Gradle does all the magic to compile the code and makes it accessible in your app.
To start the Scanner afterwards, use this class/method:
From the Activity:
new IntentIntegrator(this).initiateScan(); // `this` is the current Activity
From a Fragment:
IntentIntegrator.forFragment(this).initiateScan(); // `this` is the current Fragment
// If you're using the support library, use IntentIntegrator.forSupportFragment(this) instead.
There are several customizing options:
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.setDesiredBarcodeFormats(IntentIntegrator.ONE_D_CODE_TYPES);
integrator.setPrompt("Scan a barcode");
integrator.setCameraId(0); // Use a specific camera of the device
integrator.setBeepEnabled(false);
integrator.setBarcodeImageEnabled(true);
integrator.initiateScan();
They have a sample-project and are providing several integration examples:
AnyOrientationCaptureActivity
ContinuousCaptureActivity
CustomScannerActivity
ToolbarCaptureActivity
If you already visited the link you going to see that I just copy&pasted the code from the git README. If not, go there to get some more insight and code examples.
Anybody facing the same issues, follow the simple steps:
Import the project android from downloaded zxing-master zip file using option Import project (Eclipse ADT, Gradle, etc.) and add the dollowing 2 lines of codes in your app level build.gradle file and and you are ready to run.
So simple, yahh...
dependencies {
// https://mvnrepository.com/artifact/com.google.zxing/core
compile group: 'com.google.zxing', name: 'core', version: '3.2.1'
// https://mvnrepository.com/artifact/com.google.zxing/android-core
compile group: 'com.google.zxing', name: 'android-core', version: '3.2.0'
}
You can always find latest version core and android core from below links:
https://mvnrepository.com/artifact/com.google.zxing/core/3.2.1
https://mvnrepository.com/artifact/com.google.zxing/android-core/3.2.0
UPDATE (29.05.2019)
Add these dependencies instead:
dependencies {
implementation 'com.google.zxing:core:3.4.0'
implementation 'com.google.zxing:android-core:3.3.0'
}
buttion.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
new com.google.zxing.integration.android.IntentIntegrator(Fragment.this).initiateScan();
}
});
public void onActivityResult(int requestCode, int resultCode, Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if(result != null) {
if(result.getContents() == null) {
Log.d("MainActivity", "Cancelled scan");
Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
} else {
Log.d("MainActivity", "Scanned");
Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
}
} else {
// This is important, otherwise the result will not be passed to the fragment
super.onActivityResult(requestCode, resultCode, data);
}
}
dependencies {
compile 'com.journeyapps:zxing-android-embedded:3.2.0#aar'
compile 'com.google.zxing:core:3.2.1'
compile 'com.android.support:appcompat-v7:23.1.0'
}
From version 4.x, only Android SDK 24+ is supported by default, and androidx is required.
Add the following to your build.gradle file:
repositories {
jcenter()
}
dependencies {
implementation 'com.journeyapps:zxing-android-embedded:4.1.0'
implementation 'androidx.appcompat:appcompat:1.0.2'
}
android {
buildToolsVersion '28.0.3' // Older versions may give compile errors
}
Older SDK versions
For Android SDK versions < 24, you can downgrade zxing:core to 3.3.0 or earlier for Android 14+ support:
repositories {
jcenter()
}
dependencies {
implementation('com.journeyapps:zxing-android-embedded:4.1.0') { transitive = false }
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.zxing:core:3.3.0'
}
android {
buildToolsVersion '28.0.3'
}
You'll also need this in your Android manifest:
<uses-sdk tools:overrideLibrary="com.google.zxing.client.android" />
Source : https://github.com/journeyapps/zxing-android-embedded
this tutorial help me to integrate to android studio:
http://wahidgazzah.olympe.in/integrating-zxing-in-your-android-app-as-standalone-scanner/
if down try THIS
just add to AndroidManifest.xml
<activity
android:name="com.google.zxing.client.android.CaptureActivity"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="landscape"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden" >
<intent-filter>
<action android:name="com.google.zxing.client.android.SCAN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Hope this help!.

Android use Activity in Jar - NoClassDefFoundError

I am working on creating my own Android JAR file, this JAR will contain Activities which I need to call however I keep getting a NoClassDefFound error. It is only an issue with Activities contained in the JAR, any other objects called from the external JAR work fine.
Below are the steps I have taken when creating this JAR
I created a new library project called LibraryTest, and placed one Activity in it called LibraryActivity, which has a basic layout called librarymain.xml with some random text.
I have marked this project as a library, retrieved the JAR from the bin folder, I then created new project called TestAddLibrary. I added the JAR file to the lib folder, I then added the librarymain.xml from the LibraryTest project to the layout folder of the TestAddLibrary project.
I then added the the LibraryActivity to the manifest of the new project. Manifest looks like this
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testaddlibrary"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="10" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.testaddlibrary.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="com.example.librarytest.LibraryActivity"
>
</activity>
</application>
</manifest>
Then in the main activity of the new project, I have this
package com.example.testaddlibrary;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.example.librarytest.LibraryActivity;
public class MainActivity extends Activity
{
Button but;
Context context;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context = this;
but = (Button) findViewById(R.id.butNext);
but.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v)
{
Intent i = new Intent(MainActivity.this, LibraryActivity.class);
startActivity(i);
}
});
}
}
When I click the button to launch the LibraryActivity which is stored in the JAR file, I get this error
07-10 09:20:24.798: E/AndroidRuntime(28195): FATAL EXCEPTION: main
07-10 09:20:24.798: E/AndroidRuntime(28195): java.lang.NoClassDefFoundError: com.example.librarytest.R$layout 07-10
09:20:24.798: E/AndroidRuntime(28195): at com.example.librarytest.LibraryActivity.onCreate(LibraryActivity.java:20)
07-10 09:20:24.798: E/AndroidRuntime(28195): at android.app.Activity.performCreate(Activity.java:5104) 07-10
09:20:24.798: E/AndroidRuntime(28195): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
07-10 09:20:24.798: E/AndroidRuntime(28195): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
07-10 09:20:24.798: E/AndroidRuntime(28195): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
07-10 09:20:24.798: E/AndroidRuntime(28195): at android.app.ActivityThread.access$600(ActivityThread.java:141) 07-10
09:20:24.798: E/AndroidRuntime(28195): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-10 09:20:24.798: E/AndroidRuntime(28195): at android.os.Handler.dispatchMessage(Handler.java:99) 07-10
09:20:24.798: E/AndroidRuntime(28195): at android.os.Looper.loop(Looper.java:137) 07-10 09:20:24.798:
E/AndroidRuntime(28195): at android.app.ActivityThread.main(ActivityThread.java:5041) 07-10
09:20:24.798: E/AndroidRuntime(28195): at java.lang.reflect.Method.invokeNative(Native Method) 07-10
09:20:24.798: E/AndroidRuntime(28195): at java.lang.reflect.Method.invoke(Method.java:511) 07-10 09:20:24.798:
E/AndroidRuntime(28195): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-10 09:20:24.798: E/AndroidRuntime(28195): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 07-10
09:20:24.798: E/AndroidRuntime(28195): at dalvik.system.NativeStart.main(Native Method)
I have read several questions on StackOverflow regarding this issue but nothing I have read has helped. I have the latest version of ADT Eclipse plugin, I have made sure that under Order and Export, I have ticked Android dependencies and Private Libraries.
Anyone have any idea what is causing this issue? Any help would be much appreciated!!
Edit: Forgot to mention other reason I am doing this is that I require my code to be hidden so I can share this out to other people without them seeing my code
You cannot package resources into jar files.
You can package pure java files that do not refer to any resources as jars.
In your case you need to reference the library project in your android project.
Library Projects
These projects contain shareable Android source code and resources that you can reference in Android projects. This is useful when you have common code that you want to reuse. Library projects cannot be installed onto a device, however, they are pulled into the .apk file at build time.
http://developer.android.com/tools/projects/index.html
To the question in the comment the closest resource could find
You cannot export a library project to a JAR file
A library cannot be distributed as a binary file (such as a JAR file). This will be added in a future version of the SDK Tools.
How to create jar for Android Library Project

How to call an activity in another project?

Hi I am new to android and I have created 2 projects.
Now I want to call an activity in the second project from the first project upon a button click.
The 1st project only handles login screen and when I click on the login button I need to call an activity which is present in the second project.
I searched the net but didn't find any tutorials which I understood properly.
Hi I found the following error.
01-30 08:36:47.230: E/dalvikvm(3408): Could not find class 'com.androidhive.googleplacesandmaps.MainActivity', referenced from method org.fluturasymphony.recommendation.LoginActivity$DownloadWebPageTask.doInBackground
01-30 08:36:52.587: E/AndroidRuntime(3408): FATAL EXCEPTION: AsyncTask #1
01-30 08:36:52.587: E/AndroidRuntime(3408): java.lang.RuntimeException: An error occured while executing doInBackground()
01-30 08:36:52.587: E/AndroidRuntime(3408): at android.os.AsyncTask$3.done(AsyncTask.java:299)
01-30 08:36:52.587: E/AndroidRuntime(3408): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
01-30 08:36:52.587: E/AndroidRuntime(3408): at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
01-30 08:36:52.587: E/AndroidRuntime(3408): at java.util.concurrent.FutureTask.run(FutureTask.java:239)
01-30 08:36:52.587: E/AndroidRuntime(3408): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
01-30 08:36:52.587: E/AndroidRuntime(3408): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
01-30 08:36:52.587: E/AndroidRuntime(3408): at java.lang.Thread.run(Thread.java:856)
01-30 08:36:52.587: E/AndroidRuntime(3408): Caused by: java.lang.NoClassDefFoundError: com.androidhive.googleplacesandmaps.MainActivity
01-30 08:36:52.587: E/AndroidRuntime(3408): at org.fluturasymphony.recommendation.LoginActivity$DownloadWebPageTask.doInBackground(LoginActivity.java:69)
01-30 08:36:52.587: E/AndroidRuntime(3408): at org.fluturasymphony.recommendation.LoginActivity$DownloadWebPageTask.doInBackground(LoginActivity.java:1)
01-30 08:36:52.587: E/AndroidRuntime(3408): at android.os.AsyncTask$2.call(AsyncTask.java:287)
01-30 08:36:52.587: E/AndroidRuntime(3408): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
01-30 08:36:52.587: E/AndroidRuntime(3408): ... 3 more
I have declared the manifest as this.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.fluturasymphony.recommendation"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="9"
android:targetSdkVersion="11" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application android:icon="#drawable/ic_launcher" android:label="#string/app_name">
<activity android:label="#string/app_name" 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="org.achartengine.GraphicalActivity" />
<activity android:name=".CategoryWiseSalesChartActivity" />
<activity android:name=".ProductWiseSalesChartActivity" />
<activity android:name="com.androidhive.googleplacesandmaps.MainActivity"/>
<activity android:label="#string/home_screen" android:name=".HomeActivity" android:configChanges="orientation">
</activity>
<activity android:label="#string/store_screen" android:name=".StoreActivity" android:configChanges="orientation">
</activity>
<activity android:label="#string/store_list_screen" android:name=".StoreListActivity" android:configChanges="orientation">
</activity>
<activity android:label="#string/location_screen" android:name=".StoreMapActivity" android:configChanges="orientation">
</activity>
<activity android:label="#string/recommended_products_list_screen" android:name=".RecommendedProductsListActivity" android:configChanges="orientation">
</activity>
<activity android:label="#string/category_wise_sales_screen" android:name=".CategoryWiseSalesActivity" android:configChanges="orientation">
</activity>
<activity android:label="#string/product_wise_sales_screen" android:name=".ProductWiseSalesActivity" android:configChanges="orientation">
</activity>
<uses-library android:name="com.google.android.maps" />
</application>
</manifest>
And I am calling the activity in the 2nd class like this.
Intent loginintent = new Intent("com.androidhive.googleplacesandmaps.MainActivity");
startActivity(loginintent);
Is this right??
According to Android you can handle this by making the project Library and then Define it in the manifest file and call it in what ever manner you want
for an explanation i did this as per my requirement
the activity you want to call on Button click Define it in the Manifest with its full package name and then when you call it on button click the activity of the new project will trigger
the sample to do this is following
in the manifest file of your 1st project define some thing like this
<activity
android:name="packagefull.activityname"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
</activity>
in the package name define the full path of the the activity you want to call and after the package name give the name of the activity
hope this will work for you as this worked perfect for me
Use this:
Intent i = new Intent(Intent.ACTION_MAIN);
i.setComponent(new ComponentName("app package name", "app launch activity's classname"));
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
This is really not a good way for developing any application. But still if you want to achieve this , you will have to declare an Intent Filter for the target activity in that application's Manifest file and use it as implicit intent from your login activity.
Inside project A's Manifest:
<activity android:name="com.example.android.TargetActivity">
<intent-filter>
<action android:name="com.someone.wants.to.call.me"></action>
</intent-filter>
</activity>
Inside project B's Activity:
Intent intent = new Intent("com.someone.wants.to.call.me");
startActivity(intent);
in the map project's AndroidManifest file add your custom intent filter
<!-- add custom action -->
<activity android:name="MapActivity"
android:label="#string/mapLabel"
>
<intent-filter>
<action android:name="com.example.map.show" />
</intent-filter>
</activity>
from the login button call this activity like this:
Intent intent = new Intent("com.example.map.show");
startActivity(intent);
You should be using one project for each application. If you want to split up your login from the rest of your application you could use different packages. Unless I am misunderstanding what you mean by "project"?

How to make simple android app with roboguice that injects a textView?

I'm a beginner in dependency injection and roboguice. I just want to be able to inject views and resources in my app. The problem is, I get a ClassNotFoundException when I extend my class with RoboActivity.
package tes.tes;
//imports
public class test extends RoboActivity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
Here's the stacktrace:
06-09 13:54:08.887: ERROR/AndroidRuntime(495): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{tes.tes/tes.tes.test}:java.lang.ClassNotFoundException: tes.tes.test in loader dalvik.system.PathClassLoader[/data/app/tes.tes-1.apk]
06-09 13:54:08.887: ERROR/AndroidRuntime(495): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
06-09 13:54:08.887: ERROR/AndroidRuntime(495): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
...
06-09 13:54:08.887: ERROR/AndroidRuntime(495): Caused by: java.lang.ClassNotFoundException: tes.tes.test in loader dalvik.system.PathClassLoader[/data/app/tes.tes-1.apk]
06-09 13:54:08.887: ERROR/AndroidRuntime(495): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243
...
and my manifest
coding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tes.tes"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".test"
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>
</manifest>
I think my dependencies are fine since I can see the jar files for guice, roboguice, etc..
I tried following the documentation and downloading the sample code but it was too complicated for me.
I don't know what I'm missing.
Thanks for the help.
I'm submitting a new answer because RoboGuice 2.0 has changed the way this works. Now, create an XML file in res/values/ named roboguice.xml. List your modules there, like so:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="roboguice_modules">
<item>com.example.CustomRenderModule</item>
<item>com.you.yourmodule.TexModule</item>
</string-array>
</resources>
Another example.
You're not properly extending RoboApplication. Please consider going through the complete RoboGuice installation tutorial
I followed the manual and used proper naming conventions and it worked!
although this line
#Override
protected void addApplicationModules(List<Module> modules) {
modules.add(new MyModule());
}
in MyApplication.java which extends RoboApplication has errors and says remove #Override and when I remove the #Override it says it clashes with another method located in RoboApplication. I dont know why.

Categories

Resources