NoClassDeffoundError in spring android - android

Hi guys I am facing problrm as NoClassDeffound: org.springframework.web.client.RestTemplate.
I don't know how it will removed? Please suggest me the solution.
Error: 05-16 15:59:03.324:
ERROR/AndroidRuntime(296):
java.lang.NoClassDefFoundError:
org.springframework.web.client.RestTemplate
05-16 15:59:03.324:
ERROR/AndroidRuntime(296): at
org.shopzilla.android.parsing.SearchResult_Json.json_parse(SearchResult_Json.java:10)
05-16 15:59:03.324:
ERROR/AndroidRuntime(296): at
org.shopzilla.android.search.SearchResultActivity$1.onClick(SearchResultActivity.java:26)
05-16 15:59:03.324:
ERROR/AndroidRuntime(296): at
android.view.View.performClick(View.java:2408)
05-16 15:59:03.324:
ERROR/AndroidRuntime(296): at
android.view.View$PerformClick.run(View.java:8816)
05-16 15:59:03.324:
ERROR/AndroidRuntime(296): at
android.os.Handler.handleCallback(Handler.java:587)
05-16 15:59:03.324:
ERROR/AndroidRuntime(296): at
android.os.Handler.dispatchMessage(Handler.java:92)
05-16 15:59:03.324:
ERROR/AndroidRuntime(296): at
android.os.Looper.loop(Looper.java:123)
05-16 15:59:03.324:
ERROR/AndroidRuntime(296): at
android.app.ActivityThread.main(ActivityThread.java:4627)
05-16 15:59:03.324:
ERROR/AndroidRuntime(296): at
java.lang.reflect.Method.invokeNative(Native
Method) 05-16 15:59:03.324:
ERROR/AndroidRuntime(296): at
java.lang.reflect.Method.invoke(Method.java:521)
05-16 15:59:03.324:
ERROR/AndroidRuntime(296): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-16 15:59:03.324:
ERROR/AndroidRuntime(296): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-16 15:59:03.324:
ERROR/AndroidRuntime(296): at
dalvik.system.NativeStart.main(Native
Method)
code:
public void json_parse()
{
RestTemplate restTemplate = new RestTemplate();
String url = "http://catalog.bizrate.com/services/catalog/v1/us/product/2?publisherId=50085&placementId=1&categoryId=1&keyword=iphone+cases&start=0&results=10&sort=relevancy_desc&brandId=&attFilter=&zipCode=90291&biddedOnly=&minRelevancyScore=100&apiKey=58f536aa2fab110bbe0da501150bac1e&format=json";
String result = restTemplate.getForObject(url, String.class, "SpringSource");
System.out.println("Result:"+result);
}

The exception occurs because the RestTemplate is not included in the .apk. I have struggled with this problem for a while myself and found out that i haven't installed the m2eclipse-android-integration plugin. After installing the plugin everything worked seamlessly. I am now able to use the "Run as < Android Application" function from within Eclipse/STS.
You may have to create your project again to get this working.

Do you add your Spring jar files in libs folder correctly?
spring-android-core-1.0.0.RELEASE.jar
spring-android-rest-template-1.0.0.RELEASE.jar
If you did try this
Right click on your jar files in libs folder > BuildPath > Exclude Then Right click on your jar files in libs folder > BuildPath > Include your files again

short answer:
remove jars from build path and rename lib to libs -> done
https://jira.springsource.org/browse/ANDROID-78
http://android.foxykeep.com/dev/how-to-fix-the-classdefnotfounderror-with-adt-17

put .jars into /libs folder, so they to be included in the .apk

Related

How to upload file on google drive using my android application

I start with google drive sdk. I follows steps which describe in that post.
But I face problem in Step 3: Create and Configure an Android Project
I cant find options in my eclipse so I add plugins for google. After installation of plugins, Eclipse give errors and we now update my SDK also. So for that I update my SDK but now All projects giving me error in eclipse. I cant run any projects. So I use my old SDK back.
Now I stuck with this How to create Project for Google Drive and how to integrate it.
I need to upload file from my android application to Google Drive.
Please help me to find this.
EDIT
Now I successfully create project with error free. But when I run project it give me following errors.
12-12 11:05:08.788: E/AndroidRuntime(377): java.lang.NoClassDefFoundError: com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential
12-12 11:05:08.788: E/AndroidRuntime(377): at com.rarenoice.screen.MainActivity.onCreate(MainActivity.java:42)
12-12 11:05:08.788: E/AndroidRuntime(377): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-12 11:05:08.788: E/AndroidRuntime(377): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
12-12 11:05:08.788: E/AndroidRuntime(377): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
12-12 11:05:08.788: E/AndroidRuntime(377): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
12-12 11:05:08.788: E/AndroidRuntime(377): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
12-12 11:05:08.788: E/AndroidRuntime(377): at android.os.Handler.dispatchMessage(Handler.java:99)
12-12 11:05:08.788: E/AndroidRuntime(377): at android.os.Looper.loop(Looper.java:123)
12-12 11:05:08.788: E/AndroidRuntime(377): at android.app.ActivityThread.main(ActivityThread.java:4627)
12-12 11:05:08.788: E/AndroidRuntime(377): at java.lang.reflect.Method.invokeNative(Native Method)
12-12 11:05:08.788: E/AndroidRuntime(377): at java.lang.reflect.Method.invoke(Method.java:521)
12-12 11:05:08.788: E/AndroidRuntime(377): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-12 11:05:08.788: E/AndroidRuntime(377): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-12 11:05:08.788: E/AndroidRuntime(377): at dalvik.system.NativeStart.main(Native Method)
At Following line :-
private GoogleAccountCredential credential;
credential = GoogleAccountCredential.usingOAuth2(MainActivity.this,
DriveScopes.DRIVE);
You need to add the Google Play Services jars to your project, as explained in Step 3 of the quickstart guide you are following.
You can also watch this video where I go through all the steps to build the same quickstart application for Android: http://www.youtube.com/watch?v=Ied1CjJ0iP0

Android project working on Motodev but crashes on Eclipse

I made an android project on Motodev (which is an eclipse plugin itself). But now when I am trying to run the same project on eclipse, the emulator gives me an error the following error:
FATAL EXCEPTION: main E/AndroidRuntime(4711): java.lang.VerifyError: com.tenpearls.namecalling.Activities.SearchContactsActivity
E/AndroidRuntime(4711): at java.lang.Class.newInstanceImpl(Native Method)
E/AndroidRuntime(4711): at java.lang.Class.newInstance(Class.java:1429)
E/AndroidRuntime(4711): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
E/AndroidRuntime(4711): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
E/AndroidRuntime(4711): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
E/AndroidRuntime(4711): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
E/AndroidRuntime(4711): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
E/AndroidRuntime(4711): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(4711): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(4711): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime(4711): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(4711): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(4711): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime(4711): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime(4711): at dalvik.system.NativeStart.main(Native Method)
That can be the result when you have compiled against a different library than you are using at runtime.
A good explanation can be had here.
Another possibility is having a duplicate class in the classpath somewhere, such as in a library jar.

java.lang.VerifyError when running Android jUnit Test

I've been trying to work out why I keep getting a java.lang.VerifyError
every time I try to instantiate one of my classes in any of my jUnit tests, but am completely stumped.
I created a simple, minimal test case that exhibits this behaviour:
package com.example;
public class Foo {
private int bar;
public Foo(int b) {
bar = b;
}
public int getBar() {
return bar;
}
}
And the unit tests:
package com.example.tests;
import com.example.Foo;
import junit.framework.TestCase;
public class FooTest extends TestCase {
private Foo foo;
protected void setUp() throws Exception {
super.setUp();
}
public void testSanity() {
foo = new Foo(1);
assertTrue(true);
}
}
When the unit tests attempts to instantiate a Foo object e.g. the first line of the testSanity method, I get a java.lang.VerifyError.
The project is being built against Android 1.6. The stack trace from DDMS in Eclipse looks like this:
05-16 23:40:01.543: ERROR/AndroidRuntime(934): Uncaught handler: thread main exiting due to uncaught exception
05-16 23:40:01.563: ERROR/AndroidRuntime(934): java.lang.VerifyError: com.example.tests.FooTest
05-16 23:40:01.563: ERROR/AndroidRuntime(934): at java.lang.Class.getDeclaredConstructors(Native Method)
05-16 23:40:01.563: ERROR/AndroidRuntime(934): at java.lang.Class.getConstructor(Class.java:484)
05-16 23:40:01.563: ERROR/AndroidRuntime(934): at junit.framework.TestSuite.getTestConstructor(TestSuite.java:177)
05-16 23:40:01.563: ERROR/AndroidRuntime(934): at junit.framework.TestSuite.<init>(TestSuite.java:59)
05-16 23:40:01.563: ERROR/AndroidRuntime(934): at junit.runner.BaseTestRunner.getTest(BaseTestRunner.java:103)
05-16 23:40:01.563: ERROR/AndroidRuntime(934): at android.test.AndroidTestRunner.getTest(AndroidTestRunner.java:124)
05-16 23:40:01.563: ERROR/AndroidRuntime(934): at android.test.AndroidTestRunner.setTestClassName(AndroidTestRunner.java:52)
05-16 23:40:01.563: ERROR/AndroidRuntime(934): at android.test.suitebuilder.TestSuiteBuilder.addTestClassByName(TestSuiteBuilder.java:81)
05-16 23:40:01.563: ERROR/AndroidRuntime(934): at android.test.InstrumentationTestRunner.parseTestClass(InstrumentationTestRunner.java:375)
05-16 23:40:01.563: ERROR/AndroidRuntime(934): at android.test.InstrumentationTestRunner.parseTestClasses(InstrumentationTestRunner.java:357)
05-16 23:40:01.563: ERROR/AndroidRuntime(934): at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:325)
05-16 23:40:01.563: ERROR/AndroidRuntime(934): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3848)
05-16 23:40:01.563: ERROR/AndroidRuntime(934): at android.app.ActivityThread.access$2800(ActivityThread.java:116)
05-16 23:40:01.563: ERROR/AndroidRuntime(934): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1831)
05-16 23:40:01.563: ERROR/AndroidRuntime(934): at android.os.Handler.dispatchMessage(Handler.java:99)
05-16 23:40:01.563: ERROR/AndroidRuntime(934): at android.os.Looper.loop(Looper.java:123)
05-16 23:40:01.563: ERROR/AndroidRuntime(934): at android.app.ActivityThread.main(ActivityThread.java:4203)
05-16 23:40:01.563: ERROR/AndroidRuntime(934): at java.lang.reflect.Method.invokeNative(Native Method)
05-16 23:40:01.563: ERROR/AndroidRuntime(934): at java.lang.reflect.Method.invoke(Method.java:521)
05-16 23:40:01.563: ERROR/AndroidRuntime(934): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
05-16 23:40:01.563: ERROR/AndroidRuntime(934): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
05-16 23:40:01.563: ERROR/AndroidRuntime(934): at dalvik.system.NativeStart.main(Native Met
Any help in fixing this and getting the tests running would be much appreciated.
UPDATE
Further to fadden's answer, the VFY logcat output is as follows:
05-18 20:33:04.052: ERROR/dalvikvm(234): Could not find class 'com.example.Foo', referenced from method com.example.tests.FooTest.testSanity
05-18 20:33:04.052: WARN/dalvikvm(234): VFY: unable to resolve new-instance 5 (Lcom/example/Foo;) in Lcom/example/tests/FooTest;
05-18 20:33:04.052: WARN/dalvikvm(234): VFY: rejecting opcode 0x22 at 0x0001
05-18 20:33:04.052: WARN/dalvikvm(234): VFY: rejected Lcom/example/tests/FooTest;.testSanity ()V
05-18 20:33:04.052: WARN/dalvikvm(234): Verifier rejected class Lcom/example/tests/FooTest;
The verifier in 1.5/1.6 was pretty severe. The detailed explanation of the problem is on the lines above the exception (look for "VFY" in the logcat output).
UPDATE: looking at the logcat output, code in com.example.tests.FooTest is not able to find com.example.Foo. In Android >= 2.0 this would result in a ClassNotFoundException, but in 1.6 the verifier gets cranky and just rejects the whole class.
So the question is: why can't it find it? The first thing I'd check is to make sure both com.example.Foo and com.example.tests.FooTest appear in the same APK / classes.dex file. You can check this by examining them with "dexdump".

How to get around java.lang.UnsupportedOperationException: Can't modify environment?

I'm trying to run a sub process on Android (see this question) which requires that the PYTHONHOME environment variable be set. I tried to do so with the following code:
ProcessBuilder pbuilder = new ProcessBuilder("python/bin/python", "test.py");
pbuilder.directory(getFilesDir());
Map<String, String> env = pbuilder.environment();
env.put("PYTHONHOME", "python");
Process process = pbuilder.start();
but I get this exception:
E/AndroidRuntime(25857): FATAL EXCEPTION: main
E/AndroidRuntime(25857): java.lang.UnsupportedOperationException: Can't modify environment
E/AndroidRuntime(25857): at java.lang.SystemEnvironment.put(System.java:740)
E/AndroidRuntime(25857): at java.lang.SystemEnvironment.put(System.java:688)
E/AndroidRuntime(25857): at my code
E/AndroidRuntime(25857): at android.view.View.performClick(View.java:2408)
E/AndroidRuntime(25857): at android.view.View$PerformClick.run(View.java:8816)
E/AndroidRuntime(25857): at android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime(25857): at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime(25857): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(25857): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime(25857): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(25857): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(25857): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime(25857): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime(25857): at dalvik.system.NativeStart.main(Native Method)
Does anyone have any advice? I've tried wrapping the call to python in a shell script which exports PYTHONHOME but that didn't do the trick.
Gabe
Just recently ran into the same problem. Seems like you can't modify the ProcessBuilder's environment map on Android versions <= 2.2. The only workaround that I found was to use exec() rather than the ProcessBuilder. In your case, this would result in something along the lines of:
String[] cmdarray = {"python/bin/python", "test.py"};
String[] envp = {"PYTHONHOME=python"};
Process process = Runtime.getRuntime().exec(cmdarray, envp, getFilesDir());
Hope that helps.
C

Google Maps Api android key

I have some trouble testing my Android application which includes the google maps API. The ooficial API example worked just fine but if I copy the code into my own project it keeps saying: "The application has stopped unexpectedly". I looked up the key in the keystore several times and registered it with google. Even tried reinstalling the SDK. Does anybody know what the problem is?
Thanks in advance
05-16 14:31:11.142: ERROR/ActivityThread(662): Failed to find provider info for com.google.settings
05-16 14:31:11.150: ERROR/ActivityThread(662): Failed to find provider info for com.google.settings
05-16 14:31:12.598: ERROR/MediaPlayerService(542): Couldn't open fd for content://settings/system/notification_sound
05-16 14:31:12.624: ERROR/MediaPlayer(562): Unable to to create media player
05-16 14:31:05.098: ERROR/ActivityThread(608): Failed to find provider info for android.server.checkin
05-16 14:31:06.538: ERROR/ActivityThread(608): Failed to find provider info for android.server.checkin
05-16 14:31:06.645: ERROR/ActivityThread(608): Failed to find provider info for android.server.checkin
05-16 14:31:12.803: ERROR/AndroidRuntime(715): ERROR: thread attach failed
05-16 14:31:13.698: ERROR/ActivityThread(723): Failed to find provider info for com.google.settings
05-16 14:31:13.987: ERROR/AndroidRuntime(723): Uncaught handler: thread main exiting due to uncaught exception
Basically my code is:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//connect to server
//get current map scope
//get media within map scope + a bit
//init and show map
setContentView(R.layout.main);
//add zoom controls
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
//add menu
}
Exceptions:
05-16 15:13:05.204: ERROR/AndroidRuntime(726): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.diretto.client.smartphone.android/org.diretto.client.smartphone.android.AnDiretto}: android.view.InflateException: Binary XML file line #6: Error inflating class java.lang.reflect.Constructor
05-16 15:13:05.204: ERROR/AndroidRuntime(726): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2268)
05-16 15:13:05.204: ERROR/AndroidRuntime(726): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
05-16 15:13:05.204: ERROR/AndroidRuntime(726): at android.app.ActivityThread.access$1800(ActivityThread.java:112)
05-16 15:13:05.204: ERROR/AndroidRuntime(726): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
05-16 15:13:05.204: ERROR/AndroidRuntime(726): at android.os.Handler.dispatchMessage(Handler.java:99)
05-16 15:13:05.204: ERROR/AndroidRuntime(726): at android.os.Looper.loop(Looper.java:123)
05-16 15:13:05.204: ERROR/AndroidRuntime(726): at android.app.ActivityThread.main(ActivityThread.java:3948)
05-16 15:13:05.204: ERROR/AndroidRuntime(726): at java.lang.reflect.Method.invokeNative(Native Method)
05-16 15:13:05.204: ERROR/AndroidRuntime(726): at java.lang.reflect.Method.invoke(Method.java:521)
05-16 15:13:05.204: ERROR/AndroidRuntime(726): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
05-16 15:13:05.204: ERROR/AndroidRuntime(726): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
05-16 15:13:05.204: ERROR/AndroidRuntime(726): at dalvik.system.NativeStart.main(Native Method)
05-16 15:13:05.204: ERROR/AndroidRuntime(726): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class java.lang.reflect.Constructor
05-16 15:13:05.204: ERROR/AndroidRuntime(726): at android.view.LayoutInflater.createView(LayoutInflater.java:512)
05-16 15:13:05.204: ERROR/AndroidRuntime(726): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:564)
05-16 15:13:05.204: ERROR/AndroidRuntime(726): at android.view.LayoutInflater.rInflate(LayoutInflater.java:617)
05-16 15:13:05.204: ERROR/AndroidRuntime(726): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
05-16 15:13:05.204: ERROR/AndroidRuntime(726): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
05-16 15:13:05.204: ERROR/AndroidRuntime(726): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
05-16 15:13:05.204: ERROR/AndroidRuntime(726): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:309)
05-16 15:13:05.204: ERROR/AndroidRuntime(726): at android.app.Activity.setContentView(Activity.java:1626)
05-16 15:13:05.204: ERROR/AndroidRuntime(726): at org.diretto.client.smartphone.android.AnDiretto.onCreate(AnDiretto.java:39)
05-16 15:13:05.204: ERROR/AndroidRuntime(726): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
05-16 15:13:05.204: ERROR/AndroidRuntime(726): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
05-16 15:13:05.204: ERROR/AndroidRuntime(726): ... 11 more
05-16 15:13:05.204: ERROR/AndroidRuntime(726): Caused by: java.lang.reflect.InvocationTargetException
05-16 15:13:05.204: ERROR/AndroidRuntime(726): at com.google.android.maps.MapView.(MapView.java:237)
05-16 15:13:05.204: ERROR/AndroidRuntime(726): at java.lang.reflect.Constructor.constructNative(Native Method)
05-16 15:13:05.204: ERROR/AndroidRuntime(726): at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
05-16 15:13:05.204: ERROR/AndroidRuntime(726): at android.view.LayoutInflater.createView(LayoutInflater.java:499)
05-16 15:13:05.204: ERROR/AndroidRuntime(726): ... 21 more
05-16 15:13:05.204: ERROR/AndroidRuntime(726): Caused by: java.lang.IllegalStateException: You are only allowed to have a single MapView in a MapActivity
05-16 15:13:05.204: ERROR/AndroidRuntime(726): at com.google.android.maps.MapActivity.setupMapView(MapActivity.java:180)
05-16 15:13:05.204: ERROR/AndroidRuntime(726): at com.google.android.maps.MapView.(MapView.java:279)
05-16 15:13:05.204: ERROR/AndroidRuntime(726): at com.google.android.maps.MapView.(MapView.java:254)
05-16 15:13:05.204: ERROR/AndroidRuntime(726): ... 25 more
XML file line 6 would be:
<com.google.android.maps.MapView android:id="#+id/mapview" ...
followed by other lines of XML-parameters
First, do not answer your own question unless you are truly providing an answer. You can edit your question to add new materials, such as your longer stack trace.
Your exception is:
Caused by: java.lang.IllegalStateException: You are only allowed to have a single MapView in a MapActivity
This is because you are only allowed to have a single MapView in a MapActivity, and apparently you have two or more.
I know you are well past this issue, but I had the same issue, here are my notes about the same problem and how I was able to fix it.
You are only allowed to have a single MapView in a MapActivity
Delete a view and recreate it

Categories

Resources