java - 应用程序运行时不显示任何内容

标签 java android xml android-intent android-studio

我才使用 android studio 一天。我必须为我的学校项目创建一个应用程序,我做到了,我在 android studio 中对其进行了编程,并且没有错误。请帮忙, 这是名为 frontpagee 的主要 Activity

package com.example.lenovo.shop_easy;

import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

public class frontpagee extends Activity

{
 public void sendMessage(View view){
    Intent intent = new Intent(frontpagee.this, catalog.class);
    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.menu_frontpagee, 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();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

}

XML 是这样的

我想从此 Activity 移至名为 Catalog 的第二个 Activity java是

package com.example.lenovo.shop_easy;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

public class catalog extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_catalog);
}

@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_catalog, 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();

    //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

public void sendMessage(View view) {
    Intent intent = new Intent(catalog.this, product1.class);
    startActivity(intent);
}
public void sendMessage1(View view) {
    Intent intent = new Intent(catalog.this, PRODUCT2.class);
    startActivity(intent);
}
public void sendMessage2(View view) {
    Intent intent = new Intent(catalog.this, PRODUCT3.class);
    startActivity(intent);
}
public void sendMessage3(View view) {
    Intent intent = new Intent(catalog.this, product4.class);
    startActivity(intent);
}
public void sendMessage4(View view) {
    Intent intent = new Intent(catalog.this, product5.class);
    startActivity(intent);
}
public void sendMessage5(View view) {
    Intent intent = new Intent(catalog.this, product6.class);
    startActivity(intent);
}
public void sendMessage6(View view) {
    Intent intent = new Intent(catalog.this, product7.class);
    startActivity(intent);
}
public void sendMessage7(View view) {
    Intent intent = new Intent(catalog.this, product8.class);
    startActivity(intent);
}
public void sendMessage8(View view) {
    Intent intent = new Intent(catalog.this, product9.class);
    startActivity(intent);
}
public void sendMessage9(View view) {
    Intent intent = new Intent(catalog.this, product10.class);
    startActivity(intent);
}

}




   <FrameLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 android:paddingBottom="@dimen/activity_vertical_margin"                            tools:context=".frontpagee"
    android:background="@drawable/back">

    <ImageView
    android:layout_width="472dp"
    android:layout_height="500dp"
    android:id="@+id/imageView11"
    android:src="@mipmap/cover"
    android:layout_gravity="center_horizontal|top"
    android:contentDescription="@string/content" />

    <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/text12"
    android:id="@+id/button11"
    android:layout_gravity="center_horizontal|bottom"
    android:textSize="@dimen/size2"
    android:clickable="true"
    android:onClick="sendMessage"/>

    </FrameLayout>

android studio 说代码是正确的,但是当我在手机上运行 adb 时,它会安装应用程序,一切正常,但是当我打开应用程序时,它只显示应用程序图标和顶部的名称,没有其他内容去做。请帮忙

这里还有主要的 xml 文件

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

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".frontpagee"
        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=".catalog"
        android:label="@string/title_activity_catalog" >
    </activity>
    <activity
        android:name=".product1"
        android:label="@string/title_activity_product1" >
    </activity>
    <activity
        android:name=".PRODUCT2"
        android:label="@string/title_activity_product2" >
    </activity>
    <activity
        android:name=".PRODUCT3"
        android:label="@string/title_activity_product3" >
    </activity>
    <activity
        android:name=".product4"
        android:label="@string/title_activity_product4" >
    </activity>
    <activity
        android:name=".product5"
        android:label="@string/title_activity_product5" >
    </activity>
    <activity
        android:name=".product6"
        android:label="@string/title_activity_product6" >
    </activity>
    <activity
        android:name=".product7"
        android:label="@string/title_activity_product7" >
    </activity>
    <activity
        android:name=".product8"
        android:label="@string/title_activity_product8" >
    </activity>
    <activity
        android:name=".product9"
        android:label="@string/title_activity_product9" >
    </activity>
    <activity
        android:name=".product10"
        android:label="@string/title_activity_product10" >
    </activity>
</application>


</manifest>

该做什么

最佳答案

您尚未重写 class frontpagee 中的 onCreate(Bundle savingInstance) 方法,也未调用 setContentView(R.layout...) 在其中。

关于java - 应用程序运行时不显示任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32420851/

相关文章:

来自套接字的 Java 堆内存错误

python - Odoo 9 空 TreeView

php - 第 1 行第 3 列错误 : xmlParsePI : no target name

python - 在django中解析xml文件

java - 如何从 Java 连接到需要 Windows 客户端身份验证的 REST 服务?

java - Java 中的 Oracle 数据库 BLOB 到 InputStream?

java - 没有谷歌凭据的 Firebase 云消息传递

android - 如何在 kotlin Activity 中获取 ListPreference 值

android - ListView中图片的延迟加载

android - 如何在 Android Jetpack Compose 中创建任意方向的拖动手势