Java 为什么intent使我的应用程序崩溃?

Java 为什么intent使我的应用程序崩溃?,java,android,android-layout,android-activity,android-listview,Java,Android,Android Layout,Android Activity,Android Listview,我只是想问你为什么使用intent会让我的系统崩溃?我以前也用过同样的代码,而且很管用,但现在我再用一次就不行了。你觉得问题出在哪里 显示 <?xml version="1.0" encoding="utf-8"?> 第二个活动(如果我单击了主活动,我只希望此活动弹出) 希望一些专业人士能帮助我解决我的问题。有人说这很简单,但我无法解决,先生。您需要将登录活动添加到您的AndroidManifest.xml中,以便android操作系统可以找到意图引用的活动 <activit

我只是想问你为什么使用intent会让我的系统崩溃?我以前也用过同样的代码,而且很管用,但现在我再用一次就不行了。你觉得问题出在哪里

显示

<?xml version="1.0" encoding="utf-8"?>
第二个活动(如果我单击了主活动,我只希望此活动弹出)
希望一些专业人士能帮助我解决我的问题。有人说这很简单,但我无法解决,先生。

您需要将登录活动添加到您的
AndroidManifest.xml
中,以便android操作系统可以找到意图引用的活动

<activity
android:name=".Activities.Login"
android:label="Login" />

您确实需要向我们展示您的stacktrace,以获得有用的反馈。我怀疑您在
AndroidManifest.xml
中没有正确声明登录活动

LogCat将包含错误堆栈跟踪。您很可能会看到一大块红色文本,表示我们感兴趣的部分。下面是我的一个StackTrace示例。希望它能帮助你找到它

java.lang.RuntimeException:无法启动活动ComponentInfo{package.name.ThingDetailActivity}:java.lang.NullPointerException:尝试对空对象引用调用虚拟方法“long 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)

你能用stacktrace更新你的帖子吗?什么是stacktrace先生?我是初学者。你是说logcat?@Lawrence:
为什么intent会让我的应用程序崩溃?
哪个intent?是的,在你的logcat中,每当出现未捕获的异常或记录的异常时,它都会告诉你错误是什么,发生在哪里,有时还会提出修复建议。试着在你的日志中搜索“致命异常”@ρ∑ρєK看看我的主要活动,先生!我试图打开登录类,但它崩溃了。对了,先生!我正在尝试为我的thesishow is android:name=“.Activities.Login”开发一个移动杂货店应用程序,是否有帮助?没有这样的“.Activities.Login”活动,只需登录即可activity@Lawrence没有包含足够的信息(如包名),无法提供100%准确的答案。
.Activities.Login
是对活动类名称的最佳猜测(如果它存储在名为
Activities
的主java文件夹的子包中)。它很可能类似于
com.lawrence.activities.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);
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
        }
    });

}
<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" />
<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>
  .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
<activity
android:name=".Activities.Login"
android:label="Login" />