繁体   English   中英

活动类别不是以活动开头

[英]Activity class not starting with activity

我有第一个活动,从另一个活动开始。

我创建了第二个:

  • 右键点击项目浏览器中的app
  • 新建>活动>空活动

有了这个,我在Java文件夹和activity_newActivity.xml获得了class文件

我在该活动中创建了一些东西,并在为什么尝试从class运行它们时为什么功能不起作用,但是我尝试在onCreate函数中添加Log.d("Testing", "TEST")以及发现的内容结果是它甚至没有运行它。 为什么会这样呢?

全班:

package rs.termodom.www.termodom;

import android.graphics.Point;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Display;
import android.widget.ImageView;
import android.widget.TextView;

public class pocetna extends AppCompatActivity {
    Display display;
    Point screenSize;
    TextView tp_txt;
    ImageView test;

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

        Log.d("PROBLEM", "PROBLEM");

        //==========================================================================================
        //==========================================================================================
        //==========================================================================================
        display = getWindowManager().getDefaultDisplay();
        display.getSize(screenSize);

        tp_txt = (TextView) findViewById(R.id.tp_txt);
        tp_txt.setText("StA");

        test = (ImageView)findViewById(R.id.akcija1_img);
        test.getLayoutParams().height = 150;
        test.getLayoutParams().width = screenSize.x;
        //==========================================================================================
        //==========================================================================================
        //==========================================================================================

    }
}

这是清单:

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

    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:hardwareAccelerated="false"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name=".pocetna"
            android:theme="@style/AppTheme.NoActionBar">
        </activity>
    </application>

</manifest>

和XML

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="rs.termodom.www.termodom.pocetna">

    <android.support.constraint.ConstraintLayout
        android:id="@+id/header"
        android:layout_width="0dp"
        android:layout_height="50dp"
        android:background="@android:color/holo_blue_light"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <TextView
            android:id="@+id/userName_txt"
            android:layout_width="151dp"
            android:layout_height="32dp"
            android:layout_marginLeft="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:text="KORISNIK 123"
            android:textSize="24sp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/tp_txt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:layout_marginRight="8dp"
            android:layout_marginTop="8dp"
            android:text="1600 TP"
            android:textColor="@android:color/holo_red_dark"
            android:textSize="24sp"
            android:textStyle="bold"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

    </android.support.constraint.ConstraintLayout>

    <android.support.constraint.ConstraintLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginTop="50dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <android.support.constraint.ConstraintLayout
            android:id="@+id/akcijaSlider"
            android:layout_width="411dp"
            android:layout_height="150dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <ImageButton
                android:id="@+id/akcija1_img"
                android:layout_width="268dp"
                android:layout_height="112dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="1.0"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintVertical_bias="0.0"
                app:srcCompat="@mipmap/ic_launcher" />

        </android.support.constraint.ConstraintLayout>

    </android.support.constraint.ConstraintLayout>

</android.support.constraint.ConstraintLayout>

我认为问题出在这里

display.getSize(screenSize);

screenSize对象未初始化。

尝试这个:

screenSize = new Point();
display = getWindowManager().getDefaultDisplay();
display.getSize(screenSize);

您是否在应用程序清单(AndroidManifest.xml)文件中注册了活动?

问题是我没有正确调用新活动。

我应该这样称呼它:

Intent myIntent = new Intent(getApplicationContext(), pocetna.class);
startActivity(myIntent);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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