java – 运行android应用程序错误(致命例外:主程序:PID:14099)

java – 运行android应用程序错误(致命例外:主程序:PID:14099),第1张

概述我有以下代码,并在运行App PLZ帮助我时出现以下错误 主要活动 package com.comp.easybuy.easybuy;import android.app.Activity;import android.support.v7.app.AppCompatActivity;import android.content.Context;import android.conten 我有以下代码,并在运行App PLZ帮助我时出现以下错误

主要活动

package com.comp.easybuy.easybuy;import androID.app.Activity;import androID.support.v7.app.AppCompatActivity;import androID.content.Context;import androID.content.Intent;import androID.support.v4.vIEw.PagerAdapter;import androID.support.v4.vIEw.VIEwPager;import androID.support.v7.app.AppCompatActivity;import androID.os.Bundle;import androID.vIEw.Menu;import androID.vIEw.MenuItem;import androID.vIEw.VIEw;import androID.vIEw.VIEw.OnClickListener;import androID.vIEw.VIEwGroup;import androID.Widget.Imagebutton;import androID.Widget.ImageVIEw;import static androID.net.Uri.parse;public class MainActivity extends Activity {    private Imagebutton callusphone;    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_main);        VIEwPager vIEwPager = (VIEwPager) findVIEwByID(R.ID.vIEw_pager);        ImagePagerAdapter adapter = new ImagePagerAdapter();        vIEwPager.setAdapter(adapter);        callusphone=(Imagebutton)findVIEwByID(R.ID.callus);        callusphone.setonClickListener(new OnClickListener() {            @OverrIDe            public voID onClick(VIEw v) {                Intent callintent = new Intent(Intent.ACTION_CALL,parse("tel:+962796880853"));                startActivity(callintent);            }        });    }    public voID flick(VIEw vIEw){        Intent bowsprit =new Intent(Intent.ACTION_VIEW,parse("http://www.facebook.com/ebuy2015/"));        startActivity(bowsprit);    }    public voID incline(VIEw vIEw){        Intent browbeaten =new Intent(Intent.ACTION_VIEW,parse("http://www.instagram.com/easy_buy_1/"));        startActivity(browbeaten);    }    private class ImagePagerAdapter extends PagerAdapter {        private int[] mImages = new int[] {                R.drawable.offer4,R.drawable.offer5,R.drawable.offer6,};        @OverrIDe        public int getCount() {            return mImages.length;        }        @OverrIDe        public boolean isVIEwFromObject(VIEw vIEw,Object object) {            return vIEw == object;        }        @OverrIDe        public Object instantiateItem(VIEwGroup container,int position) {            Context context = MainActivity.this;            ImageVIEw imageVIEw = new ImageVIEw(context);            int padding =context.getResources().                    getDimensionPixelSize(R.dimen.abc_switch_padding);            imageVIEw.setpadding(padding,padding,padding);            imageVIEw.setScaleType(ImageVIEw.ScaleType.FIT_XY);            imageVIEw.setimageResource(mImages[position]);            container.addVIEw(imageVIEw,0);            return imageVIEw;        }        @OverrIDe        public voID destroyItem(VIEwGroup container,int position,Object object) {            container.removeVIEw((ImageVIEw) object);        }        }    @OverrIDe    public boolean onCreateOptionsMenu(Menu menu) {        // Inflate the menu; this adds items to the action bar if it is present.        getMenuInflater().inflate(R.menu.menu_main,menu);        return true;    }    @OverrIDe    public boolean onoptionsItemSelected(MenuItem item) {        // Handle action bar item clicks here. The action bar will        // automatically handle clicks on the Home/Up button,so long        // as you specify a parent activity in AndroIDManifest.xml.        int ID = item.getItemID();        //noinspection SimplifiableIfStatement        if (ID == R.ID.action_settings) {            return true;        }        return super.onoptionsItemSelected(item);    }}

启动画面

package com.comp.easybuy.easybuy;import androID.app.Activity;import androID.content.Intent;import androID.os.Bundle;public class Splash extends Activity {    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        // Todo auto-generated method stub        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.splash);        Thread timerThread = new Thread(){            public voID run(){                try{                    sleep(3000);                }                catch(InterruptedException e){                    e.printstacktrace();                }                finally{                    Intent intent = new Intent(Splash.this,MainActivity.class);                    startActivity(intent);                }            }        };        timerThread.start();    }    @OverrIDe    protected voID onPause() {        // Todo auto-generated method stub        super.onPause();        finish();    }}

表现

<?xml version="1.0" enCoding="utf-8"?><manifest xmlns:androID="http://schemas.androID.com/apk/res/androID"    package="com.comp.easybuy.easybuy">    <uses-permission androID:name="ANDROID.PERMISSION.CALL_PHONE"/>    <application        androID:allowBackup="true"        androID:icon="@mipmap/ic_launcher"        androID:label="@string/app_name"        androID:theme="@style/Apptheme" >        <activity            androID:name=".Splash"            androID:label="@string/app_name">            <intent-filter>                <action androID:name="androID.intent.action.MAIN"/>                <category androID:name="androID.intent.category.LAUNCHER" />            </intent-filter>        </activity>        <activity            androID:name=".MainActivity"            androID:label="@string/app_name"            androID:exported="true">            <intent-filter>
                <action androID:name="androID.intent.action.MAIN" />

                <category androID:name="androID.intent.category.LAUNCHER" />
            </intent-filter>        </activity>    </application></manifest>

主要活动

<relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent" androID:paddingleft="@dimen/activity_horizontal_margin"    androID:paddingRight="@dimen/activity_horizontal_margin"    androID:paddingtop="@dimen/activity_vertical_margin"    androID:paddingBottom="@dimen/activity_vertical_margin">    <Imagebutton        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:ID="@+ID/imagebutton"        androID:onClick="flick"        androID:src="@drawable/fbook"        androID:layout_alignParentBottom="true"        androID:layout_alignParentRight="true"        androID:layout_alignParentEnd="false"        androID:scaleType="center"        androID:contentDescription="facebook Image button"        androID:layout_alignParentStart="false"        androID:theme="@style/Widget.AppCompat.ratingbar"        androID:visibility="visible" />    <Imagebutton        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:ID="@+ID/insta"        androID:onClick="incline"        androID:src="@drawable/inst"        androID:layout_alignParentBottom="true"        androID:layout_aligntop="@+ID/imagebutton"        androID:layout_alignParentEnd="false"        androID:layout_alignParentStart="false"        androID:scaleType="center"        androID:theme="@style/Widget.AppCompat.ratingbar"        androID:visibility="visible" />    <Imagebutton        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:ID="@+ID/callus"        androID:onClick="callusphone"        androID:src="@drawable/callus"        androID:layout_alignParentBottom="false"        androID:layout_centerHorizontal="true"        androID:layout_marginleft="145dp"        androID:layout_marginRight="145dp"        androID:layout_below="@+ID/vIEw_pager"        androID:layout_alignParentEnd="false"        androID:layout_alignParentStart="false"        androID:scaleType="center"        androID:theme="@style/Widget.AppCompat.ratingbar"        androID:visibility="visible" />    <androID.support.v4.vIEw.VIEwPager        androID:ID="@+ID/vIEw_pager"        androID:layout_wIDth="match_parent"        androID:layout_height="match_parent"        androID:layout_alignWithParentIfMissing="false"        androID:layout_gravity="right|left"        androID:visibility="visible"        androID:background="#ffffff"        androID:layout_alignParentRight="true"        androID:layout_alignParentEnd="true"        androID:layout_above="@+ID/imagebutton" /></relativeLayout>

并有错误

08-19 09:30:36.123  14099-14099/com.comp.easybuy.easybuy E/AndroIDRuntime﹕ FATAL EXCEPTION: main    Process: com.comp.easybuy.easybuy,PID: 14099    java.lang.IllegalArgumentException: Expected receiver of type com.comp.easybuy.easybuy.MainActivity,but got androID.vIEw.ContextthemeWrapper            at java.lang.reflect.Method.invoke(Native Method)            at androID.vIEw.VIEw$DeclaredOnClickListener.onClick(VIEw.java:4448)            at androID.vIEw.VIEw.performClick(VIEw.java:5199)            at androID.vIEw.VIEw$PerformClick.run(VIEw.java:21155)            at androID.os.Handler.handleCallback(Handler.java:739)            at androID.os.Handler.dispatchMessage(Handler.java:95)            at androID.os.Looper.loop(Looper.java:148)            at androID.app.ActivityThread.main(ActivityThread.java:5415)            at java.lang.reflect.Method.invoke(Native Method)            at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:725)            at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:615)
解决方法 首先声明您的图像按钮如下
imageFb=(Imagebutton)findVIEwByID(R.ID.imagebutton);        imageInsta=(Imagebutton)findVIEwByID(R.ID.insta);

并使用OnClickListener

imageFb.setonClickListener(new VIEw.OnClickListener() {            @OverrIDe            public voID onClick(VIEw v) {                flick(v);            }        });        imageInsta.setonClickListener(new VIEw.OnClickListener() {            @OverrIDe            public voID onClick(VIEw v) {                incline(v);            }        });

现在检查它应该工作!!你已经在xml中定义了你的onClick但没有使用它并将视图传递给方法,所以它崩溃了你的代码!

最终的MainActivity应该是这样的!

package com.comp.easybuy.easybuy;    import androID.app.Activity;    import androID.support.v7.app.AppCompatActivity;    import androID.content.Context;    import androID.content.Intent;    import androID.support.v4.vIEw.PagerAdapter;    import androID.support.v4.vIEw.VIEwPager;    import androID.support.v7.app.AppCompatActivity;    import androID.os.Bundle;    import androID.vIEw.Menu;    import androID.vIEw.MenuItem;    import androID.vIEw.VIEw;    import androID.vIEw.VIEw.OnClickListener;    import androID.vIEw.VIEwGroup;    import androID.Widget.Imagebutton;    import androID.Widget.ImageVIEw;    import static androID.net.Uri.parse;    public class MainActivity extends Activity {        private Imagebutton callusphone;        private Imagebutton imageFb;        private Imagebutton imageInsta;        @OverrIDe        protected voID onCreate(Bundle savedInstanceState) {            super.onCreate(savedInstanceState);            setContentVIEw(R.layout.activity_main);            VIEwPager vIEwPager = (VIEwPager) findVIEwByID(R.ID.vIEw_pager);            ImagePagerAdapter adapter = new ImagePagerAdapter();            vIEwPager.setAdapter(adapter);            callusphone=(Imagebutton)findVIEwByID(R.ID.callus);            imageFb=(Imagebutton)findVIEwByID(R.ID.imagebutton);            imageInsta=(Imagebutton)findVIEwByID(R.ID.insta);            callusphone.setonClickListener(new OnClickListener() {                @OverrIDe                public voID onClick(VIEw v) {                    Intent callintent = new Intent(Intent.ACTION_CALL,parse("tel:+962796880853"));                    startActivity(callintent);                }            });            imageFb.setonClickListener(new VIEw.OnClickListener() {                @OverrIDe                public voID onClick(VIEw v) {                    flick(v);                }            });            imageInsta.setonClickListener(new VIEw.OnClickListener() {                @OverrIDe                public voID onClick(VIEw v) {                    incline(v);                }            });        }        public voID flick(VIEw vIEw){            Intent bowsprit =new Intent(Intent.ACTION_VIEW,parse("http://www.facebook.com/ebuy2015/"));            startActivity(bowsprit);        }        public voID incline(VIEw vIEw){            Intent browbeaten =new Intent(Intent.ACTION_VIEW,parse("http://www.instagram.com/easy_buy_1/"));            startActivity(browbeaten);        }        private class ImagePagerAdapter extends PagerAdapter {            private int[] mImages = new int[] {                    R.drawable.offer4,};            @OverrIDe            public int getCount() {                return mImages.length;            }            @OverrIDe            public boolean isVIEwFromObject(VIEw vIEw,Object object) {                return vIEw == object;            }            @OverrIDe            public Object instantiateItem(VIEwGroup container,int position) {                Context context = MainActivity.this;                ImageVIEw imageVIEw = new ImageVIEw(context);                int padding =context.getResources().                        getDimensionPixelSize(R.dimen.abc_switch_padding);                imageVIEw.setpadding(padding,padding);                imageVIEw.setScaleType(ImageVIEw.ScaleType.FIT_XY);                imageVIEw.setimageResource(mImages[position]);                container.addVIEw(imageVIEw,0);                return imageVIEw;            }            @OverrIDe            public voID destroyItem(VIEwGroup container,Object object) {                container.removeVIEw((ImageVIEw) object);            }            }        @OverrIDe        public boolean onCreateOptionsMenu(Menu menu) {            // Inflate the menu; this adds items to the action bar if it is present.            getMenuInflater().inflate(R.menu.menu_main,menu);            return true;        }        @OverrIDe        public boolean onoptionsItemSelected(MenuItem item) {            // Handle action bar item clicks here. The action bar will            // automatically handle clicks on the Home/Up button,so long            // as you specify a parent activity in AndroIDManifest.xml.            int ID = item.getItemID();            //noinspection SimplifiableIfStatement            if (ID == R.ID.action_settings) {                return true;            }            return super.onoptionsItemSelected(item);        }    }
总结

以上是内存溢出为你收集整理的java – 运行android应用程序错误(致命例外:主程序:PID:14099)全部内容,希望文章能够帮你解决java – 运行android应用程序错误(致命例外:主程序:PID:14099)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1148256.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存