同じコードがAndroid2.3で正常に実行される理由はわかりませんが、Android 3.1タブレットの場合、NullPointerExceptionsがスローされます...コードは次のとおりです。
public class CalleeButton extends Button implements OnClickListener, AddressAware {
private AddressText mAddress;
private OnClickListener externalClickListener;
public void setExternalClickListener(OnClickListener e) {externalClickListener = e;}
public void setAddressWidget(AddressText a) {a=mAddress;}
//set Uri SipUri ,so we can initialize the mAddress inside calleebutton --smartclassroom
//because every calleebutton will have one sip account/ext. this will replace the information for original mAddress --smartclassroom
public void setSip(String StudentName,String SipUri, AddressText a)
{
Log.i("CalleeButton-35");
super.setText(StudentName);
//mAddress.setText(SipUri);
Log.i("CalleeButton-38");
mAddress.setContactAddress(SipUri, StudentName);
Log.i("CalleeButton-40");
setAddressWidget(a);
Log.i("CalleeButton-42");
}
public CalleeButton(Context context, AttributeSet attrs) {
super(context, attrs);
setOnClickListener(this);
//must use this line or you got null pointer exception...smartclassroom
Log.i("CalleeButton-50");
mAddress = new AddressText(context, attrs);
//mAddress = null;
Log.i("CalleeButton-52");
}
public void onClick(View v) {
try {
if (!LinphoneManager.getInstance().acceptCallIfIncomingPending()) {
if (mAddress.getText().length() >0) {
LinphoneManager.getInstance().newOutgoingCall(mAddress);
//add new action here
/*******************************************************/
/*******************************************************/
}
}
} catch (LinphoneCoreException e) {
LinphoneManager.getInstance().terminateCall();
onWrongDestinationAddress();
};
if (externalClickListener != null) externalClickListener.onClick(v);
}
protected void onWrongDestinationAddress() {
Toast toast = Toast.makeText(getContext()
,String.format(getResources().getString(R.string.warning_wrong_destination_address),mAddress.getText().toString())
,Toast.LENGTH_LONG);
toast.show();
}
}
実際、Android 2.3プラットフォームでNullPointerExceptionが発生したことがありますが、追加した後は次のようになります。
mAddress = new AddressText(context, attrs);
その後、コンパイルしてスムーズに実行されます...同じプログラムをAndroid3.1タブレットにインストールしようとするまで...奇妙ですね。よろしくお願いします!logcatのエラーメッセージは次のとおりです。
04-25 23:58:13.308: ERROR/AndroidRuntime(6728): FATAL EXCEPTION: main
04-25 23:58:13.308: ERROR/AndroidRuntime(6728): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.linphone/org.linphone.LinphoneActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{org.linphone/org.linphone.DialerActivity}: java.lang.NullPointerException
04-25 23:58:13.308: ERROR/AndroidRuntime(6728): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1751)
04-25 23:58:13.308: ERROR/AndroidRuntime(6728): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1767)
04-25 23:58:13.308: ERROR/AndroidRuntime(6728): at android.app.ActivityThread.access$1500(ActivityThread.java:122)
04-25 23:58:13.308: ERROR/AndroidRuntime(6728): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1005)
04-25 23:58:13.308: ERROR/AndroidRuntime(6728): at android.os.Handler.dispatchMessage(Handler.java:99)
04-25 23:58:13.308: ERROR/AndroidRuntime(6728): at android.os.Looper.loop(Looper.java:132)
04-25 23:58:13.308: ERROR/AndroidRuntime(6728): at android.app.ActivityThread.main(ActivityThread.java:4028)
04-25 23:58:13.308: ERROR/AndroidRuntime(6728): at java.lang.reflect.Method.invokeNative(Native Method)
04-25 23:58:13.308: ERROR/AndroidRuntime(6728): at java.lang.reflect.Method.invoke(Method.java:491)
04-25 23:58:13.308: ERROR/AndroidRuntime(6728): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
04-25 23:58:13.308: ERROR/AndroidRuntime(6728): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
04-25 23:58:13.308: ERROR/AndroidRuntime(6728): at dalvik.system.NativeStart.main(Native Method)
04-25 23:58:13.308: ERROR/AndroidRuntime(6728): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{org.linphone/org.linphone.DialerActivity}: java.lang.NullPointerException
04-25 23:58:13.308: ERROR/AndroidRuntime(6728): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1751)
04-25 23:58:13.308: ERROR/AndroidRuntime(6728): at android.app.ActivityThread.startActivityNow(ActivityThread.java:1592)
04-25 23:58:13.308: ERROR/AndroidRuntime(6728): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:130)
04-25 23:58:13.308: ERROR/AndroidRuntime(6728): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:342)
04-25 23:58:13.308: ERROR/AndroidRuntime(6728): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:676)
04-25 23:58:13.308: ERROR/AndroidRuntime(6728): at android.widget.TabHost.setCurrentTab(TabHost.java:345)
04-25 23:58:13.308: ERROR/AndroidRuntime(6728): at android.widget.TabHost.setCurrentTabByTag(TabHost.java:282)
04-25 23:58:13.308: ERROR/AndroidRuntime(6728): at org.linphone.LinphoneActivity.gotToDialer(LinphoneActivity.java:481)
04-25 23:58:13.308: ERROR/AndroidRuntime(6728): at org.linphone.LinphoneActivity.fillTabHost(LinphoneActivity.java:207)
04-25 23:58:13.308: ERROR/AndroidRuntime(6728): at org.linphone.LinphoneActivity.onCreate(LinphoneActivity.java:126)
04-25 23:58:13.308: ERROR/AndroidRuntime(6728): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
04-25 23:58:13.308: ERROR/AndroidRuntime(6728): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1715)
04-25 23:58:13.308: ERROR/AndroidRuntime(6728): ... 11 more
04-25 23:58:13.308: ERROR/AndroidRuntime(6728): Caused by: java.lang.NullPointerException
04-25 23:58:13.308: ERROR/AndroidRuntime(6728): at org.linphone.DialerActivity.onCreate(DialerActivity.java:128)
04-25 23:58:13.308: ERROR/AndroidRuntime(6728): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
04-25 23:58:13.308: ERROR/AndroidRuntime(6728): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1715)
04-25 23:58:13.308: ERROR/AndroidRuntime(6728): ... 22 more
私の意見から、logcatmsgsは関数について教えてくれました:
mCallee1.setSip("Jack","sip:xxx@xxx.xxx.xxx.xxx",mAddress);
DailerActivity.java(ここではメイン関数として扱うことができます)でNullPointerExcetionが発生し、コードをCalleeButton.javaまでトレースしましたが、それでもnullポインター例外が発生したポイントを見つけることができません...