eclipse - Android - force closes app -



eclipse - Android - force closes app -

this question has reply here:

nullpointerexception accessing views in oncreate() 8 answers

myapp contains 1 textview , 2 buttons - add together , sub. when add together button pressed, counter++. sub -> counter --.

i got msg console - not wglgetextensionsstringarb.

could see homepage. failed open myapp. forcefulness close needed.

main:

<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" tools:context="com.btp.myapp.mainactivity"> <item android:id="@+id/action_settings" android:orderincategory="100" android:title="@string/action_settings" /> </menu>

manifest:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.btp.myapp" android:versioncode="1" android:versionname="1.0" > <uses-sdk android:minsdkversion="8" android:targetsdkversion="19" /> <application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name="com.btp.myapp.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>

mainactivity.java:

package com.btp.myapp; import android.support.v7.app.actionbaractivity; import android.support.v4.app.fragment; import android.os.bundle; import android.view.layoutinflater; import android.view.menu; import android.view.menuitem; import android.view.view; import android.view.viewgroup; import android.widget.button; import android.widget.textview; public class mainactivity extends actionbaractivity { int counter; button add, sub; textview display; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); counter = 0; add together = (button) findviewbyid(r.id.add); sub = (button) findviewbyid(r.id.sub); display = (textview)findviewbyid(r.id.textview2); add.setonclicklistener(new view.onclicklistener(){ public void onclick(view v){ // todo auto-generated method stub counter++; display.settext("your total is" + counter); } }); sub.setonclicklistener(new view.onclicklistener(){ public void onclick(view v){ // todo auto-generated method stub counter--; display.settext("your total is" + counter); } }); if (savedinstancestate == null) { getsupportfragmentmanager().begintransaction() .add(r.id.container, new placeholderfragment()).commit(); } } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); homecoming true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); if (id == r.id.action_settings) { homecoming true; } homecoming super.onoptionsitemselected(item); } /** * placeholder fragment containing simple view. */ public static class placeholderfragment extends fragment { public placeholderfragment() { } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view rootview = inflater.inflate(r.layout.fragment_main, container, false); homecoming rootview; } } }

logcat:

06-18 04:05:45.942: i/dalvikvm(325): not find method android.content.pm.packagemanager.getactivitylogo, referenced method android.support.v7.internal.widget.actionbarview.<init> 06-18 04:05:45.942: w/dalvikvm(325): vfy: unable resolve virtual method 318: landroid/content/pm/packagemanager;.getactivitylogo (landroid/content/componentname;)landroid/graphics/drawable/drawable; 06-18 04:05:45.942: d/dalvikvm(325): vfy: replacing opcode 0x6e @ 0x008b 06-18 04:05:45.951: i/dalvikvm(325): not find method android.content.pm.applicationinfo.loadlogo, referenced method android.support.v7.internal.widget.actionbarview.<init> 06-18 04:05:45.951: w/dalvikvm(325): vfy: unable resolve virtual method 314: landroid/content/pm/applicationinfo;.loadlogo (landroid/content/pm/packagemanager;)landroid/graphics/drawable/drawable; 06-18 04:05:45.951: d/dalvikvm(325): vfy: replacing opcode 0x6e @ 0x0099 06-18 04:05:45.972: d/dalvikvm(325): vfy: dead code 0x008e-0092 in landroid/support/v7/internal/widget/actionbarview;.<init> (landroid/content/context;landroid/util/attributeset;)v 06-18 04:05:45.972: d/dalvikvm(325): vfy: dead code 0x009c-00a0 in landroid/support/v7/internal/widget/actionbarview;.<init> (landroid/content/context;landroid/util/attributeset;)v 06-18 04:05:46.221: d/androidruntime(325): shutting downwards vm 06-18 04:05:46.221: w/dalvikvm(325): threadid=1: thread exiting uncaught exception (group=0x4001d800) 06-18 04:05:46.241: e/androidruntime(325): fatal exception: main 06-18 04:05:46.241: e/androidruntime(325): java.lang.runtimeexception: unable start activity componentinfo{com.btp.myapp/com.btp.myapp.mainactivity}: java.lang.nullpointerexception 06-18 04:05:46.241: e/androidruntime(325): @ android.app.activitythread.performlaunchactivity(activitythread.java:2663) 06-18 04:05:46.241: e/androidruntime(325): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2679) 06-18 04:05:46.241: e/androidruntime(325): @ android.app.activitythread.access$2300(activitythread.java:125) 06-18 04:05:46.241: e/androidruntime(325): @ android.app.activitythread$h.handlemessage(activitythread.java:2033) 06-18 04:05:46.241: e/androidruntime(325): @ android.os.handler.dispatchmessage(handler.java:99) 06-18 04:05:46.241: e/androidruntime(325): @ android.os.looper.loop(looper.java:123) 06-18 04:05:46.241: e/androidruntime(325): @ android.app.activitythread.main(activitythread.java:4627) 06-18 04:05:46.241: e/androidruntime(325): @ java.lang.reflect.method.invokenative(native method) 06-18 04:05:46.241: e/androidruntime(325): @ java.lang.reflect.method.invoke(method.java:521) 06-18 04:05:46.241: e/androidruntime(325): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:868) 06-18 04:05:46.241: e/androidruntime(325): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:626) 06-18 04:05:46.241: e/androidruntime(325): @ dalvik.system.nativestart.main(native method) 06-18 04:05:46.241: e/androidruntime(325): caused by: java.lang.nullpointerexception 06-18 04:05:46.241: e/androidruntime(325): @ com.btp.myapp.mainactivity.oncreate(mainactivity.java:32) 06-18 04:05:46.241: e/androidruntime(325): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1047) 06-18 04:05:46.241: e/androidruntime(325): @ android.app.activitythread.performlaunchactivity(activitythread.java:2627) 06-18 04:05:46.241: e/androidruntime(325): ... 11 more

the log refers null reference exception thrown on line 32 in mainactivity.

this line add.setonclicklistener(new view.onclicklistener(){

now object 'add' loaded line add together = (button) findviewbyid(r.id.add);

looking @ xml files, cannot see have resource id 'add', explains it. cannot find resource, 'add' null

android eclipse

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -