This is the content of the file: MainActivity.xml
It was working good I clicked the button and it opened the camera application on my device ! But as soon as I added this lines:
int i = Camera.getNumberOfCameras(); TextView age = (TextView) findViewById(R.id.textView1); age.setText(i);Im getting the error on my device say nned to force close.
I tried also instead age.setText(I); this:
age.setText(Integer.toString(i));I tried instead of id.textView1 also id.button1 but not working.
This is the content of activity_main.xml file:
This is the only two files I did changes.
I can make I did that on button click it will open the camera application on my device ! but I can't find how to show a message also when I click the button that will show how many cameras I have on the device. Im getting on my device when clicking the button an error say need to force close it if I move this 3 lines of the numberofcameras it will work good again.
Code:
package com.example.camera_test;import android.os.Bundle;import android.annotation.SuppressLint;import android.app.Activity;import android.content.Intent;import android.hardware.Camera;import android.view.Menu;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.ImageView;import android.widget.TextView;public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button button = (Button) findViewById(R.id.button1); button.setOnClickListener(new OnClickListener() { @SuppressLint("NewApi") @Override public void onClick(View arg0) { // TODO Auto-generated method stub Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE ); int i = Camera.getNumberOfCameras(); TextView age = (TextView) findViewById(R.id.textView1); age.setText(i); startActivityForResult( intent, 0 ); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_main, menu); return true; }}
int i = Camera.getNumberOfCameras(); TextView age = (TextView) findViewById(R.id.textView1); age.setText(i);Im getting the error on my device say nned to force close.
I tried also instead age.setText(I); this:
age.setText(Integer.toString(i));I tried instead of id.textView1 also id.button1 but not working.
This is the content of activity_main.xml file:
Code:
<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" tools:context=".MainActivity" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="@string/hello_world" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_marginRight="45dp" android:layout_marginTop="62dp" android:text="Activate The Camera" /></RelativeLayout>
I can make I did that on button click it will open the camera application on my device ! but I can't find how to show a message also when I click the button that will show how many cameras I have on the device. Im getting on my device when clicking the button an error say need to force close it if I move this 3 lines of the numberofcameras it will work good again.