getResources error

  • Antworten:1
Robin G.
  • Forum-Beiträge: 1

16.07.2011, 00:36:38 via Website

Hi,

ich bekomme immer wenn ich "getResources()" in der MainActivity aufrufe einen Fehler und die App beendet sich. Dies geschieht auch wenn ich getApplicationContext().getResources() aufrufe. Auch wenn ich ein komplett frisches Projekt in Eclipse erstelle. Muss ich irgendetwas beachten wovon ich nichts weiß? Auf AVD mit Android 2.1 und LG GW620 mit OpenEtna

LogCat:
W/dalvikvm( 3308): threadid=1: thread exiting with uncaught exception (group=0x400207e0)
E/AndroidRuntime( 3308): FATAL EXCEPTION: main
E/AndroidRuntime( 3308): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.android.gradeCalc/com.android.blub.BlaActivity}: java.lang.NullPointerException
E/AndroidRuntime( 3308): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
E/AndroidRuntime( 3308): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
E/AndroidRuntime( 3308): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
E/AndroidRuntime( 3308): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
E/AndroidRuntime( 3308): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 3308): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 3308): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime( 3308): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 3308): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 3308): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime( 3308): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime( 3308): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 3308): Caused by: java.lang.NullPointerException
E/AndroidRuntime( 3308): at android.content.ContextWrapper.getApplicationContext(ContextWrapper.java:100)
E/AndroidRuntime( 3308): at com.android.gradeCalc.GradeCalcActivity.<init>(GradeCalcActivity.java:10)
E/AndroidRuntime( 3308): at java.lang.Class.newInstanceImpl(Native Method)
E/AndroidRuntime( 3308): at java.lang.Class.newInstance(Class.java:1429)
E/AndroidRuntime( 3308): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
E/AndroidRuntime( 3308): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
E/AndroidRuntime( 3308): ... 11 more

Antworten
Stefan S.
  • Forum-Beiträge: 560

19.07.2011, 08:03:33 via Website

Versuchmal statt getApplicationContext()... ClassName.this
d.h. wenn deine Klasse public class TestClass... heisst einfach mal TestClass.this verwenden.

Antworten