-9

It's hello world project.

content_main.xml =>

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.example.user.myapplication.MainActivity"
    tools:showIn="@layout/activity_main">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!" />
</RelativeLayout>

MainActivity.java=>

package com.example.user.myapplication;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
    }

    @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_main, 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);
    }
}

If i run the project, i see the black screen device. Can't see "Hello World!" string on that device. Why is this? It's Nexus 5 API 23 x86 . screenshot: enter image description here

From AVD window at bottom i see:

emulator: device fd:640

HAXM is not working and emulator runs in emulation mode

How can i fix it?

cola
  • 12,198
  • 36
  • 105
  • 165

10 Answers10

2

There are two parts to your question:

1. Emulator not working : HAXM is not working and emulator runs in emulation mode

This one is already answered here: How to fix: “HAX is not working and emulator runs in emulation mode”. It was just one search away.

AND

2. "Hello! World" not showing

That is because your emulator does not run at all. (Provided your code is sane) Just run it on your physical device (I hope you have one) and see if the string displays.

Just wondering, what so complex in this which made this question deserve a bounty? :)

Community
  • 1
  • 1
Viral Patel
  • 32,418
  • 18
  • 82
  • 110
1

If you're running it on a black background you can change the text colour to white.

<TextView
    android:textColor="@android:color/white"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!" />
1
android:textColor="#FFFFFF"

Add this line in your textView

Abhishek
  • 1,654
  • 2
  • 18
  • 31
  • 1
    Because the color of your background and text view both are black.. So if you will change the color your text view from black to white by adding this line in your Textview. It might work – Abhishek Jan 01 '16 at 05:19
1

Your code is doing setContentView to R.layout.activity_main (which seems to have things like a toolbar and fab button?!?) while the layout you are showing us with your hello world text is content_main.xml

Change this and see what happens:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.content_main);
}
jt-gilkeson
  • 2,661
  • 1
  • 30
  • 40
1

What is the name of your XML layout.Is it content_main.xml or activity_main.

If it is content_main.xml,you should do something like this

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.content_main);
    }
Birat Bade Shrestha
  • 800
  • 1
  • 8
  • 28
1

You are using content_main.xml layout instead of activity_main.xml.

It should be:

 setContentView(R.layout.content_main);
Héctor
  • 24,444
  • 35
  • 132
  • 243
0

Past this code in your mainatcivity

public class MainActivity   extends  Activity {

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

}   }

and below in activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:background="#fff"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
 >
 <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#000"
    android:layout_centerInParent="true"
    android:text="Hello World!" />
</RelativeLayout>
0

Your emulator is not working.

  1. This may help you. HAXM is not working and emulator runs in emulation mode

  2. on the other hands you should know this;

Important:

Intel HAXM cannot be used on systems without an Intel processor, or with an Intel processor that lacks the hardware features described in the "Hardware Requirements" section above. To determine the capabilities of your Intel processor, visit http://ark.intel.com/ Additionally, Intel HAXM can be used only with Android* x86 emulator images provided by Intel. 

Intel HAXM cannot be used with ARM* Android* emulator images or non-Intel x86 Android* emulator images. Source

  1. Then if it does not help you or your hardware not available for HAXM, you can try Genymotion.

* I recommend the 3rd. It works better than default about RAM using

Community
  • 1
  • 1
Kaloglu
  • 1,651
  • 1
  • 20
  • 31
0

You have created the "Blank Activity" from Android Studio, which has auto-generated all of this code for you. A lot of other answers here are targeting the implementation (confusion over activity_main.xml vs content_main.xml, or the unused fab, and so on). This code should work fine, despite being a little confusing for a newbie. If you haven't changed anything in the default code, then it's also not likely a color issue.

Looks like it's something to do with your emulator. Try creating a new emulator and run it. It should run just like a device, independent from your code. Verify the emulator works (or try another emulator, like Genymotion). When you know you have a good emulator, try running your code again. Android Studio should ask you which device (real or emulated) to run it on. You can also plug your device in to the computer and run your code on a real phone to verify it works.

travisa
  • 1,037
  • 9
  • 12
0

You are using wrong xml to set on the activity - MainActivity Instead of using - setContentView(R.layout.activity_main) write setContentView(R.layout.content_main) as content_main has your textView widget with a "Hello World" string in it.

After doing so you might get compilation errors on your activity as there are no FAB widget in content_main... so just remove that code of fab and all as you don't need it while showing the hello world example!

Avijeet
  • 1,031
  • 1
  • 10
  • 27