我有这个问题:java.lang.NullPointerException
我的代码和LogCat图片:
WebviewActivity.class
public class WebviewActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_webview);
Bundle alinan = getIntent().getExtras();
String alinmis = alinan.getString("veri");
WebView webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(alinmis);
webView.getSettings().setBuiltInZoomControls(true);
webView.setWebChromeClient(new WebChromeClient() {
});
MenutrActivity.class
public class MenutrActivity extends Activity{
Bundle bnd;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menutr);
bnd = new Bundle();
Button mekanlar = (Button)findViewById(R.id.mekanlar);
final Intent i = new Intent(getApplicationContext(), WebviewActivity.class);
mekanlar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent("android.intent.action.WEBK"));
String myString = "http://www.google.com.tr";
bnd.putString("veri", myString);
i.putExtras(bnd);
startActivity(i);
}
}); }}
按下按钮时,应用程序失败。
LogCat错误:WebviewActivity.class中的java.lang.NullPointerException
答案 0 :(得分:2)
首先将“StartActivity(new Intent ....”更改为“Intent i = new Intent(...”)。在添加额外内容之前调用该活动。
下次只需复制代码并粘贴为代码即可。这种方式很难看到......