Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/217.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 无法启动活动组件信息:java空指针异常_Android_Android Intent - Fatal编程技术网

Android 无法启动活动组件信息:java空指针异常

Android 无法启动活动组件信息:java空指针异常,android,android-intent,Android,Android Intent,我遇到了无法启动活动组件信息的异常:java.nullpointer异常我已检查了所有代码,但无法解决错误 这是我的密码 public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.store_denomination); actionbar=getSupportActionBar(); acti

我遇到了无法启动活动组件信息的异常:java.nullpointer异常我已检查了所有代码,但无法解决错误

这是我的密码

    public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.store_denomination);
    actionbar=getSupportActionBar();
    actionbar.setDisplayShowHomeEnabled(false);
     actionbar.setDisplayShowTitleEnabled(false);
     actionbar.setDisplayShowCustomEnabled(true);
     actionbar1 = LayoutInflater.from(this).inflate(R.layout.action_custom, null);

    spin1 = (Spinner)findViewById(R.id.spin);   
    ProgressDialog progress = new ProgressDialog(this);
    progress.setMessage("Loading......");
    new MyClass(progress).execute();

    String urlvalue = ((MyApplication) getApplicationContext()).url;
    new DownloadImageTask().execute(urlvalue);




    youpaytxt = (TextView)findViewById(R.id.youpaytextview);  
    //name = (TextView)findViewById(R.id.nametextview);
    description = (TextView)findViewById(R.id.descriptiontextview);
    btncheckout = (Button)findViewById(R.id.checkoutbutton);
    edt = (EditText)findViewById(R.id.editText1);
    thumb_image = (ImageView)findViewById(R.id.imageView1);
    contshopping = (Button)findViewById(R.id.continueshoppingbutton);
    pg = (ProgressBar)findViewById(R.id.progressBar1);
    nametextview = (TextView)findViewById(R.id.nametextview);
    description = (TextView)findViewById(R.id.descriptiontextview);
    btnterms = (Button)findViewById(R.id.termsbutton);
    //termstxt=(TextView)findViewById(R.id.trmstxtview);
    //termstxt.setVisibility(termstxt.GONE);
    //termstxt.setTypeface(arial_font);

    description.setTypeface(arial_font);
    name = ((MyApplication) getApplicationContext()).nameofbrand;
    nametextview.setText(name);
    Typeface.createFromAsset(getAssets(), "fonts/arial.ttf");
    quant = String.valueOf(1);
    btn=(ImageButton)findViewById(R.id.cartbutton);
    if(!(((MyApplication)getApplicationContext()).cartproductsname).isEmpty())
    {
    btn.setOnClickListener(new OnClickListener() {          //error is coming here from logcat

        public void onClick(View v) {
            // TODO Auto-generated method stub
        Intent first=new     Intent(Detailsofproduct.this,CommentListActivity.class);   
        startActivity(first);
        }
    });
    }
这是我的日志

10-09 13:01:01.951: E/AndroidRuntime(2135): FATAL EXCEPTION: main
10-09 13:01:01.951: E/AndroidRuntime(2135): java.lang.RuntimeException: Unable to start   activity ComponentInfo{com.androidhive.xmlparsing/com.androidhive.xmlparsing.Detailsofproduct}: java.lang.NullPointerException
10-09 13:01:01.951: E/AndroidRuntime(2135):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
10-09 13:01:01.951: E/AndroidRuntime(2135):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
10-09 13:01:01.951: E/AndroidRuntime(2135):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
10-09 13:01:01.951: E/AndroidRuntime(2135):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
10-09 13:01:01.951: E/AndroidRuntime(2135):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-09 13:01:01.951: E/AndroidRuntime(2135):     at android.os.Looper.loop(Looper.java:123)
10-09 13:01:01.951: E/AndroidRuntime(2135):     at android.app.ActivityThread.main(ActivityThread.java:3683)
10-09 13:01:01.951: E/AndroidRuntime(2135):     at java.lang.reflect.Method.invokeNative(Native Method)
10-09 13:01:01.951: E/AndroidRuntime(2135):     at java.lang.reflect.Method.invoke(Method.java:507)
10-09 13:01:01.951: E/AndroidRuntime(2135):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-09 13:01:01.951: E/AndroidRuntime(2135):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-09 13:01:01.951: E/AndroidRuntime(2135):     at dalvik.system.NativeStart.main(Native Method)
10-09 13:01:01.951: E/AndroidRuntime(2135): Caused by: java.lang.NullPointerException
10-09 13:01:01.951: E/AndroidRuntime(2135):     at com.androidhive.xmlparsing.Detailsofproduct.onCreate(Detailsofproduct.java:209)
10-09 13:01:01.951: E/AndroidRuntime(2135):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-09 13:01:01.951: E/AndroidRuntime(2135):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
10-09 13:01:01.951: E/AndroidRuntime(2135):     ... 11 more
为什么我会出错。有什么帮助吗

  btn=(ImageButton)findViewById(R.id.cartbutton);

也许从它的起源处引用视图应该可以做到这一点

因为通常在调用
findViewbyId()
时,android只从
setContentView
中使用的xml中搜索元素,因为您使用的是操作栏视图,这应该会有所帮助

改变这个

  btn=(ImageButton)findViewById(R.id.cartbutton);

也许从它的起源处引用视图应该可以做到这一点


因为通常在调用
findViewbyId()
时,android只从
setContentView
中使用的xml中搜索元素,因为您使用的是操作栏视图,这应该会有所帮助

你确定你的store_面额.xml中有一个id为cartbutton的ImageButton吗?我已经在ActionBar的自定义视图中放置了我的图像按钮。你能告诉我你的第209行是什么吗???@kalpesh Lakhani btn.setonCLickLister。。。。我在我的代码中写了注释,这是我的第209行,所以你知道btn是空的,你试图解决这个问题的方法是什么?你确定你的store_面额.xml中有一个id为cartbutton的ImageButton吗?我已经在ActionBar的自定义视图中放置了我的图像按钮。你能告诉我你的第209行是什么吗???@kalpesh Lakhani btn.setonCLickLister。。。。我已经在我的代码中写了注释,这是我的第209行,所以,你知道btn是空的,你试图解决这个问题吗?@KalpeshLakhani谢谢你的支持:)。很高兴这是一件有用的破布。@KalpeshLakhani感谢您的支持:)。很高兴这是一块有用的破布。