简体   繁体   中英

Android studio crashing after Intent hit

I just want to ask you why Intenting activity makes my system crashed? I've created two layout, one of them named "MainActivity" and the other one named "Login". So in main activity there is a button, I just want to pop the Login activity after hitting that button. Because I want to view the list view I've been created to see if its right or wrong. The problem here is whenever I hit the button it always crashed. Somebody help me please.

MAIN ACTIVITY

public class MainActivity extends ActionBarActivity {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
        }

        public void okay(View view) {
            Intent i = new Intent(this, Login.class);
            startActivity(i);
}
@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;
}

LOGIN ###

public class Login extends ActionBarActivity {
ListView listView;
ArrayAdapter<String> adapter;
String[] grocery_categories = {"Beverages", "Bakery", "Canned Goods", "Condiments", "Dairy", "Snacks", "Frozen Foods",
                                "Meat", "Produce", "Cleaners", "Paper Goods", "Personal Care", "Others"};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    listView = (ListView) findViewById(R.id.list_view);
    adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, grocery_categories);
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> listView, View view, int position, long id) {
            String grocery = (String) listView.getAdapter().getItem(position);
            Intent intent = new Intent(listView.getContext(),Login.class);
            listView.getContext().startActivity(intent);
            //or create other intents here
        }
    });

}

MAIN ACTIVITY XML

<RelativeLayout 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"  tools:context=".MainActivity"
android:id="@+id/rl_main_activity">

<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/mobile_grocery_bckgrnd"
    android:src="@drawable/mobile_grocery"
    android:scaleType="centerCrop"
    />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="MOBILE GROCERY"
    android:id="@+id/mobile_grocery_app"
    android:textSize="45dp"
    android:textColor="#000000"
    android:gravity="center"

    android:textStyle="bold|italic"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Application"
    android:id="@+id/application"
    android:textColor="#000000"
    android:textSize="25dp"
    android:layout_below="@+id/mobile_grocery_app"
    android:layout_centerHorizontal="true" />

<EditText
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:id="@+id/username"
    android:layout_alignParentBottom="true"
    android:layout_alignRight="@+id/application"
    android:layout_alignEnd="@+id/application"
    android:layout_marginBottom="135dp"
    android:hint="Username"
    android:textColorHint="#000000"
    />

<EditText
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:id="@+id/password"
    android:layout_alignTop="@+id/username"
    android:layout_alignRight="@+id/username"
    android:layout_alignEnd="@+id/username"
    android:layout_marginTop="52dp"
    android:hint="Password"
    android:textColorHint="#000000"
    android:password="true" />

<Button
    style="?android:attr/buttonStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="OK"
    android:id="@+id/ok"
    android:layout_below="@+id/password"
    android:layout_alignLeft="@+id/application"
    android:layout_alignStart="@+id/application"
    android:onClick="okay" />

LOGIN

<RelativeLayout 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"
tools:context="com.example.admin.mobilegroceryapp.Login"
android:id="@+id/rl_login">

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/login_bckgrnd"
    android:src="@drawable/login_bckgrnd"
    android:scaleType="centerCrop"
    />

<ListView
    android:id="@+id/list_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">



</ListView>

LOGCAT

 09-30 11:10:39.957 2019-2210/? E/Watchdog﹕ !@Sync 8890 09-30 11:10:41.812 1735-19431/? E/OMXCodec﹕ [OMX.SEC.MP3.Decoder] err = -1011 09-30 11:10:41.882 1735-6638/? E/OMXCodec﹕ [OMX.SEC.MP3.Decoder] err = -1011 09-30 11:10:41.992 1735-20195/? E/OMXCodec﹕ [OMX.SEC.MP3.Decoder] err = -1011 09-30 11:10:42.117 1735-19431/? E/MP3Extractor﹕ Unable to resync. Signalling end of stream. 09-30 11:10:42.117 1735-19431/? E/OMXCodec﹕ [OMX.SEC.MP3.Decoder] err = -1011 09-30 11:10:42.192 1735-6638/? E/OMXCodec﹕ [OMX.SEC.MP3.Decoder] err = -1011 09-30 11:10:42.262 1735-20195/? E/OMXCodec﹕ [OMX.SEC.MP3.Decoder] err = -1011 09-30 11:10:45.782 14900-14900/? E/MtpServerJNI﹕ could not open MTP driver, errno: 2 09-30 11:10:45.787 14900-14917/? E/MtpServerJNI﹕ server is null in run 09-30 11:10:45.787 14900-14917/? E/MtpServerJNI﹕ server is null in cleanup 09-30 11:11:02.912 4074-4074/? E/MtpService﹕ In MTPAPP onReceive:android.intent.action.BATTERY_CHANGED 09-30 11:11:02.912 4074-4074/? E/MtpService﹕ battPlugged Type : 2 09-30 11:11:09.957 2019-2210/? E/Watchdog﹕ !@Sync 8891 09-30 11:11:15.392 14943-14943/? E/dalvikvm﹕ Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zza 09-30 11:11:16.807 14969-14969/? E/dalvikvm﹕ Could not find class 'com.google.android.gms.common.h.c', referenced from method com.google.android.gms.common.app.GmsApplication.onCreate 09-30 11:11:17.317 28048-28048/? E/AuthorizationBluetoothService﹕ Proximity feature is not enabled. 09-30 11:11:17.492 14969-14969/? E/dalvikvm﹕ Could not find class 'android.telecom.TelecomManager', referenced from method com.google.android.gms.wearable.service.ya 09-30 11:11:17.712 14969-14980/? E/dalvikvm﹕ Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.kz.a 09-30 11:11:17.757 14969-14980/? E/dalvikvm﹕ Could not find class 'android.os.UserManager', referenced from method com.google.android.gms.common.kz.j 09-30 11:11:17.872 14943-14943/? E/ConnectionService﹕ Failed to connect to GoogleApiClient: ConnectionResult{statusCode=API_UNAVAILABLE, resolution=null} 09-30 11:11:21.612 14943-15002/? E/GmsUtils﹕ Failed to connect to Google API client: ConnectionResult{statusCode=API_UNAVAILABLE, resolution=null} 09-30 11:11:39.962 2019-2210/? E/Watchdog﹕ !@Sync 8892 09-30 11:11:43.047 4074-4074/? E/MtpService﹕ In MTPAPP onReceive:android.intent.action.BATTERY_CHANGED 09-30 11:11:43.047 4074-4074/? E/MtpService﹕ battPlugged Type : 2 09-30 11:11:45.397 15132-15132/? E/Samsung TTS﹕ onLoadLanguage() - lang : eng, country : GBR, variant : 09-30 11:11:45.397 15132-15132/? E/Samsung TTS﹕ onIsLanguageAvailable() - lang : eng, country : GBR, variant : , iResult : 1 09-30 11:11:45.397 15132-15132/? E/Samsung TTS﹕ onLoadLanguage() - LANG_COUNTRY_AVAILABLE 09-30 11:11:45.397 15132-15132/? E/Samsung TTS﹕ onLoadLanguage() - lang : eng, country : GBR, variant : f01 09-30 11:11:45.687 15132-15132/? E/Samsung TTS﹕ onCreate() - Samsung TTS package (released - 2012.06.14) 09-30 11:11:45.687 15132-15132/? E/﹕ Samsung TTS Engine - initialize() : Samsung TTS Engine (released - 2012.07.11) 09-30 11:11:45.687 15132-15132/? E/﹕ Samsung TTS Engine - initialize() : ro.product.manufacturer - samsung 09-30 11:11:45.697 15132-15143/? E/Samsung TTS﹕ onLoadLanguage() - lang : eng, country : , variant : 09-30 11:11:45.697 15132-15143/? E/Samsung TTS﹕ onIsLanguageAvailable() - lang : eng, country : , variant : , iResult : 0 09-30 11:11:45.697 15132-15143/? E/Samsung TTS﹕ onLoadLanguage() - LANG_AVAILABLE 09-30 11:11:45.697 15132-15143/? E/Samsung TTS﹕ onLoadLanguage() - lang : eng, country : USA, variant : f01 09-30 11:11:45.847 15132-15144/? E/Samsung TTS﹕ onIsLanguageAvailable() - lang : eng, country : , variant : , iResult : 0 09-30 11:12:09.962 2019-2210/? E/Watchdog﹕ !@Sync 8893 09-30 11:12:22.132 15191-15234/? E/dalvikvm﹕ Could not find class 'android.telephony.CellInfoCdma', referenced from method com.facebook.common.hardware.CellDiagnosticsSerializer.c 09-30 11:12:23.157 4074-4074/? E/MtpService﹕ In MTPAPP onReceive:android.intent.action.BATTERY_CHANGED 09-30 11:12:23.157 4074-4074/? E/MtpService﹕ battPlugged Type : 2 09-30 11:12:27.297 15191-15191/? E/dalvikvm﹕ Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.GooglePlayServicesUtil.a 09-30 11:12:29.802 15191-15191/? E/dalvikvm﹕ Could not find class 'com.facebook.push.adm.ADMBroadcastReceiver', referenced from method com.facebook.push.adm.ADMPushManager.b 09-30 11:12:31.892 2019-2087/? E/InputDispatcher﹕ channel ~ Channel is unrecoverably broken and will be disposed! 09-30 11:12:32.182 2019-2087/? E/InputDispatcher﹕ Received spurious receive callback for unknown input channel. fd=217, events=0x9 09-30 11:12:33.812 15191-15300/? E/fb4a(:<default>):VaultDeviceSetup﹕ setupDeviceFromServer 

MANIFEST

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
    android:name=".MainActivity"
    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=".Login"
    android:label="@string/title_activity_login" >
</activity>

Try this code

public void okay(View view) {
        Intent i = new Intent(MainActivity.this, Login.class);
        startActivity(i);
} 

在崩溃日志中可以看到,清单文件中有一些权限。请确保已在清单文件中添加了所有必需的权限和活动。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM