-4

This is the code I am using

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

    showVoiceText.setText("I am working");
}

However it seems not to be called... It never displays "I am working"

This is my xml

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

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Core A.I."
    android:id="@+id/showVoiceOutput"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Enable voice control"
    tools:layout_editor_absoluteX="88dp"
    tools:layout_editor_absoluteY="167dp" />

</android.support.constraint.ConstraintLayout>

This is not my main activity, my main activity is just an intro playing a small mp4 file

This is the main activity code

package com.example.phoenix.coreai;


import android.content.Intent;
import android.net.Uri;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.VideoView;

public class MainActivity extends AppCompatActivity {

    VideoView view;
    private static int SPLASH_TIME_OUT = 2700;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        view = (VideoView) findViewById(R.id.videoView);
        videoPlay(view);
        new Handler().postDelayed(new Runnable(){
            @Override
            public void run(){
                Intent homeIntent = new Intent(MainActivity.this, HomeActivity.class);
                startActivity(homeIntent);
                finish();
            }
        },SPLASH_TIME_OUT);
    }

    public void videoPlay(View v){

        String videoPath = "android.resource://com.example.phoenix.coreai/" + R.raw.spashscreen;
        Uri uri = Uri.parse(videoPath);
        view.setVideoURI(uri);
        view.start();
    }
}

and this is the xml of the main activity

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:background="#000000"
    tools:context="com.example.phoenix.coreai.MainActivity">


    <VideoView
        android:id="@+id/videoView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_marginTop="-27dp"
        app:layout_constraintTop_toTopOf="parent"
        tools:layout_editor_absoluteX="0dp">

    </VideoView>


</LinearLayout>

I cannot debug the application through my mobile it has a custom rom and android studio wont recognize it

Let's assume that I would like to call this void from onCreate

private void musicScan(){
    File f = new File(path);
    File file[] = f.listFiles();
    fileArray = new String[file.length];
    for (int i = 0; i < file.length; ++i){
        fileArray[i] = file[i].getName();
    }
}

It does not seem to execute the void that I am calling

2 Answers2

0
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    TextView showVoiceText = (TextView) findViewById(R.id.showVoiceOutput);

    showVoiceText.setText("I am working");
}

[maybe you need to remove the first "TextView" if it is already declared in another place, but since we don't have the whole code...]

But still will be good to know how your main activity start/call this activity

Canato
  • 3,598
  • 5
  • 33
  • 57
  • @DrunkProgrammer you can try to debug using your cellphone. But I need to ask again, can you edit with the Main Activity code? – Canato Feb 10 '18 at 10:40
  • I added the Main Activity – DrunkProgrammer Feb 10 '18 at 12:40
  • So, you are sure that the Home Activity is showed after the video? And could you put the whole code for Home Activity (I should has asked before). And you really need to find a way to debug, even using your on cellphone. @DrunkProgrammer – Canato Feb 10 '18 at 15:45
  • I think that this is not the problem of my code... I am having a conflict error with media player – DrunkProgrammer Feb 10 '18 at 16:41
  • Remove the video and just make a startActivity call to test – Canato Feb 10 '18 at 17:06
  • @DrunkProgrammerwe have other problems, you have a activity result and playmusic functions in your homeActivity? Can you put the whole code? – Canato Feb 10 '18 at 17:08
  • The whole code is actually huge... It's about 600 lines – DrunkProgrammer Feb 10 '18 at 17:11
  • @DrunkProgrammer your problem became to complex, for help you it need to became more specific, now can be a lot of stuffs. You should try to learn how debug with the hardware that you have, you will need this now and in the future, sorry for not provide a better answer – Canato Feb 10 '18 at 17:13
0

I think the problem is that you declared a global TextView and called it showVoiceText but you never initialise it

the solution is to initialise it after the setContentView like the following:

showVoiceText=(TextView) findViewById(R.id.showVoiceOutput);
Ahmed Rajab
  • 603
  • 3
  • 10
  • 28
  • may be the background color is the same color of the font....in other words it is working but the similarity of the colors make it feel not – Ahmed Rajab Feb 11 '18 at 06:16