在Android中调试NullPointerException需要帮助吗

在Android中调试NullPointerException需要帮助吗,android,debugging,pointers,Android,Debugging,Pointers,我的应用程序中有一个about类来显示一些按钮,当用户单击该按钮时,它会跳转到webview活动以查看一些网页,因此我在about类中定义了URL,然后设置onlick方法将它们发送到同一webview活动以打开网页,但是当我运行这个活动时,我不断地得到一个奇怪的NullPointerException,我的logcat只打印一个 12-02 09:03:11.815:警告/活动管理器(51):活动空闲超时 有关历史记录{44d68ea0 com.appkon.hdtvs/.About}12-0

我的应用程序中有一个about类来显示一些按钮,当用户单击该按钮时,它会跳转到webview活动以查看一些网页,因此我在about类中定义了URL,然后设置onlick方法将它们发送到同一webview活动以打开网页,但是当我运行这个活动时,我不断地得到一个奇怪的NullPointerException,我的logcat只打印一个

12-02 09:03:11.815:警告/活动管理器(51):活动空闲超时 有关历史记录{44d68ea0 com.appkon.hdtvs/.About}12-02 09:03:17.026:WARN/ActivityManager(51):的活动销毁超时 历史记录{44e37518 com.appkon.hdtvs/.hdtvs}

这是我的代码。如果您有任何帮助,我们将不胜感激,谢谢

关于.java

public class About extends Activity{

    private Button backbutton;
    private Button likebutton;
    private ImageView versionlogo;
    private ImageButton faq;
    private ImageButton forum;
    private ImageButton feedback;
    private ImageButton rate;
    private String likepath ="http://appkon.com/hdtvs/share.html";
    private String likename = "分享";
    private String lpath="" ;
    private String lname="" ;
    private String faqpath ="http://appkon.com/hdtvs/faq.html";
    private String faqname ="常见问题";
    private String forumpath= "http://appkon.com/forum/" ;
    private String forumname = "APP论坛";
    private String fqpath="";
    private String fqname="";
    private String frpath="";
    private String frname="";
    private String ratepath ="http://appkon.com/hdtvs/";
    private String ratename="评价";
    private String rpath=""; 
    private String rname="";
    private String feedbackpath ="http://appkon.com/hdtvs/feedback.html";
    private String feedbackname="反馈问题";
    private String fdname="";
    private String fdpath="";

    @Override    
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


        backbutton=(Button) findViewById(R.id.back);
        likebutton=(Button) findViewById(R.id.share);
        faq =(ImageButton)findViewById(R.id.faqbutton);
        forum =(ImageButton)findViewById(R.id.forumbutton);
        feedback =(ImageButton)findViewById(R.id.feedbackbutton);
        rate =(ImageButton)findViewById(R.id.ratebutton);

        backbutton.setOnClickListener(new View.OnClickListener()
        {
          public void onClick(View v)
          {
            Intent intent = new Intent();
            intent.setClass(About.this, HDtvs.class);
            startActivity(intent);
            About.this.finish();

          }
        });

        likebutton.setOnClickListener(new View.OnClickListener()
        {
          public void onClick(View v)
          {
            Intent intent = new Intent();
            intent.setClass(About.this, Renrenframe.class);
            startActivity(intent);
            About.this.finish();

          }
        });

        faq.setOnClickListener(new View.OnClickListener()
        {
          public void onClick(View v)
          {
            Intent intent = new Intent();
            intent.setClass(About.this, Aboutframe.class);
            Bundle bundle = new Bundle();
            bundle.putString("fqpath",faqpath);
            bundle.putString("fqname",faqname);
            intent.putExtras(bundle);
            startActivity(intent);
            About.this.finish();

          }
        });

        feedback.setOnClickListener(new View.OnClickListener()
        {
          public void onClick(View v)
          {
            Intent intent = new Intent();
            intent.setClass(About.this, Aboutframe.class);
            Bundle bundle = new Bundle();
            bundle.putString("fdpath",feedbackpath);
            bundle.putString("fdname",feedbackname);
            intent.putExtras(bundle);
            startActivity(intent);
            About.this.finish();

          }
        });

        rate.setOnClickListener(new View.OnClickListener()
        {
          public void onClick(View v)
          {
            Intent intent = new Intent();
            intent.setClass(About.this, Aboutframe.class);
            Bundle bundle = new Bundle();
            bundle.putString("rpath",ratepath);
            bundle.putString("rname",ratename);
            intent.putExtras(bundle);
            startActivity(intent);
            About.this.finish();

          }
        });

        forum.setOnClickListener(new View.OnClickListener()
        {
          public void onClick(View v)
          {
            Intent intent = new Intent();
            intent.setClass(About.this, Aboutframe.class);
            Bundle bundle = new Bundle();
            bundle.putString("frpath",forumpath);
            bundle.putString("frname",forumname);
            intent.putExtras(bundle);
            startActivity(intent);
            About.this.finish();

          }
        });

        }
}
Aboutframe.java

public class Aboutframe extends Activity{

      private TextView namebar;
      private ImageButton likebutton;
      private ImageButton backbutton;
      private WebView aboutframe;
      private String lpath ;
      private String lname ;
      private String fqpath;
      private String fqname;
      private String frpath;
      private String frname;
      private String rpath; 
      private String rname;
      private String fdname;
      private String fdpath;


      @Override    
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.aboutframe);
          this.requestWindowFeature(Window.FEATURE_NO_TITLE);//remove title bar

          backbutton=(ImageButton) findViewById(R.id.back);
          likebutton=(ImageButton) findViewById(R.id.share);
          aboutframe =(WebView)findViewById(R.id.aboutframe);

          Intent intent=this.getIntent();
          Bundle bunde = intent.getExtras();

          lname = bunde.getString("lname");
          lpath = bunde.getString("lpath");
          fqname = bunde.getString("fqname");
          fqpath = bunde.getString("fqpath");
          frname = bunde.getString("frname");
          frpath = bunde.getString("frpath");
          rname = bunde.getString("rname");
          rpath = bunde.getString("rpath");
          fdname = bunde.getString("fdname");
          fdpath = bunde.getString("fdpath");

          if(lname != null&lpath!= null){
              namebar.setText(lname);
              aboutframe.setWebViewClient(new WebViewClient(){  
                  public boolean shouldOverrideUrlLoading(WebView view, String url) {  
                      view.loadUrl(lpath);  
                      return true; 
                  }
                  });  
          }
          if(fqname != null&fqpath!= null){
              namebar.setText(fqname);
              aboutframe.setWebViewClient(new WebViewClient(){  
                  public boolean shouldOverrideUrlLoading(WebView view, String url) {  
                      view.loadUrl(fqpath);  
                      return true; 
                  }
                  });  
          }
          if(frname != null&frpath!= null){
              namebar.setText(frname);
              aboutframe.setWebViewClient(new WebViewClient(){  
                  public boolean shouldOverrideUrlLoading(WebView view, String url) {  
                      view.loadUrl(frpath);  
                      return true; 
                  }
                  });  
          }
          if(rname != null&rpath!= null){
              namebar.setText(rname);
              aboutframe.setWebViewClient(new WebViewClient(){  
                  public boolean shouldOverrideUrlLoading(WebView view, String url) {  
                      view.loadUrl(rpath);  
                      return true; 
                  }
                  });  
          }
          if(fdname != null&fdpath!= null){
              namebar.setText(fdname);
              aboutframe.setWebViewClient(new WebViewClient(){  
                  public boolean shouldOverrideUrlLoading(WebView view, String url) {  
                      view.loadUrl(fdpath);  
                      return true; 
                  }
                  });  

              backbutton.setOnClickListener(new View.OnClickListener()
              {
                public void onClick(View v)
                {
                  Intent intent = new Intent();
                  intent.setClass(Aboutframe.this, About.class);
                  startActivity(intent);
                  Aboutframe.this.finish();

                }
              });

              likebutton.setOnClickListener(new View.OnClickListener()
              {
                public void onClick(View v)
                {
                  Intent intent = new Intent();
                  intent.setClass(Aboutframe.this, Renrenframe.class);
                  startActivity(intent);
                  Aboutframe.this.finish();

                }
              });
          }



}
}

该错误意味着您的活动超时

我不明白你为什么打电话:

aboutframe.setWebViewClient
多次。您可以尝试将
if的
替换为
if-else的

/*...*/
else if(frname != null&frpath!= null){
/*...*/
else if(rname != null&rpath!= null){
/*...*/

将所有代码放在

try
{
your Code here...
}
catch(NullPointerException e)
{
e.printStackTrace();
}

您最好使用
&
而不是
&
。后者是“二进制和”,您想使用“逻辑和”。

如果日志中没有打印它,您如何知道您得到了
NullPointerException
?如果我是您,我会仔细检查布局。在不同的布局文件中,对不同类型的视图使用相同的名称:在“关于您的背部”和“类似”按钮中,它们是一个
按钮
,但在“关于框架”中,它们是一个
图像按钮
。通过这种方式很容易得到运行时错误,特别是空指针。我在about.java而不是about.frame.java中得到了这个异常,我尝试了你的方法,但没有成功。有什么想法吗?谢谢