Strange force closing - android

I have an app which works perfectly on my Galaxy Nexus, but when i run it on the emulator (only on some setups, one is tablet with JB and the other is ldpi with android 2.1) it crashes.
The logcat looks like this
03-29 16:26:16.842: D/AndroidRuntime(526): Shutting down VM
03-29 16:26:16.842: W/dalvikvm(526): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
03-29 16:26:16.842: E/AndroidRuntime(526): Uncaught handler: thread main exiting due to uncaught exception
03-29 16:26:16.862: E/AndroidRuntime(526): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.doublep.wakey/com.doublep.wakey.Bulb}: java.lang.NullPointerException
03-29 16:26:16.862: E/AndroidRuntime(526): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
03-29 16:26:16.862: E/AndroidRuntime(526): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
03-29 16:26:16.862: E/AndroidRuntime(526): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
03-29 16:26:16.862: E/AndroidRuntime(526): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
03-29 16:26:16.862: E/AndroidRuntime(526): at android.os.Handler.dispatchMessage(Handler.java:99)
03-29 16:26:16.862: E/AndroidRuntime(526): at android.os.Looper.loop(Looper.java:123)
03-29 16:26:16.862: E/AndroidRuntime(526): at android.app.ActivityThread.main(ActivityThread.java:4363)
03-29 16:26:16.862: E/AndroidRuntime(526): at java.lang.reflect.Method.invokeNative(Native Method)
03-29 16:26:16.862: E/AndroidRuntime(526): at java.lang.reflect.Method.invoke(Method.java:521)
03-29 16:26:16.862: E/AndroidRuntime(526): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
03-29 16:26:16.862: E/AndroidRuntime(526): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
03-29 16:26:16.862: E/AndroidRuntime(526): at dalvik.system.NativeStart.main(Native Method)
03-29 16:26:16.862: E/AndroidRuntime(526): Caused by: java.lang.NullPointerException
03-29 16:26:16.862: E/AndroidRuntime(526): at com.doublep.wakey.Bulb.onCreate(Bulb.java:465)
03-29 16:26:16.862: E/AndroidRuntime(526): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-29 16:26:16.862: E/AndroidRuntime(526): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
03-29 16:26:16.862: E/AndroidRuntime(526): ... 11 more
03-29 16:26:16.882: I/dalvikvm(526): threadid=7: reacting to signal 3
03-29 16:26:16.882: E/dalvikvm(526): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
03-29 16:26:18.752: I/Process(526): Sending signal. PID: 526 SIG: 9
I've discovered that if i comment out a button the problem goes away (this was an imageButton before, but i converted it to button, as imageButton it was working fine)
//This is a global variable declariation
Button premiumFeaturesBtn;
//this is inside the oncreate
premiumFeaturesBtn = (Button) findViewById(R.id.btn_premium_features);
//this is inside a thread
premiumFeaturesBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent premiumPurchase = new Intent(Bulb.this, PremiumPurchase.class);
startActivity(premiumPurchase);
}
});
//This is at the end of my onCreate
Typeface bebas = Typeface.createFromAsset(getAssets(), "fonts/bebas_neue.otf");
premiumFeaturesBtn.setTypeface(bebas);
After commenting out the above lines everything works fine
This is the xml of the button
<Button
android:id="#+id/btn_premium_features"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:background="#drawable/img_btn_premium"
android:padding="10dp"
android:text="#string/premium_features"
android:textSize="25sp" />
Can you spot something i did wrong?
I think the problem is in this line
premiumFeaturesBtn = (Button) findViewById(R.id.btn_premium_features);
Because before i was getting sometimes the error saying that i can't cast Button on ImageButton
But obviously i am not

The different behavior on various devices can result in using different layouts being defined for screen sizes, orientations, and so on.
Check if the button identifier (android:id="#+id/btn_premium_features") is defined in all of your applicable layouts.
This would explain why it runs on certain devices and doesn't on others.

//this is inside a thread
premiumFeaturesBtn.setOnClickListener(new View.OnClickListener() {
It shouldn't be inside any other than than main / UI thread where onCreate is executing.

Related

Null Pointer Exception in First Android App

I am trying to write my first Android app, and I'm having trouble. I wrote a simple Java program to find the factors of a number provided by the user, and I'd like to port it over to Java. I have an XML file for the interface, which seemed to run OK until I added the first Java class. Now it won't run, and log.cat says that there's a null pointer exception. So far, I only have stubs, but it seems like it should run OK with what I've done to this point. I'm including the log.cat text, but I'm too new it this to make much sense out of it.
There may be more than one problem. After adding the Java file I began to get run-time errors right away, but I don't think they were null pointer exceptions. I think that started when I made changes to fix what was already causing problems.
Any help is appreciated.
Here is the Java file:
import android.app.Activity; <br>
import android.os.Bundle; <br>
import android.widget.Button; <br>
import android.widget.EditText; <br>
import android.widget.TextView; <br>
public class AndroidFactoringActivity extends Activity {
// Instance Variables
EditText userNumber;
Button factorButton;
TextView resultsField;
int factorResults;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
factorButton = (Button) findViewById(R.id.factorButton);
userNumber = (EditText) findViewById(R.id.userNumber);
factorResults = 1;
resultsField.setText(String.valueOf(factorResults));
}
}
Here is main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/askField"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/ask"
android:textSize="24dp" />
<EditText
android:id="#+id/userNumber"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number" >
<requestFocus />
</EditText>
<Button
android:id="#+id/factorButton"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/click" />
<TextView
android:id="#+id/resultsField"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/tell"
android:textSize="24dp" />
</LinearLayout>
Here are the log.cat results:
03-31 23:58:53.579: D/AndroidRuntime(2804): Shutting down VM
03-31 23:58:53.589: W/dalvikvm(2804): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
03-31 23:58:53.589: E/AndroidRuntime(2804): Uncaught handler: thread main exiting due to uncaught exception
03-31 23:58:53.650: E/AndroidRuntime(2804): java.lang.RuntimeException: Unable to start activity ComponentInfo{net.dave_b.factoring/net.dave_b.factoring.AndroidFactoringActivity}: java.lang.NullPointerException
03-31 23:58:53.650: E/AndroidRuntime(2804): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
03-31 23:58:53.650: E/AndroidRuntime(2804): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
03-31 23:58:53.650: E/AndroidRuntime(2804): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
03-31 23:58:53.650: E/AndroidRuntime(2804): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
03-31 23:58:53.650: E/AndroidRuntime(2804): at android.os.Handler.dispatchMessage(Handler.java:99)
03-31 23:58:53.650: E/AndroidRuntime(2804): at android.os.Looper.loop(Looper.java:123)
03-31 23:58:53.650: E/AndroidRuntime(2804): at android.app.ActivityThread.main(ActivityThread.java:4363)
03-31 23:58:53.650: E/AndroidRuntime(2804): at java.lang.reflect.Method.invokeNative(Native Method)
03-31 23:58:53.650: E/AndroidRuntime(2804): at java.lang.reflect.Method.invoke(Method.java:521)
03-31 23:58:53.650: E/AndroidRuntime(2804): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
03-31 23:58:53.650: E/AndroidRuntime(2804): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
03-31 23:58:53.650: E/AndroidRuntime(2804): at dalvik.system.NativeStart.main(Native Method)
03-31 23:58:53.650: E/AndroidRuntime(2804): Caused by: java.lang.NullPointerException
03-31 23:58:53.650: E/AndroidRuntime(2804): at net.dave_b.factoring.AndroidFactoringActivity.onCreate(AndroidFactoringActivity.java:26)
03-31 23:58:53.650: E/AndroidRuntime(2804): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-31 23:58:53.650: E/AndroidRuntime(2804): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
03-31 23:58:53.650: E/AndroidRuntime(2804): ... 11 more
03-31 23:58:53.679: I/dalvikvm(2804): threadid=7: reacting to signal 3
03-31 23:58:53.679: E/dalvikvm(2804): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
03-31 23:59:57.629: I/Process(2804): Sending signal. PID: 2804 SIG: 9
04-01 00:07:36.129: D/AndroidRuntime(3040): Shutting down VM
04-01 00:07:36.129: W/dalvikvm(3040): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
04-01 00:07:36.139: E/AndroidRuntime(3040): Uncaught handler: thread main exiting due to uncaught exception
04-01 00:07:36.159: E/AndroidRuntime(3040): java.lang.RuntimeException: Unable to start activity ComponentInfo{net.dave_b.factoring/net.dave_b.factoring.AndroidFactoringActivity}: java.lang.NullPointerException
04-01 00:07:36.159: E/AndroidRuntime(3040): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
04-01 00:07:36.159: E/AndroidRuntime(3040): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
04-01 00:07:36.159: E/AndroidRuntime(3040): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
04-01 00:07:36.159: E/AndroidRuntime(3040): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
04-01 00:07:36.159: E/AndroidRuntime(3040): at android.os.Handler.dispatchMessage(Handler.java:99)
04-01 00:07:36.159: E/AndroidRuntime(3040): at android.os.Looper.loop(Looper.java:123)
04-01 00:07:36.159: E/AndroidRuntime(3040): at android.app.ActivityThread.main(ActivityThread.java:4363)
04-01 00:07:36.159: E/AndroidRuntime(3040): at java.lang.reflect.Method.invokeNative(Native Method)
04-01 00:07:36.159: E/AndroidRuntime(3040): at java.lang.reflect.Method.invoke(Method.java:521)
04-01 00:07:36.159: E/AndroidRuntime(3040): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-01 00:07:36.159: E/AndroidRuntime(3040): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-01 00:07:36.159: E/AndroidRuntime(3040): at dalvik.system.NativeStart.main(Native Method)
04-01 00:07:36.159: E/AndroidRuntime(3040): Caused by: java.lang.NullPointerException
04-01 00:07:36.159: E/AndroidRuntime(3040): at net.dave_b.factoring.AndroidFactoringActivity.onCreate(AndroidFactoringActivity.java:26)
04-01 00:07:36.159: E/AndroidRuntime(3040): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-01 00:07:36.159: E/AndroidRuntime(3040): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
04-01 00:07:36.159: E/AndroidRuntime(3040): ... 11 more
04-01 00:07:36.199: I/dalvikvm(3040): threadid=7: reacting to signal 3
04-01 00:07:36.199: E/dalvikvm(3040): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
04-01 00:07:40.329: I/Process(3040): Sending signal. PID: 3040 SIG: 9
resultsField.setText(String.valueOf(factorResults));
resultsField is null and you are trying to set value on null.
resultsField= (TextView ) findViewById(R.id.userNumber);
Get textview instance before setting value, otherwise resultsField will be null and all operations on null reference results in NullPointerException.
You got a null pointer because you didnt intialise the variable resultsField (you just declared it) .
As you used
userNumber = (EditText) findViewById(R.id.userNumber);
you must even initialise the reference resultsField.
This can be done using
resultsField= (TextView ) findViewById(R.id.resultsField);
in the onCreate() after the statement setContentView()
You need to initialize the userNumer and resultsFiled as follows
userNumber = (EditText) findViewById(R.id.userNumber);
resultsField= (TextView ) findViewById(R.id.resultsField);

Android and slf4j : "java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory"

Two days ago, when my android project in eclipse still worked, I added "android SDK 4.0.3" to my SDKs (in addition to android SDK 2.1).
From that moment on, I have a trouble with slf4j-android library; here's the exception:
Uncaught handler: thread main exiting due to uncaught exception
java.lang.ExceptionInInitializerError
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1479)
at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2409)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
at android.app.ActivityThread.access$2200(ActivityThread.java:119)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4363)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory
at it.cefriel.swa.urbanopoly.client.game.UrbanopolyActivity.<clinit>(UrbanopolyActivity.java:11)
The JAR I use is slf4j-android-1.5.8.jar. The build path seems correctly setted. I also tried to create another project using slf4j and I got the same error..
Any Ideas?
Thanks in advance
Try adding the slf4j-api-1.5.8.jar or latest version as well with the current slf4j-android-1.5.8.jar

Android, class not found from imported jar file

I included a jar file in my Android project as explained in How can I use external JARs in an Android project?. With both methods described by MannyNS and Vinayak B. in this post I get the error "Could not find class 'test.libraryCalc.Calc" which is the class provided by the library. The following code illustrates the problem:
Example class provided via library: Calc.java
package test.libraryCalc;
public class Calc {
public int add(int a, int b){
return a + b;
}
}
LibraryTestActivity.java
package test.library;
import test.libraryCalc.Calc;
import android.app.Activity;
import android.os.Bundle;
public class LibraryTestActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Calc calc = new Calc();
int c = calc.add(3, 4);
}
}
I exported the jar file containing Calc.java to LibraryTest\libs\calc.jar
and added a reference to it using the "Add JARs..." button in the Java Build Path of LibraryTest
The library shows up in the Referenced libraries in LibraryTest
LibraryTest has no build problems but when running it on the emulator the following is shown in LogCat:
12-27 14:01:33.965: E/dalvikvm(747): Could not find class 'test.libraryCalc.Calc', referenced from method test.library.LibraryTestActivity.onCreate
12-27 14:01:33.965: W/dalvikvm(747): VFY: unable to resolve new-instance 13 (Ltest/libraryCalc/Calc;) in Ltest/library/LibraryTestActivity;
12-27 14:01:33.995: D/dalvikvm(747): VFY: replacing opcode 0x22 at 0x0008
12-27 14:01:33.995: D/dalvikvm(747): VFY: dead code 0x000a-0013 in Ltest/library/LibraryTestActivity;.onCreate (Landroid/os/Bundle;)V
12-27 14:01:34.065: D/AndroidRuntime(747): Shutting down VM
12-27 14:01:34.065: W/dalvikvm(747): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
12-27 14:01:34.075: E/AndroidRuntime(747): FATAL EXCEPTION: main
12-27 14:01:34.075: E/AndroidRuntime(747): java.lang.NoClassDefFoundError: test.libraryCalc.Calc
12-27 14:01:34.075: E/AndroidRuntime(747): at test.library.LibraryTestActivity.onCreate(LibraryTestActivity.java:14)
12-27 14:01:34.075: E/AndroidRuntime(747): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-27 14:01:34.075: E/AndroidRuntime(747): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
12-27 14:01:34.075: E/AndroidRuntime(747): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
12-27 14:01:34.075: E/AndroidRuntime(747): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
12-27 14:01:34.075: E/AndroidRuntime(747): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
12-27 14:01:34.075: E/AndroidRuntime(747): at android.os.Handler.dispatchMessage(Handler.java:99)
12-27 14:01:34.075: E/AndroidRuntime(747): at android.os.Looper.loop(Looper.java:123)
12-27 14:01:34.075: E/AndroidRuntime(747): at android.app.ActivityThread.main(ActivityThread.java:4627)
12-27 14:01:34.075: E/AndroidRuntime(747): at java.lang.reflect.Method.invokeNative(Native Method)
12-27 14:01:34.075: E/AndroidRuntime(747): at java.lang.reflect.Method.invoke(Method.java:521)
12-27 14:01:34.075: E/AndroidRuntime(747): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-27 14:01:34.075: E/AndroidRuntime(747): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-27 14:01:34.075: E/AndroidRuntime(747): at dalvik.system.NativeStart.main(Native Method)
12-27 14:06:34.170: I/Process(747): Sending signal. PID: 747 SIG: 9
What needs to be done to get this working? Thanks for all suggestions.
I think that the problem is that you try to add jar that contains Android code. You cannot do this. To include Android code you should create Android library. Simply create an Android project and in the project-properties Android section set that this is library project. After that you'll be able to add this library to your projects. For more about Android libraries you can read here.
Update: I've tried your code now. It works in my case. The only difference that I've made is during export of Jar I've checked Export Java source files and resources. Hope this will help you. Try it!

Google Contacts Data API on Android not working?

I try to use Google Contacts Data API on Android and more specifically the ContactsService class but the application crash as soon as I try to instantiate ContactsService class.
I do not have this problem with a normal Java application.
For example, below code is working fine
public class TestJava {
public static void main(String[] args) {
ContactsService myService = new ContactsService("TestApp");
System.out.println("OK");
}
}
However, below Android app crashes (I put the permission for Internet in the manifest)
public class TestAndroidActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ContactsService myService = new ContactsService("TestApp");
System.out.println("OK");
}
}
Does anyone know if Google Contacts Data API is working on Android?
Did I miss a permission in the manifest?
Thanks in advance.
Edit:
I used two projects in Eclipse to test above code: a Java project and an Android project.
Both projects share the same libraries and only the Android project is crashing.
Here the error message:
09-10 12:12:43.928: INFO/AndroidRuntime(326): NOTE: attach of thread 'Binder Thread #3' failed
09-10 12:12:44.409: WARN/dalvikvm(332): Unable to resolve superclass of Lcom/google/gdata/client/contacts/ContactsService; (1133)
09-10 12:12:44.459: WARN/dalvikvm(332): Link of class 'Lcom/google/gdata/client/contacts/ContactsService;' failed
09-10 12:12:44.459: ERROR/dalvikvm(332): Could not find class 'com.google.gdata.client.contacts.ContactsService', referenced from method test34.pkg.Tests34Activity.onCreate
09-10 12:12:44.469: WARN/dalvikvm(332): VFY: unable to resolve new-instance 1142 (Lcom/google/gdata/client/contacts/ContactsService;) in Ltest34/pkg/Tests34Activity;
09-10 12:12:44.469: DEBUG/dalvikvm(332): VFY: replacing opcode 0x22 at 0x0008
09-10 12:12:44.469: DEBUG/dalvikvm(332): VFY: dead code 0x000a-0016 in Ltest34/pkg/Tests34Activity;.onCreate (Landroid/os/Bundle;)V
09-10 12:12:44.609: DEBUG/AndroidRuntime(332): Shutting down VM
09-10 12:12:44.609: WARN/dalvikvm(332): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): FATAL EXCEPTION: main
09-10 12:12:44.639: ERROR/AndroidRuntime(332): java.lang.NoClassDefFoundError: com.google.gdata.client.contacts.ContactsService
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at test34.pkg.Tests34Activity.onCreate(Tests34Activity.java:15)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at android.os.Handler.dispatchMessage(Handler.java:99)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at android.os.Looper.loop(Looper.java:123)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at android.app.ActivityThread.main(ActivityThread.java:4627)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at java.lang.reflect.Method.invokeNative(Native Method)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at java.lang.reflect.Method.invoke(Method.java:521)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at dalvik.system.NativeStart.main(Native Method)
09-10 12:12:44.659: WARN/ActivityManager(59): Force finishing activity test34.pkg/.Tests34Activity
09-10 12:12:45.159: WARN/ActivityManager(59): Activity pause timeout for HistoryRecord{450b53a0 test34.pkg/.Tests34Activity}
09-10 12:12:55.548: WARN/ActivityManager(59): Activity destroy timeout for HistoryRecord{450b53a0 test34.pkg/.Tests34Activity}
I think you getting this type of error
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/Maps
Have you added google-collect-1.0-rc1.jar file? if not then I am sure you got the error, this is the dependent file.
you can download from this file from this site and download it and add in your project.

Android app crashes with java.lang.NoClassDefFoundError after WIN DEATH

I defined an AsyncTask and create an instance from inside a MapView class. Everything works perfectly except when Android decides to kill the window, then when I try to re-open the activity the app crashes with a NoClassDefFoundError for my AsyncTask. I also tried making the AsyncTask class static but nothing changed.
I have tested it several times and I'm quite confident that the crash is due to the activity being killed previously.
[Update] I didn't post the stack trace because I saw nothing relevant. I've done some more tests and now I see something in the log that can be a clue:
I/ActivityManager( 144): Displayed activity com.myorg.myApp/.MyActivity: 4456 ms (total 4456 ms)
I/dalvikvm( 3413): **Rejecting re-init on previously-failed class** Lcom/myorg/myApp/MyMapView$MyAsyncTask; v=0x0
D/AndroidRuntime( 3413): Shutting down VM
W/dalvikvm( 3413): threadid=1: thread exiting with uncaught exception (group=0x400207e8)
E/AndroidRuntime( 3413): FATAL EXCEPTION: main
E/AndroidRuntime( 3413): java.lang.NoClassDefFoundError: com.myorg.myApp.MyMapView$MyAsyncTask
E/AndroidRuntime( 3413): at com.myorg.myApp.MyMapView$4.run(MyMapView.java:169)
E/AndroidRuntime( 3413): at android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime( 3413): at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 3413): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 3413): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime( 3413): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 3413): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 3413): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime( 3413): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime( 3413): at dalvik.system.NativeStart.main(Native Method)
The line: I/dalvikvm( 3413): Rejecting re-init on previously-failed class
Makes me think that it comes from a previous error but I see no other stack traces in the log or errors reported.
I solved that problem in UI Thread
getActivity().runOnUiThread(new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
asynTask = new LoadWebAsynTask();
asynTask.execute();
}
});
I'd need a stack trace to be sure, but I think your problem is similar to the one described in this other question.
It's not necessarily that the classloader can't find your AsyncTask class - it's that some error is thrown during the loading of the class, or during the startup of the Thread backing the AsyncTask that's preventing the classloader from loading the class.
I'd guess the WIN DEATH is causing some strange internal state that's not being checked for and is throwing the error.

Categories

Resources