在將此問題放在此處之前,我嘗試了很多。方法調用在Android中不起作用
Messaging msg = new Messaging();
msg.appendToMessageHistorysend(FriendList.ownusername, str);
我打電話appendToMessageHistorysend功能從另一個活動,以消息類
public void appendToMessageHistorysend(String username, String message) {
if (username != null && message != null) {
username1 = "<font color=#FF66CC>" + "<b>" + username + "<b/>"
+ ": " + "</font>";
message1 = "<font color=#ffcc00>" + message + " "
+ "<br/>" + "</font>";
Thread thread = new Thread() {
@Override
public void run() {
handler.post(new Runnable() {
public void run() {
if (messageHistoryText != null) {
messageHistoryText.append(Html
.fromHtml(username1));
messageHistoryText.append(Html
.fromHtml(message1));
}
else {
Toast.makeText(mCon, "hey yo you are null",
Toast.LENGTH_LONG).show();
}
}
});
}
};
thread.start();
}
}
這裏是調用的函數和我收到錯誤,如下面
01-21 15:21:42.552: E/AndroidRuntime(16751): FATAL EXCEPTION: main
01-21 15:21:42.552: E/AndroidRuntime(16751): java.lang.NullPointerException
01-21 15:21:42.552: E/AndroidRuntime(16751): at at.vcity.androidim.Messaging$7$1.run(Messaging.java:515)
01-21 15:21:42.552: E/AndroidRuntime(16751): at android.os.Handler.handleCallback(Handler.java:615)
01-21 15:21:42.552: E/AndroidRuntime(16751): at android.os.Handler.dispatchMessage(Handler.java:92)
01-21 15:21:42.552: E/AndroidRuntime(16751): at android.os.Looper.loop(Looper.java:137)
01-21 15:21:42.552: E/AndroidRuntime(16751): at android.app.ActivityThread.main(ActivityThread.java:4812)
01-21 15:21:42.552: E/AndroidRuntime(16751): at java.lang.reflect.Method.invokeNative(Native Method)
01-21 15:21:42.552: E/AndroidRuntime(16751): at java.lang.reflect.Method.invoke(Method.java:511)
01-21 15:21:42.552: E/AndroidRuntime(16751): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
01-21 15:21:42.552: E/AndroidRuntime(16751): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
01-21 15:21:42.552: E/AndroidRuntime(16751): at dalvik.system.NativeStart.main(Native Method)
01-21 15:21:44.704: E/Trace(17053): error opening trace file: No such file or directory (2)
請給您的寶貴時間和我非常感謝每一個機構。
你需要'Context'在其他班級中顯示Toast。 – 2015-01-21 09:36:52
getapplicationcontex() – 2015-01-21 09:37:41