0

嘿,当我点击打开联系我们页面的某个按钮时,每个人都会遇到这种错误,请就我在这里面临的问题提出任何建议谢谢。这是错误和代码:

enter code here

11-15 19:31:24.890: E/AndroidRuntime(11445): FATAL EXCEPTION: main
11-15 19:31:24.890: E/AndroidRuntime(11445): java.lang.IllegalStateException: Could not        execute method of the activity
11-15 19:31:24.890: E/AndroidRuntime(11445):    at android.view.View$1.onClick(View.java:3044)
11-15 19:31:24.890: E/AndroidRuntime(11445):    at android.view.View.performClick(View.java:3511)
11-15 19:31:24.890: E/AndroidRuntime(11445):    at android.view.View$PerformClick.run(View.java:14105)
11-15 19:31:24.890: E/AndroidRuntime(11445):    at android.os.Handler.handleCallback(Handler.java:605)
11-15 19:31:24.890: E/AndroidRuntime(11445):    at android.os.Handler.dispatchMessage(Handler.java:92)
11-15 19:31:24.890: E/AndroidRuntime(11445):    at android.os.Looper.loop(Looper.java:137)
11-15 19:31:24.890: E/AndroidRuntime(11445):    at android.app.ActivityThread.main(ActivityThread.java:4575)
11-15 19:31:24.890: E/AndroidRuntime(11445):    at java.lang.reflect.Method.invokeNative(Native Method)
11-15 19:31:24.890: E/AndroidRuntime(11445):    at java.lang.reflect.Method.invoke(Method.java:511)
11-15 19:31:24.890: E/AndroidRuntime(11445):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
11-15 19:31:24.890: E/AndroidRuntime(11445):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
11-15 19:31:24.890: E/AndroidRuntime(11445):    at dalvik.system.NativeStart.main(Native Method)
11-15 19:31:24.890: E/AndroidRuntime(11445): Caused by: java.lang.reflect.InvocationTargetException
11-15 19:31:24.890: E/AndroidRuntime(11445):    at java.lang.reflect.Method.invokeNative(Native Method)
11-15 19:31:24.890: E/AndroidRuntime(11445):    at java.lang.reflect.Method.invoke(Method.java:511)
11-15 19:31:24.890: E/AndroidRuntime(11445):    at android.view.View$1.onClick(View.java:3039)
11-15 19:31:24.890: E/AndroidRuntime(11445):    ... 11 more
11-15 19:31:24.890: E/AndroidRuntime(11445): Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class <unknown>
11-15 19:31:24.890: E/AndroidRuntime(11445):    at android.view.LayoutInflater.createView(LayoutInflater.java:606)
11-15 19:31:24.890: E/AndroidRuntime(11445):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
11-15 19:31:24.890: E/AndroidRuntime(11445):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
11-15 19:31:24.890: E/AndroidRuntime(11445):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
11-15 19:31:24.890: E/AndroidRuntime(11445):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)

11-15 19:31:24.890: E/AndroidRuntime(11445): 在 android.view.LayoutInflater.inflate(LayoutInflater.java:489) 11-15 19:31:24.890: E/AndroidRuntime(11445): 在 android. view.LayoutInflater.inflate(LayoutInflater.java:396) 11-15 19:31:24.890: E/AndroidRuntime(11445): 在 android.view.LayoutInflater.inflate(LayoutInflater.java:352) 11-15 19:31: 24.890: E/AndroidRuntime(11445): 在 com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251) 11-15 19:31:24.890: E/AndroidRuntime(11445): 在 android.app .Activity.setContentView(Activity.java:1835) 11-15 19:31:24.890: E/AndroidRuntime(11445): 在 menu.project.ActivityMenu.openContactUsPage(ActivityMenu.java:204) 11-15 19:31:24.890 : E/AndroidRuntime(11445): ... 14 更多 11-15 19:31:24.890: E/AndroidRuntime(11445): 引起:java.lang.reflect。InvocationTargetException 11-15 19:31:24.890: E/AndroidRuntime(11445): 在 java.lang.reflect.Constructor.constructNative(Native Method) 11-15 19:31:24.890: E/AndroidRuntime(11445): at java. lang.reflect.Constructor.newInstance(Constructor.java:417) 11-15 19:31:24.890: E/AndroidRuntime(11445): 在 android.view.LayoutInflater.createView(LayoutInflater.java:586) 11-15 19: 31:24.890: E/AndroidRuntime(11445): ... 24 更多 11-15 19:31:24.890: E/AndroidRuntime(11445): 由: java.lang.OutOfMemoryError 11-15 19:31:24.890: E /AndroidRuntime(11445): 在 android.graphics.Bitmap.nativeCreate(Native Method) 11-15 19:31:24.890: E/AndroidRuntime(11445): 在 android.graphics.Bitmap.createBitmap(Bitmap.java:605) 11 -15 19:31:24.890: E/AndroidRuntime(11445): 在 android.graphics.Bitmap.createBitmap(Bitmap.java:551) 11-15 19:31:24.890: E/AndroidRuntime(11445): 在 android.graphics.Bitmap.createScaledBitmap(Bitmap.java:437) 11-15 19:31:24.890: E/AndroidRuntime(11445): 在android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:524) 11-15 19:31:24.890: E/AndroidRuntime(11445): 在 android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:499) 11-15 19: 31:24.890: E/AndroidRuntime(11445): 在 android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351) 11-15 19:31:24.890: E/AndroidRuntime(11445): 在 android.graphics.drawable.Drawable .createFromResourceStream(Drawable.java:773) 11-15 19:31:24.890: E/AndroidRuntime(11445): 在 android.content.res.Resources.loadDrawable(Resources.java:1995) 11-15 19:31:24.890 : E/AndroidRuntime(11445): 在 android.content.res.TypedArray.getDrawable(TypedArray.java:601) 11-15 19:31:24.890: E/AndroidRuntime(11445): 在 android.view.View.(View.java:2785) 11-15 19:31:24.890: E/AndroidRuntime(11445):在 android.view.ViewGroup.(ViewGroup.java:385) 11-15 19:31:24.890: E/AndroidRuntime(11445): 在 android.widget.LinearLayout.(LinearLayout.java:174) 11-15 19:31 :24.890: E/AndroidRuntime(11445): 在 android.widget.LinearLayout.(LinearLayout.java:170) 11-15 19:31:24.890: E/AndroidRuntime(11445): ... 27 更多LinearLayout.(LinearLayout.java:170) 11-15 19:31:24.890: E/AndroidRuntime(11445): ... 27 更多LinearLayout.(LinearLayout.java:170) 11-15 19:31:24.890: E/AndroidRuntime(11445): ... 27 更多

enter code here (Here is my java code )


   public class ActivityMenu extends Activity 
   {
@Override
public void onCreate(Bundle savedInstanceState) 
{
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    String error_msg = ClassGlobal.InitializeData(this, ActivityMenu.this);

    if (error_msg != null)
    {
        Toast.makeText(ActivityMenu.this, error_msg,            Toast.LENGTH_LONG).show();
        Log.w("error_msg", error_msg);
    }       

    initializeMenuPage();
}
@Override
public void onDestroy()
{
    super.onDestroy();
    ClassGlobal.closeMySQLiteHelper();
    optionImageList.clear();
    optionClickedImages.clear();
    adapterCusine = null;
}

//On Create menu
@Override
public boolean onCreateOptionsMenu(Menu menu) 
{
   getMenuInflater().inflate(R.menu.activity_main, menu);
   return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) 
    {
        case R.id.menu_settings:
            updateButton();
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
public void updateButton()
{
    boolean check = ClassGlobal.updateData(this, ActivityMenu.this);
    Toast.makeText(ActivityMenu.this, check ? "Updated successfully" : "Error in updating", Toast.LENGTH_SHORT).show();
}


//Menu Page
AdapterCusine adapterCusine;
List<Bitmap> optionImageList, optionClickedImages;
public void openMenuPage(View v)
{
    initializeMenuPage();
}
public void initializeMenuPage()
{
    setContentView(R.layout.menu);      
    ClassGlobal.DeliveryOnly = false;
    ClassGlobal.SearchCriteria = "";
    intializeCusineAdapter();
}
public void intializeCusineAdapter()
{   
    //Intialize cusine adapter
    final GridView restaurants = (GridView)findViewById(R.id.menu_datagridview);
    restaurants.setAdapter(ClassGlobal.cusineRestaurantsAdapters.get(ClassGlobal.currentSelectedCusine));
    restaurants.setOnItemClickListener(new OnItemClickListener()
    {
        public void onItemClick(AdapterView<?> adapter, View parent, int position, long id) 
        {
            ClassGlobal.currentSelectedRestaurant = position;
            Intent restaurantIntent = new Intent(getBaseContext(), ActivityCusineRestaurantDescription.class);
            startActivity(restaurantIntent);
        }
    });


    GridView cusine = (GridView)findViewById(R.id.cusine_datagridview);
    if (adapterCusine == null)
    {
        //Images for cusines
        String[] optionsImages = getResources().getStringArray(R.array.cusineImageButtons);
        String[] optionclickedImages = getResources().getStringArray(R.array.cusineSelectedImageButtons);

        //Get cusine images
        Resources res = getResources();
        optionImageList = null;
        optionClickedImages = null;
        optionImageList = new ArrayList<Bitmap>();
        optionClickedImages = new ArrayList<Bitmap>();
        for (int i = 0; i < optionsImages.length; i++)
            optionImageList.add(BitmapFactory.decodeResource(res, res.getIdentifier(optionsImages[i], "drawable", getPackageName())));
        for (int i = 0; i < optionclickedImages.length; i++)
            optionClickedImages.add(BitmapFactory.decodeResource(res, res.getIdentifier(optionclickedImages[i], "drawable", getPackageName())));
        adapterCusine = new AdapterCusine(ActivityMenu.this, optionImageList, optionClickedImages);

    }
    cusine.setAdapter(adapterCusine);
    cusine.setOnItemClickListener(new OnItemClickListener()
    {
        public void onItemClick(AdapterView<?> adapter, View parent, int position, long id) 
        {
            ClassGlobal.currentSelectedCusine = position;
            adapterCusine.notifyDataSetChanged();
            restaurants.setAdapter(ClassGlobal.cusineRestaurantsAdapters.get(position));
        }
    });

    final EditText restaurants_filter_editview = (EditText)findViewById(R.id.restaurants_filter_editview);
    TextWatcher tw = new TextWatcher() 
    {
        public void afterTextChanged(Editable s)
        {
            ClassGlobal.SearchCriteria = restaurants_filter_editview.getText().toString();
            Log.w("SearchCriteria", ClassGlobal.SearchCriteria);
            //Notify the current selected cusine
            ClassGlobal.cusineRestaurantsAdapters.get(ClassGlobal.currentSelectedCusine).notifyDataSetChanged();
        }
        public void  beforeTextChanged(CharSequence s, int start, int count, int after)
        {
          // you can check for enter key here
        }
        public void  onTextChanged (CharSequence s, int start, int before,int count) 
        {
        } 
    };
    restaurants_filter_editview.addTextChangedListener(tw);
}

//Delivery Page
public void openDeliveryPage(View v)
{
    initializeDeliveryPage();
}
public void initializeDeliveryPage()
{
    setContentView(R.layout.delevery);
    ClassGlobal.DeliveryOnly = true;
    ClassGlobal.SearchCriteria = "";
    intializeCusineAdapter();
}


//Promotion Page
public void openPromotionPage(View v)
{
    initializePromotionPage();
}
public void initializePromotionPage()
{
    setContentView(R.layout.promotion);
    intializePromotionAdapter();
}
public void intializePromotionAdapter()
{
    GridView promotion = (GridView)findViewById(R.id.Promotion_datagridview); 
    promotion.setAdapter(ClassGlobal.promotionAdapter);
    promotion.setOnItemClickListener(new OnItemClickListener()
    {
        public void onItemClick(AdapterView<?> adapter, View parent, int position, long id) 
        {
            ClassGlobal.currentSelectedRestaurant = position;
            Intent restaurantIntent = new Intent(getBaseContext(), ActivityPromotionRestaurantDescription.class);
            startActivity(restaurantIntent);
        }
    });
}

//Contact Us Page

public void openContactUsPage(View v)

{       
    setContentView(R.layout.contact_us);
    ImageButton fbib = (ImageButton)findViewById(R.id.facebook_button);
    fbib.setOnClickListener(new OnClickListener()
    {
        public void onClick(View arg0) 
        {
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/index.php?stype=lo&lh=Ac_XWoIk0pIrPD69"));
            startActivity(browserIntent);

        }
    });
    ImageButton twit = (ImageButton)findViewById(R.id.twitter);
    twit.setOnClickListener(new OnClickListener()
    {
        public void onClick(View arg0) 
        {
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com"));
            startActivity(browserIntent);

        }
    });
    ImageButton web = (ImageButton)findViewById(R.id.web);
    web.setOnClickListener(new OnClickListener()
    {
        public void onClick(View arg0) 
        {
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com.lb"));
            startActivity(browserIntent);

        }
    });
    ImageButton call = (ImageButton)findViewById(R.id.phone);
    call.setOnClickListener(new OnClickListener()
    {
        public void onClick(View arg0) 
        {
            Intent browserIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + 123456789));
            startActivity(browserIntent);

        }
    });
    ImageButton appwe = (ImageButton)findViewById(R.id.turn);
    appwe.setOnClickListener(new View.OnClickListener()
    {
        public void onClick(View arg0) 
        {
            Intent openAppWe = new Intent("menu.project.ACTIVITYAPPWE");
            startActivity(openAppWe);

        }
    });
}

//Favorite Page
public void openFavoritesPage(View v)
{
    initializeFavoritePage();
}
public void initializeFavoritePage()
{
    setContentView(R.layout.favorite);
    intializeFavoriteAdapter();
}
public void intializeFavoriteAdapter()
{
    GridView favorite = (GridView)findViewById(R.id.main_datagridview);

    favorite.setAdapter(ClassGlobal.favoriteAdapter);

    favorite.setOnItemClickListener(new OnItemClickListener()
    {
        public void onItemClick(AdapterView<?> adapter, View parent, int position, long id) 
        {
            ClassGlobal.currentSelectedRestaurant = position;
            Intent restaurantIntent = new Intent(getBaseContext(), ActivityFavoriteRestaurantDescription.class);
            startActivity(restaurantIntent);
        }
    });
}

}

enter code here


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
android:orientation="vertical"
android:scrollbars="vertical" >

<HorizontalScrollView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true"
    android:scrollbars="horizontal" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
        <GridView
            android:id="@+id/cusine_datagridview"
            android:layout_width="610dp"
            android:layout_height="wrap_content"
            android:listSelector="@android:color/transparent"
            android:clipChildren="true"
            android:clipToPadding="true"
            android:columnWidth="100dp"
            android:numColumns="8" >
        </GridView>
    </LinearLayout>
</HorizontalScrollView>

<EditText
    android:id="@+id/restaurants_filter_editview"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:singleLine="true"
    android:hint="Search By Name"
    android:ems="10" >
</EditText>

<GridView
    android:id="@+id/menu_datagridview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_centerInParent="true"
    android:layout_gravity="center"
    android:layout_weight="1.5"
    android:paddingTop="25dp"
    android:listSelector="@android:color/transparent"
    android:numColumns="3"
    android:paddingLeft="25dp"
    android:stretchMode="columnWidth"
    android:verticalSpacing="23.0dip" />

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="80dp"
    android:background="@drawable/redlowertab"
    android:baselineAligned="true"
    android:gravity="center"
    android:orientation="horizontal" >

    <ImageButton
        android:id="@+id/delevery_button"
        android:layout_width="45dp"
        android:layout_height="60dp"
        android:layout_gravity="center"
        android:layout_marginTop="7dp"
        android:layout_weight="0.30"
        android:background="@drawable/deliv"
        android:onClick="openDeliveryPage" />

    <ImageButton
        android:id="@+id/menu_button"
        android:layout_width="45dp"
        android:layout_height="60dp"
        android:layout_marginTop="7dp"
        android:layout_weight="0.30"
        android:background="@drawable/dine2"
        android:onClick="openMenuPage"
        android:text="Menu" />

    <ImageButton
        android:id="@+id/Promotion_button"
        android:layout_width="55dp"
        android:layout_height="73dp"
        android:layout_gravity="center"
        android:layout_marginBottom="5dp"
        android:layout_marginTop="7dp"
        android:layout_weight="0.30"
        android:background="@drawable/pro2"
        android:onClick="openPromotionPage"
        android:text="Promotion" />

    <ImageButton
        android:id="@+id/favorite_button"
        android:layout_width="45dp"
        android:layout_height="60dp"
        android:layout_gravity="center"
        android:layout_marginTop="7dp"
        android:layout_weight="0.30"
        android:background="@drawable/fav2"
        android:onClick="openFavoritesPage"
        android:text="Favorites" />

    <ImageButton
        android:id="@+id/contact_us_button"
        android:layout_width="45dp"
        android:layout_height="60dp"
        android:layout_gravity="center"
        android:layout_marginTop="7dp"
        android:layout_weight="0.30"
        android:background="@drawable/contact2"
        android:onClick="openContactUsPage"
        android:text="Contact Us" />
</LinearLayout>

4

1 回答 1

0

在扩展 XML 文件时,您的应用程序正在您的活动中搜索您未实现的方法。检查您的 XML 布局文件 (/layout/menu.xml)。可能有一个带有 onClick 属性的视图,例如:

android:onClick="onButtonClick"

你需要有:

public onButtonClick(View view) {

}

在你的活动中。考虑到onButtonClick只是一个示例,我的意思是您必须实现与 XML 文件中声明的名称相同的方法。

于 2012-11-15T18:02:10.260 回答