为什么故意让我的应用程序崩溃? [英] Why intent makes my application crashed?

查看:112
本文介绍了为什么故意让我的应用程序崩溃?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想问你,为什么使用意图使我系统崩溃?我用同样的codeS之前,它的工作原理,然后当我现在再次使用它不会。您如何看待这个问题的家伙?

I just want to ask you why using intent makes my system crashed? I've used same codes before and it works, then when I use it again now it won't. What do you think the problem guys?

清单

<?xml version="1.0" encoding="utf-8"?>

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

MainActivity

MainActivity

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

2日活动(如果我点击的主要活动,我只是希望这个活动POP)

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

}

MainActivity的XML

XML of MainActivity

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

的登录活动XML(第二活动)

XML of Login Activity (2nd Activity)

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

清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.admin.mobilegroceryapp" >

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

</manifest>

logcat的

logcat

  .085    2019-2087/? I/InputDispatcher﹕ Delivering touch to current input target: action: 0x0
09-29 01:54:28.085    2019-2087/? I/InputDispatcher﹕ Delivering touch to current input target: action: 0x0
09-29 01:54:28.085    2019-2087/? I/InputDispatcher﹕ Delivering touch to current input target: action: 0x0
09-29 01:54:28.085    2019-2087/? I/InputDispatcher﹕ Delivering touch to current input target: action: 0x0
09-29 01:54:28.085    2019-2087/? I/InputDispatcher﹕ Delivering touch to current input target: action: 0x0
09-29 01:54:28.190    2019-2088/? I/InputReader﹕ Touch event's action is 0x1 (deviceType=0) [pCnt=1, s=]
09-29 01:54:28.285  30351-30351/? I/dalvikvm﹕ Could not find method android.graphics.Bitmap.getAllocationByteCount, referenced from method com.facebook.imagepipeline.a.d.a.a
09-29 01:54:28.285  30351-30351/? W/dalvikvm﹕ VFY: unable to resolve virtual method 625: Landroid/graphics/Bitmap;.getAllocationByteCount ()I
09-29 01:54:28.285  30351-30351/? D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0006
09-29 01:54:28.355  30482-30482/? D/dalvikvm﹕ WAIT_FOR_CONCURRENT_GC blocked 0ms
09-29 01:54:28.355    2019-2074/? D/BatteryService﹕ update start
09-29 01:54:28.360    2019-2079/? D/KeyguardViewMediator﹕ setHidden false
09-29 01:54:28.360    1732-1732/? I/SurfaceFlinger﹕ id=13169 Removed TcreenSaver idx=4 MapSz=10

希望有亲帮我把我的问题。有人说,这很简单,但我不能分辨先生。

Hope some pro help me to my problem. Somebody says It's simple but I can't resolved sir.

推荐答案

您确实需要向我们展示你的堆栈跟踪任何有用的反馈。我怀疑你是不是宣布在登录活动的的Andr​​oidManifest.xml 正常。

You really need to show us your stacktrace for any useful feedback. I suspect you aren't declaring the Login activity in your AndroidManifest.xml correctly.

LogCat中会包含错误堆栈跟踪。最有可能你会看到红色文本将显示我们感兴趣的部分一个巨大的块。下面是我的踪迹的一个范例。希望它可以帮助你找到它。

LogCat will contain the error stacktrace. Most likely you will see a giant block of red text that will indicate the part we are interested in. Below is an example of one of my stacktraces. Hopefully it helps you find it.

了java.lang.RuntimeException:无法启动活动ComponentInfo {package.name.ThingDetailActivity}:显示java.lang.NullPointerException:尝试调用虚方法长com.package.api.model.Thing在一个空对象引用.getId()        在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)        在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)        在android.app.ActivityThread.access $ 800(ActivityThread.java:151)        在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1303)        在android.os.Handler.dispatchMessage(Handler.java:102)        在android.os.Looper.loop(Looper.java:135)        在android.app.ActivityThread.main(ActivityThread.java:5254)        在java.lang.reflect.Method.invoke(Method.java)        在java.lang.reflect.Method.invoke(Method.java:372)        在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:903)        在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

java.lang.RuntimeException: Unable to start activity ComponentInfo{package.name.ThingDetailActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'long com.package.api.model.Thing.getId()' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) at android.app.ActivityThread.access$800(ActivityThread.java:151) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Method.java) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

这篇关于为什么故意让我的应用程序崩溃?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆