簡體   English   中英

意圖擊中后Android Studio崩潰

[英]Android studio crashing after Intent hit

我只想問你為什么Intenting活動會使我的系統崩潰? 我創建了兩個布局,其中一個名為“ MainActivity”,另一個名為“ Login”。 因此,在主要活動中有一個按鈕,我只想在單擊該按鈕后彈出“登錄”活動。 因為我想查看列表視圖,所以創建它是為了查看它是對還是錯。 這里的問題是,每當我按下按鈕時,它總是崩潰。 請有人幫我。

主要活動

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;
}

登錄 ###

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
        }
    });

}

主要活動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" />

登錄

<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 

表現

<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>

試試這個代碼

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

在崩潰日志中可以看到,清單文件中有一些權限。請確保已在清單文件中添加了所有必需的權限和活動。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM