Android Studio Emulator error - java

I have a problem with android studio emulator. Every time I create my own activity, for example myscreen.xml, and in MainActivity.java I change this line of code
setContentView(R.layout.activity_main) into setContentView(R.layout.myscreen);
the emulator shows me the following error: "UNFORTUNATELY LAUNCHER HAS STOPPED TO WORK". But if I use my main activity, for example setContentView(R.layout.activity_main);, it works perfectly without an error.
I tried everything on Virtual Device: changing the ram size, VM heap, internal storage, SD card. Nothing works. How do I fix this?

As long as the layout of myscreen.xml is valid and it is contained within the app/res/layout/* folder the myscreen.xml layout should work.
If you would like further help, it would be useful to see both the activity.java in which the layout is being used and the myscreen.xml file.

Related

android studio shows me a error on the file section and I don't know how to fix it

I don't know why is this happening i am very new in Android Studio . the main reason was I took a button in my xml design view and make button named android :id="#+id/ backbutton" at first in my MainActivcity2.java was showing me error but although I run the app and it keeps working nicely . but the error keeps showing .
i changed the android id name on the button first and then I changed it couple of time but didn't work..

Android Studio: How do I fix my AVD termination issue?

Every time I run the android studio emulator, I get this error message:
"The emulator process for AVD Nexus_5X_API_32 has terminated".
I have tried numerous things. I've tried turning on Hyper-V. I've checked and I have plenty of disk space. I have HAXXM turned on. I am using the correct version of the API in the ADK Manager. I'm not sure what to do. Can someone help?
Solution for AVD terminated:
In directory C:\User\(your user name)\.android.
Add file AdvancedFeatures.ini, add 2 lines then save it.
Vulkan = off
GLDirectMem = on

Main activity code disappeared after a force laptop shut down

I was writing an app and I was in main activity (had written thousands of lines of codes). But when I wanted to shut down my laptop, it took a while so I had to push the power button to force a shut down. Then after a while, when I powered on my laptop again and opened Android Studio, all my main activity code was gone! It's so weird.
I can see in project folder that main activity has about 40kb size but it's all empty. So is there something wrong with Android Studio and can I fix it? If not, can I use some tools or tricks to get another version of my main activity file (like changing the last date modified to the one before it or something like that).
Try to right click on your MainActivity and choose Local History > Show history
Check if it is in your android studio history .

Android Emulator: Unable to start webcam to capture picture in emulator

I have created an armeabi API 21 emulator in the AVD manager in Android Studio, set it to use the webcam as a front camera, and launched it.
The problem is that it's not able to open it, as I'm getting this error:
emulator: ERROR: camera_device_start_capturing: VIDIOC_STREAMON on camera '/dev/video0' has failed: Timer expired
emulator: ERROR: _camera_client_query_start: Cannot start camera '/dev/video0' for NV21[640x480]: Inappropriate ioctl for device
How can I solve this?
The webcam works normally using other software. The operative system is Ubuntu 14.04.
In Android Studio, go to AVD Manager, click on edit (pencil) button in Actions. After that, in next appearing window, click on Advance settings, and then scroll down and in Camera options, select webcam for front and back.
To enable Camera in your Android Emulator, just add following highlighted code in your AVD’s config.ini file. You can find the config.ini file under your <userdirectory>/.android folder.
File: ~/.android/config.ini
hw.lcd.density=160<br>
skin.name=HVGA<br>
skin.path=platforms\android-9\skins\HVGA<br>
hw.cpu.arch=arm<br>
abi.type=armeabi<br>
vm.heapSize=24<br>
image.sysdir.1=platforms\android-9\images\<br>
hw.camera=yes<br>
sdcard.size=64M<br>
In case you don’t find the config.ini file or want to enable Camera support through Android SDK and AVD Manager do the following:
Open Android SDK and AVD Manager:
Add SD Card in AVD
In the SD Card setting, set the value for Size. To enable camera, the SD Card must be enabled in Emulator.
Add Camera Support in Hardware under AVD
Now under Hardware section, click New button to add Camera hardware. It will open following Dialog box. Select Camera support from the Property dropdown and click Ok.
Enable Camera Support in Hardware
The new hardware: Camera support is visible under Hardware section. Set its value to yes and save changes by pressing Edit AVD.
Save the changes and launch the emulator.
You can try to manually edit your AVD's configuration file under
~/.android/avd/yourAvdName/config.ini
by adding this line:
hw.camera=yes
UPDATE
You can try to specify the real resolution of your webcam:
hw.camera.maxHorizontalPixels=XXX
hw.camera.maxVerticalPixels=XXX
Keep in mind that the default value for maxHorizontalPixels is 640 and for maxVerticalPixels is 480, so chaning this values may help you to solve your issues.
I had a similar issue with a slightly different error message under OS X. I turned out that everything was ok but the emulator is crashing when the camera takes too much time to initialize.
I my case I ended up closing other applications and it worked. You may want to test in a more performant computer.
I had trouble getting the camera to work under the emulator (under linux), even after setting it up in AVD as instructed here. I was helped by noticing that the camera it was trying to use was /dev/video0, but the camera I wanted was /dev/video3. A quick swap...
mv /dev/video0 /dev/video4
mv /dev/video3 /dev/video0
...did the trick
Change /dev/video6 into /dev/video0

beginner issue ved java and android

I just started programming android apps with eclipse..
I try to follow this guide: http://developer.android.com/training/basics/firstapp/building-ui.html
but I can't get further than here..
When I run my app through my htc phone, it just shows an empty app....
Then I tried creating a totally new android application in eclipse, and as a standard, there is an app with a text writing "Hello world"..
And when I show my activity_main.xml in graphical layout, it shows an app with this text "hello world".... but still, when I run it through my htc, I still just get an empty app...
How can this be, what am I missing?
Thanks.
Edit: actually, the app on the phone is not totally empty... it does show the standard head-banner with the android logo and the name of my app. But no textview...
First close the version of application that is already running on the HTC device. OR best thing woulld be uninstall it and try again.
It should work
Also, set the content view
setContView(R.layout.your XML file name);
Your activity does not add any content to the window so therefore nothing is shown.
Seems like you already have the wizard-generated layouts in res/layout. Just add
setContentView(R.layout.activity_main);
to onCreate() where activity_main corresponds to res/layout/activity_main.xml and that layout file actually contains the UI you want displayed.
Also import your generated resource identifiers:
import com.example.nytapp.R;
You will also need to call the superclass onCreate() in your onCreate(). Add
super.onCreate(savedInstanceState);
as the first line in your onCreate().
The warning
ActivityManager: Warning: Activity not started, its current task has been brought to the front
is nothing to worry about - if you didn't change your code and try to run it, the app won't get reinstalled and launched but just an existing instance is brought to front.

Categories

Resources