I was testing android minSDKVersion property and find a strange behavior-
I put minSDKVersion=3 (1.5) and targetSDKVersion=4 (1.6) in androidManifest.xml file.
For testing, I put following lines in onCreate method of launching activity -
android.telephony.SmsManager sm = android.telephony.SmsManager.getDefault();
ArrayList<String> stringArray = sm.divideMessage("this is message");
Toast.makeText(this, stringArray.get(0), Toast.LENGTH_LONG).show();
android.telephony.SmsManager class is being introduced in android 1.6.
After adding these lines, on 1.6 emulator it was showing toast, but on 1.5 emulator it did not show toast and did not crashed either.
I was expecting that the application will crash on 1.5 emulator but this did not happen.
Can anyone explain this?
Thanks
Attempting to call methods of classes that aren't available will result in an exception.
It isn't clear to me why you did not observe a crash. Perhaps you have other code that is saving you.
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.versions"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".MinSdk"
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>
<uses-sdk android:minSdkVersion="3" />
</manifest>
Activity Code:
package com.example.versions;
import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.widget.Toast;
public class MinSdk extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SmsManager sm = SmsManager.getDefault();
ArrayList<String> stringArray = sm.divideMessage("this is message");
Toast.makeText(this, stringArray.get(0), Toast.LENGTH_LONG).show();
}
}
Dump of Logcat when run in Android 1.5 emulator:
E/dalvikvm( 779): Could not find method android.telephony.SmsManager.getDefault, referenced from method com.example.versions.MinSdk.onCreate
W/dalvikvm( 779): VFY: unable to resolve static method 3: Landroid/telephony/SmsManager;.getDefault ()Landroid/telephony/SmsManager;
W/dalvikvm( 779): VFY: rejecting opcode 0x71 at 0x0008
W/dalvikvm( 779): VFY: rejected Lcom/example/versions/MinSdk;.onCreate (Landroid/os/Bundle;)V
W/dalvikvm( 779): Verifier rejected class Lcom/example/versions/MinSdk;
W/dalvikvm( 779): Class init failed in newInstance call (Lcom/example/versions/MinSdk;)
D/AndroidRuntime( 779): Shutting down VM
W/dalvikvm( 779): threadid=3: thread exiting with uncaught exception (group=0x4000fe70)
E/AndroidRuntime( 779): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime( 779): java.lang.VerifyError: com.example.versions.MinSdk
E/AndroidRuntime( 779): at java.lang.Class.newInstanceImpl(Native Method)
E/AndroidRuntime( 779): at java.lang.Class.newInstance(Class.java:1472)
E/AndroidRuntime( 779): at android.app.Instrumentation.newActivity(Instrumentation.java:1097)
E/AndroidRuntime( 779): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2186)
E/AndroidRuntime( 779): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
E/AndroidRuntime( 779): at android.app.ActivityThread.access$1800(ActivityThread.java:112)
E/AndroidRuntime( 779): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
E/AndroidRuntime( 779): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 779): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 779): at android.app.ActivityThread.main(ActivityThread.java:3948)
E/AndroidRuntime( 779): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 779): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 779): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
E/AndroidRuntime( 779): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
E/AndroidRuntime( 779): at dalvik.system.NativeStart.main(Native Method)
D/dalvikvm( 541): GC freed 2 objects / 48 bytes in 194ms
I/Process ( 575): Sending signal. PID: 779 SIG: 3
I/dalvikvm( 779): threadid=7: reacting to signal 3
I/dalvikvm( 779): Wrote stack trace to '/data/anr/traces.txt'
Related
I'm trying to run hello world app using Rho Studio (just New -> Project -> Finish) on various supported platforms. I managed to run it on win32. I'm curious about windows mobile deployment, but I'm holding out now, since it requires paid subscription. The app also runs on all platforms on simulator, however I failed to run it on android using either run configuration -> Android -> Device) and RhoMobile -> Production Build -> Android, Local.
I've installed Android SDK, and NDK. I run keytool.exe manually since cert generation requires keyboard input and it blocked rake script. Generally builds are ok, and I have RhoMobileApplication1-debug.apk or RhoMobileApplication1-signed.apk.
Then I deploy it to the device
adb install *.apk
And when I run the app it almost immediately crashes with standard android messagebox when something goes really wrong. So i did adb logcat to file and figure out that possibly cause is that when loading librhodes.so it tries to load soinfo_relocate and fail.
However at this point my superpowers failed me, because google gives me only clue that it might be something with the Android NDK itself.
Any suggestions?
D/AbsListView(29935): unregisterIRListener() is called
E/dalvikvm( 6074): dlopen("/data/app-lib/com.rhomobile.rhomobileapplication1-1/librhodes.so") failed: Cannot load library: soinfo_relocate(linker.cpp:976): cannot locate symbol "sigemptyset" referenced by "librhodes.so"...
W/dalvikvm( 6074): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/rhomobile/rhodes/RhodesApplication;
W/dalvikvm( 6074): Class init failed in newInstance call (Lcom/rhomobile/rhodes/RhodesApplication;)
D/AndroidRuntime( 6074): Shutting down VM
W/dalvikvm( 6074): threadid=1: thread exiting with uncaught exception (group=0x42040930)
E/AndroidRuntime( 6074): FATAL EXCEPTION: main
E/AndroidRuntime( 6074): java.lang.ExceptionInInitializerError
E/AndroidRuntime( 6074): at java.lang.Class.newInstanceImpl(Native Method)
E/AndroidRuntime( 6074): at java.lang.Class.newInstance(Class.java:1319)
E/AndroidRuntime( 6074): at android.app.Instrumentation.newApplication(Instrumentation.java:1000)
E/AndroidRuntime( 6074): at android.app.Instrumentation.newApplication(Instrumentation.java:985)
E/AndroidRuntime( 6074): at android.app.LoadedApk.makeApplication(LoadedApk.java:499)
E/AndroidRuntime( 6074): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4565)
E/AndroidRuntime( 6074): at android.app.ActivityThread.access$1400(ActivityThread.java:157)
E/AndroidRuntime( 6074): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)
E/AndroidRuntime( 6074): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 6074): at android.os.Looper.loop(Looper.java:176)
E/AndroidRuntime( 6074): at android.app.ActivityThread.main(ActivityThread.java:5319)
E/AndroidRuntime( 6074): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 6074): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 6074): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
E/AndroidRuntime( 6074): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
E/AndroidRuntime( 6074): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 6074): Caused by: java.lang.UnsatisfiedLinkError: Cannot load library: soinfo_relocate(linker.cpp:976): cannot locate symbol "sigemptyset" referenced by "librhodes.so"...
E/AndroidRuntime( 6074): at java.lang.Runtime.loadLibrary(Runtime.java:371)
E/AndroidRuntime( 6074): at java.lang.System.loadLibrary(System.java:535)
E/AndroidRuntime( 6074): at com.rhomobile.rhodes.NativeLibraries.load(NativeLibraries.java:5)
E/AndroidRuntime( 6074): at com.rhomobile.rhodes.RhodesApplication.(RhodesApplication.java:105)
E/AndroidRuntime( 6074): ... 16 more
D/SensorService( 1959): -0.1 0.7 10.0
D/CrashAnrDetector( 1959): processName: com.rhomobile.rhomobileapplication1
D/CrashAnrDetector( 1959): broadcastEvent : com.rhomobile.rhomobileapplication1 data_app_crash
RhoMobileSuite5.2.2
jre1.8.0_51
android-ndk-r10e
phone with android 4.2.2
tablet with android 4.4.2
RhoMobile doesn't support at this moment NDK r10, you need to use NDK r9, as documented on RhoMobile documentation website.
On RhoMobile developer forums there're some discussion about other issues linked to people using NDK r10:
Rhostudio 5.1.1 not work in kitkat and lower versions
Android NDK r10d, Lollipop, 64-bit
Yes, I know this question is similar to this, but it never got answered and I don't like resurrecting old threads (from July '13).
I just began testing my game on a real device (yay!), and though it works perfectly on the Corona Simulator, every time I open it on the actual device and now the emulator, I get "Sorry! The application SampleApp (process com.foo.bar.SampleApp) has stopped unexpectedly. Please try again." I opened adb logcat and find that I'm getting this error:
I/ActivityThread( 1264): Pub com.foo.bar.SampleApp.files: com.ansca.corona.storage.FileContentProvider
W/dalvikvm( 1264): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/ansca/corona/JavaToNativeShim;
W/dalvikvm( 1264): Exception Ljava/lang/ExceptionInInitializerError; thrown while initializing Lcom/ansca/corona/CoronaEnvironment;
D/AndroidRuntime( 1264): Shutting down VM
W/dalvikvm( 1264): threadid=1: thread exiting with uncaught exception (group=0x40020560)
E/AndroidRuntime( 1264): FATAL EXCEPTION: main
E/AndroidRuntime( 1264): java.lang.ExceptionInInitializerError
E/AndroidRuntime( 1264): at com.ansca.corona.CoronaView.deleteTempDirectory(CoronaView.java:141)
E/AndroidRuntime( 1264): at com.ansca.corona.CoronaActivity.onCreate(CoronaActivity.java:101)
E/AndroidRuntime( 1264): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime( 1264): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1618)
E/AndroidRuntime( 1264): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1670)
E/AndroidRuntime( 1264): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
E/AndroidRuntime( 1264): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
E/AndroidRuntime( 1264): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 1264): at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime( 1264): at android.app.ActivityThread.main(ActivityThread.java:3695)
E/AndroidRuntime( 1264): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1264): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 1264): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
E/AndroidRuntime( 1264): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
E/AndroidRuntime( 1264): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 1264): Caused by: java.lang.ExceptionInInitializerError
E/AndroidRuntime( 1264): at com.ansca.corona.CoronaEnvironment.setLuaErrorHandler(CoronaEnvironment.java:379)
E/AndroidRuntime( 1264): at com.ansca.corona.CoronaEnvironment.<clinit>(CoronaEnvironment.java:41)
E/AndroidRuntime( 1264): ... 15 more
E/AndroidRuntime( 1264): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load lua: findLibrary returned null
E/AndroidRuntime( 1264): at java.lang.Runtime.loadLibrary(Runtime.java:429)
E/AndroidRuntime( 1264): at java.lang.System.loadLibrary(System.java:554)
E/AndroidRuntime( 1264): at com.ansca.corona.JavaToNativeShim.<clinit>(JavaToNativeShim.java:118)
E/AndroidRuntime( 1264): ... 17 more
W/ActivityManager( 146): Force finishing activity com.foo.bar.SampleApp/com.ansca.corona.CoronaActivity
Of course, the real process name isn't com.foo.bar.SampleApp, but it's the same thing.
I have an old Android, so that may be the issue, but I sure hope not. I'm on a Huawei-U8652, Android version 2.3.5. I also built a Corona sample code app, and it did the same thing with the same error.
The error is that Lua can't be found, that's pretty extreme. Works from Corona Sim, but not on real device, or in Eclipse-based emulator. Until you can get it to work on the real device, there is no point in using the emulator, it's just too much of an unknown wrt Corona. Try this:
verify examples that come with Corona work on your device
if they do, start adding parts of your main.lua in one of those examples; maybe at some point the error will happen again, allowing you to identify a specific lib call that corrupts memory and sends everything wally
start adding other parts of your app (if you import modules during startup), until you see the error again
I developed the project in Eclipse, then moved to IntelliJ IDEA CE 12, then moved back to the Eclipse. IDEA had converted it to eclipse project not correctly, so I imported project from existing source and added line
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
to the section. Ok, it compiles successfully, but generates a lot of strange errors for the classes written by me and then crashes.
LogCat output:
E/dalvikvm( 9673): Could not find class 'com.capsule.launcher.views.Screen', referenced from method com.capsule.launcher.views.Workspace$1.onPageSelected
W/dalvikvm( 9673): VFY: unable to resolve check-cast 458 (Lcom/capsule/launcher/views/Screen;) in Lcom/capsule/launcher/views/Workspace$1;
D/dalvikvm( 9673): VFY: replacing opcode 0x1f at 0x0010
W/dalvikvm( 9673): Unable to resolve superclass of Lcom/capsule/launcher/views/CellLayout; (346)
W/dalvikvm( 9673): Link of class 'Lcom/capsule/launcher/views/CellLayout;' failed
W/dalvikvm( 9673): Unable to resolve superclass of Lcom/capsule/launcher/views/DockBar; (455)
W/dalvikvm( 9673): Link of class 'Lcom/capsule/launcher/views/DockBar;' failed
W/dalvikvm( 9673): VFY: unable to find class referenced in signature (Lcom/capsule/launcher/views/DockBar;)
W/dalvikvm( 9673): Unable to resolve superclass of Lcom/capsule/launcher/views/CellLayout; (346)
W/dalvikvm( 9673): Link of class 'Lcom/capsule/launcher/views/CellLayout;' failed
W/dalvikvm( 9673): Unable to resolve superclass of Lcom/capsule/launcher/views/DockBar; (455)
W/dalvikvm( 9673): Link of class 'Lcom/capsule/launcher/views/DockBar;' failed
E/dalvikvm( 9673): Could not find class 'com.capsule.launcher.views.DockBar', referenced from method com.capsule.launcher.views.WorkspaceHolder.onLayout
W/dalvikvm( 9673): VFY: unable to resolve instanceof 456 (Lcom/capsule/launcher/views/DockBar;) in Lcom/capsule/launcher/views/WorkspaceHolder;
D/dalvikvm( 9673): VFY: replacing opcode 0x20 at 0x001b
D/AndroidRuntime( 9673): Shutting down VM
W/dalvikvm( 9673): threadid=1: thread exiting with uncaught exception (group=0x40d6e300)
E/AndroidRuntime( 9673): FATAL EXCEPTION: main
E/AndroidRuntime( 9673): java.lang.NoClassDefFoundError: com.capsule.launcher.views.DockBar
E/AndroidRuntime( 9673): at com.capsule.launcher.LauncherActivity.createWorkspace(LauncherActivity.java:116)
E/AndroidRuntime( 9673): at com.capsule.launcher.LauncherActivity.onCreate(LauncherActivity.java:58)
E/AndroidRuntime( 9673): at android.app.Activity.performCreate(Activity.java:5008)
E/AndroidRuntime( 9673): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
E/AndroidRuntime( 9673): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
E/AndroidRuntime( 9673): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
E/AndroidRuntime( 9673): at android.app.ActivityThread.access$600(ActivityThread.java:130)
E/AndroidRuntime( 9673): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
E/AndroidRuntime( 9673): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 9673): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 9673): at android.app.ActivityThread.main(ActivityThread.java:4745)
E/AndroidRuntime( 9673): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 9673): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 9673): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
E/AndroidRuntime( 9673): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
E/AndroidRuntime( 9673): at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager( 301): Force finishing activity com.capsule.launcher/.LauncherActivity
D/dalvikvm( 9673): GC_CONCURRENT freed 4207K, 20% free 19381K/23943K, paused 13ms+4ms, total 52ms
W/ActivityManager( 301): Activity pause timeout for ActivityRecord{418f0cd0 com.capsule.launcher/.LauncherActivity}
D/dalvikvm( 301): GC_CONCURRENT freed 1886K, 28% free 22076K/30279K, paused 4ms+9ms, total 99ms
W/ActivityManager( 301): Activity destroy timeout for ActivityRecord{418f0cd0 com.capsule.launcher/.LauncherActivity}
D/Finsky ( 7843): [1] 5.onFinished: Installation state replication succeeded.
It worked fine in IDEA and Eclipse before!
I don't know what happend to your project, but try in Eclipse: Project--> Clean--> YourProject
Clean and Build Your Project in Eclipse.Also check in Android Manifest file ,if launcher Activity is defined correctly with its package name.
Its not a good idea to use it like this(manually) rather we can export projects from IntelliJ IDEA to Eclipse in simple steps.
please follow this standard document for the above.
http://www.jetbrains.com/idea/webhelp/exporting-intellij-idea-project-to-eclipse.html
hope this will help you.
if you use librarys in your project , try in build path add to the library export
If you do have the old working eclipse project then copy/replace all the new code and jars to it, from the IntelliJ IDEA project. Remember to copy/replace only the code and jars not the IntelliJ IDEA specific settings files.
Right click on the project which has issues and select properties.
Select the appropriate Android build (1.1, 1.5 or 1.5 with google api) and say ok.
Again right click on the project and select "Android Tools > Fix Project Properties"
Fix the imports once (if required)
Refresh the project and you should be ready to go without any manual editing
Hope this helps.
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.
every time I call getResources in my main activity it results in an error and the app is forced to quit. This also happens if I call getApplicationContext().getResources() and even in a totally new project in Eclips. Do I need to do anything before the call? Error on AVD with Android 2.1 and LG GW620 with OpenEtna (2.1)
MainActivity.java:
package com.robin.blatest;
import android.app.Activity;
import android.content.res.Resources;
import android.os.Bundle;
public class MainActivity extends Activity {
Resources res = this.getResources();
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
Manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.robin.blatest"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".MainActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
LogCat:
W/dalvikvm( 229): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
E/AndroidRuntime( 229): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime( 229): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.robin.blatest/com.robin.blatest.MainActivity}: java.lang.NullPointerException
E/AndroidRuntime( 229): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
E/AndroidRuntime( 229): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
E/AndroidRuntime( 229): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
E/AndroidRuntime( 229): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
E/AndroidRuntime( 229): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 229): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 229): at android.app.ActivityThread.main(ActivityThread.java:4363)
E/AndroidRuntime( 229): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 229): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 229): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
E/AndroidRuntime( 229): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
E/AndroidRuntime( 229): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 229): Caused by: java.lang.NullPointerException
E/AndroidRuntime( 229): at android.content.ContextWrapper.getResources(ContextWrapper.java:80)
E/AndroidRuntime( 229): at com.robin.blatest.MainActivity.<init>(MainActivity.java:9)
E/AndroidRuntime( 229): at java.lang.Class.newInstanceImpl(Native Method)
E/AndroidRuntime( 229): at java.lang.Class.newInstance(Class.java:1479)
E/AndroidRuntime( 229): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
E/AndroidRuntime( 229): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2409)
E/AndroidRuntime( 229): ... 11 more
Cheers Robin
Edit: Added Code
You can't do
Resources res = this.getResources();
in the field declaration. It's null at that point!
Put it in onCreate instead.
You'd do something like:
private Resources res = null;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
res = this.getResources();
}
If you wanted a field containing that data.
But it's just as easy to do this.getResources() whenever you need it.
The getResources()-method is a method from the Context-class.
When in an Activity, you can use this to access it.
But you should show us some of your code.