我想將一個字符串值「url」傳遞給一個片段,以便在Web視圖中顯示它。我不斷收到以下錯誤:嘗試從EditText傳遞URL到片段
顯示java.lang.NullPointerException
這是我的代碼:
protected void goToTab1View() {
if(mTabState != TAB1_STATE){
mTabState = TAB1_STATE;
Toast.makeText(getActivity(), "goToTabView1: " + url, Toast.LENGTH_SHORT).show();
FragmentManager fm = getFragmentManager();
if(fm!= null){
//Perform fragment transaction
FragmentTransaction ft = fm.beginTransaction();
FragTab1 f = new FragTab1();
f.setString(url);
ft.replace(R.id.fragment_content, f);
ft.commit();
}
}
}
我相信我沒有正確安裝的片段?我只是新來的碎片,所以我很抱歉,如果問題是顯而易見的。任何幫助將非常感激。
堆棧跟蹤:
01-11 13:16:06.671: E/AndroidRuntime(23045): FATAL EXCEPTION: main
01-11 13:16:06.671: E/AndroidRuntime(23045): java.lang.NullPointerException
01-11 13:16:06.671: E/AndroidRuntime(23045): at android.widget.Toast.<init>(Toast.java:92)
01-11 13:16:06.671: E/AndroidRuntime(23045): at android.widget.Toast.makeText(Toast.java:238)
01-11 13:16:06.671: E/AndroidRuntime(23045): at com.example.tabdemo.FragTab1.setString(FragTab1.java:57)
01-11 13:16:06.671: E/AndroidRuntime(23045): at com.example.tabdemo.TabFragment.goToTab1View(TabFragment.java:60)
01-11 13:16:06.671: E/AndroidRuntime(23045): at com.example.tabdemo.MainActivity$1.onClick(MainActivity.java:34)
01-11 13:16:06.671: E/AndroidRuntime(23045): at android.view.View.performClick(View.java:4202)
01-11 13:16:06.671: E/AndroidRuntime(23045): at android.view.View$PerformClick.run(View.java:17340)
01-11 13:16:06.671: E/AndroidRuntime(23045): at android.os.Handler.handleCallback(Handler.java:725)
01-11 13:16:06.671: E/AndroidRuntime(23045): at android.os.Handler.dispatchMessage(Handler.java:92)
01-11 13:16:06.671: E/AndroidRuntime(23045): at android.os.Looper.loop(Looper.java:137)
01-11 13:16:06.671: E/AndroidRuntime(23045): at android.app.ActivityThread.main(ActivityThread.java:5039)
01-11 13:16:06.671: E/AndroidRuntime(23045): at java.lang.reflect.Method.invokeNative(Native Method)
01-11 13:16:06.671: E/AndroidRuntime(23045): at java.lang.reflect.Method.invoke(Method.java:511)
01-11 13:16:06.671: E/AndroidRuntime(23045): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-11 13:16:06.671: E/AndroidRuntime(23045): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-11 13:16:06.671: E/AndroidRuntime(23045): at dalvik.system.NativeStart.main(Native Method)
發佈堆棧跟蹤 – nandeesh
您應該真正指定導致空指針的行和變量。這是迄今爲止最容易找到你調試。 –
@nandeesh我發佈了來自堆棧跟蹤的錯誤消息。 – Javacadabra