致命异常:主android验证

致命异常:主android验证,android,validation,exception,main,fatal-error,Android,Validation,Exception,Main,Fatal Error,我有一个应用程序,我想在其中添加验证,但当我只运行验证页面时,它工作正常,但当我使用此页面时,它会给我错误。 我想我在添加imagebutton时犯了一个错误,通过它我调用了名为propertysearch的验证页面 import android.content.Intent; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.support.v4.view.ViewP

我有一个应用程序,我想在其中添加验证,但当我只运行验证页面时,它工作正常,但当我使用此页面时,它会给我错误。 我想我在添加imagebutton时犯了一个错误,通过它我调用了名为propertysearch的验证页面

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;

stacktrace显示在
ViewPagerStyle1Activity
的第32行有一个
NullPointerException
。看那条线是什么电话,你应该知道罪犯

您试图在版面
main
中查找
imageButton1
,但它实际上位于版面
layou\u-one
中。修复现在取决于您实际计划如何处理片段。您可以通过替换
setContentView(R.layout.main)将片段布局设置为
ViewPagerStyle1Activity
的布局带有
setContentView(R.layout.layout_one)
在其“
onCreate
方法中

更新:也许你应该先读一读关于Android的书,然后。这是非常基本的东西,如果你不进进出出地学习它,你就走不了多远

当然,如果您在片段中硬编码
findViewById
以返回
null
,则无法找到imageButton1

private ImageButton findViewById(int imagebutton1) {
    // TODO Auto-generated method stub
    return null;
}

但是我感觉到你真的不知道你到底在做什么。

logcat说什么?把你的logcat.02-28 14:00:32.844:E/AndroidRuntime(1136):致命异常:main 02-28 14:00:32.844:E/AndroidRuntime(1136):java.lang.RuntimeException:无法启动活动组件信息{com.newapp.Devyani/com.newapp.Devyani.ViewPagerStyle1Activity}:java.lang.NullPointerException 02-28 14:00:32.844:E/AndroidRuntime(1136):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)02-28 14:00:32.844:E/AndroidRuntime(1136):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)很抱歉,我对android非常陌生。请告诉我,我在哪里添加imagebutton是可以的。因为当我直接运行代码时,它工作正常。这应该是一个注释。我认为@Thrakbad是正确的,imageButton1没有在layout.xml中定义。请将button1重命名为imageButton1,或者其他方式。@KushalPratapSingh do实际上您有一个布局
main
?如果是这样,请在上面的问题中发布它,因为在
ViewPagerStyle1Activity
中,您有代码
setContentView(R.layout.main)
如果没有它,我们无法知道按钮是否已定义。是的,您是对的。imagebutton未在my.xml中定义,但我希望它位于layout_one文件中。请检查我正在更新我的问题。请检查我的layout_one文件plz。