我正在尝试为Android制作一个简单的启动器。但是当我从开始活动转移到MainActivity时,应用程序崩溃了

时间:2015-03-16 18:59:18

标签: java android android-activity

03-16 14:53:17.071:E / AndroidRuntime(1834):java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.slaunch / com.example.slaunch.MainActivity}:android.view。 InflateException:二进制XML文件行#154:错误膨胀类

XML文件

 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <GridLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#ff000000"
        android:columnCount="2"
        android:fitsSystemWindows="true"
        android:layoutMode="opticalBounds"
        android:orientation="vertical"
        android:rowCount="8" >

        <LinearLayout
            android:layout_gravity="fill_horizontal"
            android:orientation="vertical" >
        </LinearLayout>

        <ImageButton
            android:id="@+id/imageButton1"
            style="@style/AppTheme"
            android:layout_width="161dp"
            android:layout_height="161dp"
            android:layout_column="0"
            android:layout_gravity="left|top"
            android:layout_row="1"
            android:adjustViewBounds="true"
            android:contentDescription="TODO"
            android:padding="3dp"
            android:scaleType="fitCenter"
            android:src="@drawable/barcode" />

        <ImageButton
            android:id="@+id/imageButton3"
            android:layout_width="160dp"
            android:layout_height="160dp"
            android:layout_column="0"
            android:layout_gravity="right|top"
            android:layout_row="0"
            android:adjustViewBounds="true"
            android:padding="3dp"


            android:scaleType="fitCenter"
            android:src="@drawable/text" />
        <ImageButton
            android:id="@+id/imageButton9"
            android:layout_width="160dp"
            android:layout_height="160dp"
            android:layout_column="0"
            android:layout_gravity="right|top"
            android:layout_row="5"
            android:adjustViewBounds="true"
            android:padding="3dp"
            android:scaleType="fitCenter"
            android:src="@drawable/whatsapp" />
              <ImageButton
            android:id="@+id/imageButton10"
            android:layout_width="160dp"
            android:layout_height="160dp"
            android:layout_column="1"
            android:layout_gravity="center_horizontal|top"
            android:layout_row="5"
            android:adjustViewBounds="true"
            android:padding="3dp"
            android:scaleType="fitCenter"
            android:src="@drawable/skype" />

        <ImageButton
            android:id="@+id/imageButton5"
            android:layout_width="160dp"
            android:layout_height="160dp"
            android:layout_column="0"
            android:layout_gravity="left|top"
            android:layout_row="3"
            android:adjustViewBounds="true"
            android:padding="3dp"
            android:scaleType="fitCenter"
            android:src="@drawable/locationnotifier" />

        <ImageButton
            android:id="@+id/imageButton6"
            android:layout_width="160dp"
            android:layout_height="160dp"
            android:layout_column="1"
            android:layout_gravity="center_horizontal|top"
            android:layout_row="1"
            android:adjustViewBounds="true"
            android:padding="3dp"
            android:scaleType="fitCenter"
            android:src="@drawable/screenreading" />

        <ImageButton
            android:id="@+id/imageButton4"
            android:layout_width="160dp"
            android:layout_height="160dp"
            android:layout_column="1"
            android:layout_gravity="center_horizontal|top"
            android:layout_row="3"
            android:adjustViewBounds="true"
            android:padding="3dp"
            android:scaleType="fitCenter"
            android:src="@drawable/custombrowser" />

        <ImageButton
            android:id="@+id/imageButton2"
            android:layout_width="160dp"
            android:layout_height="160dp"
            android:layout_column="1"
            android:layout_gravity="center_horizontal|top"
            android:layout_row="0"
            android:adjustViewBounds="true"
            android:padding="3dp"
            android:scaleType="fitCenter"
            android:src="@drawable/call" />

        <ImageButton
            android:id="@+id/imageButton7"

            android:layout_width="160dp"
            android:layout_height="160dp"
            android:layout_column="1"
            android:layout_gravity="center_horizontal|top"
            android:layout_row="4"
            android:adjustViewBounds="true"
            android:padding="3dp"
            android:scaleType="fitCenter"
            android:src="@drawable/currencyrecognition" />
 <ImageButton
            android:id="@+id/imageButton11"

            android:layout_width="160dp"
            android:layout_height="160dp"
            android:layout_column="0"
            android:layout_gravity="center_horizontal|top"
            android:layout_row="6"
            android:adjustViewBounds="true"
            android:padding="3dp"
            android:scaleType="fitCenter"
            android:src="@drawable/settings" />

        <ImageButton
            android:id="@+id/imageButton8"
            android:layout_width="160dp"
            android:layout_height="160dp"
            android:layout_column="0"
            android:layout_gravity="center_horizontal|top"
            android:layout_row="4"
            android:adjustViewBounds="true"
            android:padding="3dp"
            android:scaleType="fitCenter"
            android:src="@drawable/colorrecognition" />
        <ImageButton
            android:id="@+id/imageButton12"
            android:layout_width="160dp"
            android:layout_height="160dp"
            android:layout_column="1"
            android:layout_gravity="center_horizontal|top"
            android:layout_row="6"
            android:adjustViewBounds="true"
            android:padding="3dp"
            android:scaleType="fitCenter"
            android:src="@drawable/app_drawer" />

    </GridLayout>

  </ScrollView>

主要活动.JAVA

package com.example.slaunch;

import android.app.ActionBar;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.net.Uri;
import android.view.Display;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageButton;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.content.Context;
import android.content.pm.PackageManager;
import android.widget.NumberPicker;



public class MainActivity extends Activity {


    public ImageButton caller;
    public ImageButton message;
    public ImageButton browser;
    public ImageButton setting;
    public ImageButton apps;
    public ImageButton barcodeScan;
    public ImageButton textspeech;
    public ImageButton skype;
    public ImageButton whatsapp;
    public ImageButton viber ;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
               requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        if(((myapp)getApplication()).getViewSize()==1)
        {
            setContentView(R.layout.activity_main); 
        }
        else if(((myapp)getApplication()).getViewSize()==2)
        {
            setContentView(R.layout.size_two);  
        }
        else if(((myapp)getApplication()).getViewSize()==3)
        {
            setContentView(R.layout.size_three);    
        }
        else if(((myapp)getApplication()).getViewSize()==4)
        {
            setContentView(R.layout.size_three);    
        }
        else if(((myapp)getApplication()).getViewSize()==5)
        {
            setContentView(R.layout.size_threebrown);   
        }
        else if(((myapp)getApplication()).getViewSize()==6)
        {
            setContentView(R.layout.largest_size);  
        }



         caller= (ImageButton)findViewById(R.id.imageButton2);
          caller.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                 // TODO Auto-generated method stub
                Intent intent = new Intent(Intent.ACTION_DIAL);
                intent.setData(Uri.parse("tel:0123456789"));
                startActivity(intent); 

            }
        });

          message= (ImageButton)findViewById(R.id.imageButton3);
          message.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                 // TODO Auto-generated method stub
                Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.setType("vnd.android-dir/mms-sms");


                //intent.setData(Uri.parse("content://sms/inbox"));
             startActivity(intent);

            }
        });
          browser= (ImageButton)findViewById(R.id.imageButton4);
          browser.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                 // TODO Auto-generated method stub
                Intent intent = new Intent("com.example.slaunch.WebBrowser");
            //intent.setType("vnd.android-dir/mms-sms");


                //intent.setData(Uri.parse("content://sms/inbox"));
             startActivity(intent);

            }
        });
          setting= (ImageButton)findViewById(R.id.imageButton11);
          setting.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                 // TODO Auto-generated method stub
                Intent intent = new Intent("com.example.slaunch.LauncherSettings");
            //intent.setType("vnd.android-dir/mms-sms");


                //intent.setData(Uri.parse("content://sms/inbox"));
             startActivity(intent);
                finish();
            }
        });
          apps= (ImageButton)findViewById(R.id.imageButton12);
          apps.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                 // TODO Auto-generated method stub
                Intent intent = new Intent("com.example.slaunch.applist");
            //intent.setType("vnd.android-dir/mms-sms");


                //intent.setData(Uri.parse("content://sms/inbox"));
             startActivity(intent);

            }
        });
          barcodeScan= (ImageButton)findViewById(R.id.imageButton1);
          barcodeScan.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                 // TODO Auto-generated method stub
            //  Intent intent = new Intent("com.example.slaunch.barcodeScan");
            //intent.setType("vnd.android-dir/mms-sms");


                //intent.setData(Uri.parse("content://sms/inbox"));
            // startActivity(intent);

            }
        });
          textspeech= (ImageButton)findViewById(R.id.imageButton6);
          textspeech.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                 // TODO Auto-generated method stub
                //Intent intent = new Intent("com.example.slaunch.textToSpeech");
            //intent.setType("vnd.android-dir/mms-sms");


                //intent.setData(Uri.parse("content://sms/inbox"));
            // startActivity(intent);

            }
        });
          skype= (ImageButton)findViewById(R.id.imageButton10);
          skype.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                 // TODO Auto-generated method stub
            //  Intent intent = new Intent("com.skype.raider");
            //intent.setType("vnd.android-dir/mms-sms");


                //intent.setData(Uri.parse("content://sms/inbox"));
            // startActivity(intent);

            }
        });


    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.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();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

0 个答案:

没有答案