android - NullPointerException while trying to startActivityForResult -
android - NullPointerException while trying to startActivityForResult -
edit: reply not phone call startactivityforresult
on called activity object, instead invoke caller's context.
this code, exception on lastly line:
107 intent intent = new intent(callingactivity.this, calledactivity.class); 108 calledactivity calledactivity = new calledactivity(); 109 calledactivity.startactivityforresult(intent, called_activity_code);
inside callingactivity:
@override protected void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data); log.i(sr.tag,"req=" + requestcode + " res=" + resultcode); //never getting here }
manifest file snippet:
<activity android:name=".ui.callingactivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name=".ui.calledactivity"></activity>
exception:
01-14 11:30:14.850: error/androidruntime(1036): fatal exception: main 01-14 11:30:14.850: error/androidruntime(1036): java.lang.nullpointerexception 01-14 11:30:14.850: error/androidruntime(1036): @ android.app.activity.startactivityforresult(activity.java:2833) 01-14 11:30:14.850: error/androidruntime(1036): @ com.litvin.app.ui.callingactivity.onsharedpreferencechanged(callingactivity.java:109 ) ...
whenever move home , launcher intent filters .ui.calledactivity
, works fine. starts calledactivity when press icon.
i have looked through many similar answers here, none worked me.
// no need create object
calledactivity calledactivity = new calledactivity(); //comment line
//do this
intent.startactivityforresult(intent, called_activity_code);
android
Comments
Post a Comment