Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在我的android应用程序中显示黑屏-在Eclipse中_Java_Android_Xml_Development Environment - Fatal编程技术网

Java 在我的android应用程序中显示黑屏-在Eclipse中

Java 在我的android应用程序中显示黑屏-在Eclipse中,java,android,xml,development-environment,Java,Android,Xml,Development Environment,我是Android编程的初学者,我有一个大问题。 使用开发环境Eclispe。正在创建秒表应用程序,但是 始终在我的应用程序中只显示黑屏。由于我手机上的项目一开始是通过安卓系统连接的,所以ADB中只显示一个黑屏。我查看了这个站点上的一些线程,但我仍然不知道问题出在哪里 我的MainActivity.java文件: package cz.miegl.stopky; import android.app.Activity; import android.os.Bundle; import andr

我是Android编程的初学者,我有一个大问题。 使用开发环境Eclispe。正在创建秒表应用程序,但是 始终在我的应用程序中只显示黑屏。由于我手机上的项目一开始是通过安卓系统连接的,所以ADB中只显示一个黑屏。我查看了这个站点上的一些线程,但我仍然不知道问题出在哪里

我的MainActivity.java文件:

package cz.miegl.stopky;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.SystemClock;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {

    private TextView textTimer;
    private Button startButton;
    private Button pauseButton;
    private long startTime = 0L;
    private Handler myHandler = new Handler();
    long timeInMillies = 0L;
    long timeSwap = 0L;
    long finalTime = 0L;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        textTimer = (TextView) findViewById(R.id.textTimer);

        startButton = (Button) findViewById(R.id.btnStart);
        startButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                startTime = SystemClock.uptimeMillis();
                myHandler.postDelayed(updateTimerMethod, 0);

            }
        });

        pauseButton = (Button) findViewById(R.id.btnPause);
        pauseButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                timeSwap += timeInMillies;
                myHandler.removeCallbacks(updateTimerMethod);

            }
        });

    }

    private Runnable updateTimerMethod = new Runnable() {

        public void run() {
            timeInMillies = SystemClock.uptimeMillis() - startTime;
            finalTime = timeSwap + timeInMillies;

            int seconds = (int) (finalTime / 1000);
            int minutes = seconds / 60;
            seconds = seconds % 60;
            int milliseconds = (int) (finalTime % 1000);
            textTimer.setText("" + minutes + ":"
                    + String.format("%02d", seconds) + ":"
                    + String.format("%03d", milliseconds));
            myHandler.postDelayed(this, 0);
        }

    };

}
<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"
    android:background="@android:color/white" >
    <Button

    android:id="@+id/btnPause"
    android:layout_width="90dp"
    android:layout_marginLeft="20dp"
    android:layout_height="45dp"
    android:layout_centerVertical="true"
    android:layout_toRightOf="@+id/btnStart"
    android:text="Pauza" />

    <Button
    android:id="@+id/btnStart"
    android:layout_width="90dp"
    android:layout_height="45dp"

    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"
    android:layout_marginLeft="68dp"
    android:text="Start" />

    <TextView
    android:id="@+id/textTimer"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/btnPause"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="37dp"
    android:textSize="40sp"
    android:textColor="#000000"
    android:text="00:00:00" />

</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="cz.miegl.stopky"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="cz.miegl.stopky.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>
    </application>

</manifest>
我的活动\u main.xml文件:

package cz.miegl.stopky;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.SystemClock;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {

    private TextView textTimer;
    private Button startButton;
    private Button pauseButton;
    private long startTime = 0L;
    private Handler myHandler = new Handler();
    long timeInMillies = 0L;
    long timeSwap = 0L;
    long finalTime = 0L;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        textTimer = (TextView) findViewById(R.id.textTimer);

        startButton = (Button) findViewById(R.id.btnStart);
        startButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                startTime = SystemClock.uptimeMillis();
                myHandler.postDelayed(updateTimerMethod, 0);

            }
        });

        pauseButton = (Button) findViewById(R.id.btnPause);
        pauseButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                timeSwap += timeInMillies;
                myHandler.removeCallbacks(updateTimerMethod);

            }
        });

    }

    private Runnable updateTimerMethod = new Runnable() {

        public void run() {
            timeInMillies = SystemClock.uptimeMillis() - startTime;
            finalTime = timeSwap + timeInMillies;

            int seconds = (int) (finalTime / 1000);
            int minutes = seconds / 60;
            seconds = seconds % 60;
            int milliseconds = (int) (finalTime % 1000);
            textTimer.setText("" + minutes + ":"
                    + String.format("%02d", seconds) + ":"
                    + String.format("%03d", milliseconds));
            myHandler.postDelayed(this, 0);
        }

    };

}
<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"
    android:background="@android:color/white" >
    <Button

    android:id="@+id/btnPause"
    android:layout_width="90dp"
    android:layout_marginLeft="20dp"
    android:layout_height="45dp"
    android:layout_centerVertical="true"
    android:layout_toRightOf="@+id/btnStart"
    android:text="Pauza" />

    <Button
    android:id="@+id/btnStart"
    android:layout_width="90dp"
    android:layout_height="45dp"

    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"
    android:layout_marginLeft="68dp"
    android:text="Start" />

    <TextView
    android:id="@+id/textTimer"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/btnPause"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="37dp"
    android:textSize="40sp"
    android:textColor="#000000"
    android:text="00:00:00" />

</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="cz.miegl.stopky"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="cz.miegl.stopky.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>
    </application>

</manifest>

和我的AndroidManifest.xml文件:

package cz.miegl.stopky;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.SystemClock;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {

    private TextView textTimer;
    private Button startButton;
    private Button pauseButton;
    private long startTime = 0L;
    private Handler myHandler = new Handler();
    long timeInMillies = 0L;
    long timeSwap = 0L;
    long finalTime = 0L;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        textTimer = (TextView) findViewById(R.id.textTimer);

        startButton = (Button) findViewById(R.id.btnStart);
        startButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                startTime = SystemClock.uptimeMillis();
                myHandler.postDelayed(updateTimerMethod, 0);

            }
        });

        pauseButton = (Button) findViewById(R.id.btnPause);
        pauseButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                timeSwap += timeInMillies;
                myHandler.removeCallbacks(updateTimerMethod);

            }
        });

    }

    private Runnable updateTimerMethod = new Runnable() {

        public void run() {
            timeInMillies = SystemClock.uptimeMillis() - startTime;
            finalTime = timeSwap + timeInMillies;

            int seconds = (int) (finalTime / 1000);
            int minutes = seconds / 60;
            seconds = seconds % 60;
            int milliseconds = (int) (finalTime % 1000);
            textTimer.setText("" + minutes + ":"
                    + String.format("%02d", seconds) + ":"
                    + String.format("%03d", milliseconds));
            myHandler.postDelayed(this, 0);
        }

    };

}
<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"
    android:background="@android:color/white" >
    <Button

    android:id="@+id/btnPause"
    android:layout_width="90dp"
    android:layout_marginLeft="20dp"
    android:layout_height="45dp"
    android:layout_centerVertical="true"
    android:layout_toRightOf="@+id/btnStart"
    android:text="Pauza" />

    <Button
    android:id="@+id/btnStart"
    android:layout_width="90dp"
    android:layout_height="45dp"

    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"
    android:layout_marginLeft="68dp"
    android:text="Start" />

    <TextView
    android:id="@+id/textTimer"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/btnPause"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="37dp"
    android:textSize="40sp"
    android:textColor="#000000"
    android:text="00:00:00" />

</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="cz.miegl.stopky"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="cz.miegl.stopky.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>
    </application>

</manifest>

请帮帮我。我不知道该怎么办。谢谢大家!


请帮帮我!!!谢谢

现在看来,您正在将主要活动和主要片段混合在一起。我仍然不熟悉片段,但我非常确定在活动的OnCreate中,您希望调用

setContentView(R.id.activity_main)
然后在activity_main.xml中,引用片段


查看位于

的片段编程指南。您的activity\u main.xml文件中有一个framelayout。这是另一个视图的占位符,因此不显示任何内容。通常在使用片段时会使用此视图。但是,您没有使用片段


由于您是初学者,请将fragment_main的全部内容复制到activity_main.xml文件中。

谢谢。如何归档fragment_main.xml链接?我将fragment_main.xml的内容复制到了activity_main.xml,但仍然没有任何内容。还是黑屏。。。我该怎么办?抱歉,我注意到您在代码中引用了R.Layout.fragment\u main,请将其更改为R.Layout.activity\u main。您在setContentView中引用的视图将被膨胀。我想给出fragment_main.xml按钮,等等。。我应该在哪里给出?是的,我将代码路径更改为activity_main.xml,但仍然没有更改。我不知道该怎么办。