unique Fatal Exception: main (Unfortunately app has stopped error) [duplicate] - java

This question already has answers here:
NullPointerException accessing views in onCreate()
(13 answers)
Closed 8 years ago.
Edit: I changed my content view to setContentView(R.layout.fragment_main); the application still crashes. I do not quite understand the reason for this.
This is a simple application for detecting and counting the number of potholes felt on a road. I have read many threads on this issue and implemented many different changes to my code. But none seem to work out in fixing the error that I have. Where exactly am I going wrong in my code here?
MainActivity.java
package com.example.potholedetector;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity implements Button.OnClickListener {
// Private member field to keep track of the number of potholes
private static int num_potholes = 0;
#Override
protected void onCreate(Bundle savedInstanceState)
{
//Restore any saved state
super.onCreate(savedInstanceState);
//Set content view
setContentView(R.layout.activity_main);
//Initialize UI elements
final Button pothole = (Button)findViewById(R.id.pothole);
final TextView NumPotholes = (TextView)findViewById(R.id.NumPotholes);
//Link UI elements to actions in code
pothole.setOnClickListener(new Button.OnClickListener()
{
#Override
public void onClick(View v)
{
num_potholes++;
NumPotholes.setText("Number of potholes felt: " + num_potholes);
}
});
if (savedInstanceState == null)
{
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.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();
if (id == R.id.action_settings)
{
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment
{
public PlaceholderFragment()
{
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
return rootView;
/** Called when the user clicks the Pothole button */
}
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
fragment_main.xml
<LinearLayout 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:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.potholedetector.MainActivity$PlaceholderFragment" >
<TextView android:id="#+id/pothole_message"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="#string/pothole_message"
android:textSize="20sp"/>
<Button android:id="#+id/pothole"
android:layout_width="wrap_content"
android:minWidth="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/pothole"
android:onClick="potholeFelt"/>
<TextView android:id="#+id/NumPotholes"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textSize="20sp"/>
</LinearLayout>
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">PotholeDetector</string>
<string name="pothole_message">Pothole felt?</string>
<string name="pothole">Pothole</string>
<string name="action_settings">Settings</string>
<string name="title_activity_main">MainActivity</string>
</resources>
I tried to carefully follow many tutorials, but after spending so much time debugging, I am no closer to eradicating the error and moving on. How can I make this code work?

Your app is crashing for NPE, since you are passing as parameter R.layout.activity_main to setContentView, but the elements you are looking for are declared inside fragment_main.xml. Call setContentView(R.layout.fragment_main);

Related

Udacity Sunshine app-lesson 1

I'm going through the android dev training at udacity.com,following along with the implementation of sunshine app.I'm using android studio latest version for implementation.
I'm at the point to get where I'm supposed to get the mock listview and I am getting nothing on the screen and it was showing no errors.
Here is my mainActivity.java code
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment, new PlaceholderFragment())
.commit();
}
}
#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);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
String[] foreastarray={
"SUN-CLOUDY","MON-SUNNY","TUE-FOGGY","WED-CLOUDY","THU_ASTEROIDS","FRI-HEAVYRAIN","SAT-SUNNY"
};
List<String> weakforecast=new ArrayList<String>(Arrays.asList(foreastarray));
ArrayAdapter<String> mForecastAdapter=new ArrayAdapter<String>(getActivity(),
R.layout.list_item_forecast,weakforecast);
ListView listView=(ListView) rootView.findViewById(R.id.listview_forecast);
listView.setAdapter(mForecastAdapter);
return rootView;
}
}
}
Here is my content_main.xml code
<fragment 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:id="#+id/fragment"
android:name="com.example.android.sunshine.MainActivityFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:layout="#layout/fragment_main" />
Here is my fragment_main.xml code
<FrameLayout 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.android.sunshine.MainActivityFragment"
tools:showIn="#layout/activity_main">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/listview_forecast">
</ListView>
</FrameLayout>
Finally here is my list_item_forecast.xml code
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/list_item_forecast_textview"
android:gravity="center_vertical">
</TextView>
PLEASE HELP ME
You should take a look at the code here. The attached link is for the relevant branch.
In your content_main.xml, you should just have a FrameLayout, like this:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="#+id/container"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context=".MainActivity" tools:ignore="MergeRootFrame" />
By doing this everything will fall in place.
The reason you don't get to see anything is because the fragment is to be loaded into a container, which is usually a FrameLayout. When you call add(R.id.fragment, new PlaceholderFragment()), you actually add the fragment to the container whose id is passed in the first parameter, which as I said earlier is a FrameLayout. In your case, you are passing an id of a fragment, so it is unable to render inside it.
I believe your problem is that you actually create 2 fragments here, one declared in XML, and another (empty) one added dynamically (not correctly, as pointed out by Eric B. in his answer) at runtime which hides the first fragment.
You should try removing the transaction inside your activity's onCreate().
Declaring a fragment in XML: https://developer.android.com/training/basics/fragments/creating.html
Adding a fragment at runtime: https://developer.android.com/training/basics/fragments/fragment-ui.html

Overlapping fragments in activity

I have been learning android app development for a couple of days using the 'developer.android.com' tutorial. Currently I m learning the concept of fragments and frame-sets. I have written a hello world program using fragments. But the prob is that my fragment layout gets inserted in the fragment container twice and the result is 2 overlapped fragments in the frame-set. Can u please tell me why this happens and what is wrong with my code?
Below is my Home_page.java (the activity which contains the fragment_container)
package com.technology.computer.mit.ctechmit;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class Home_page extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_page);
// Create a new Fragment to be placed in the activity layout
Home_pageFragment firstFragment = new Home_pageFragment();
// In case this activity was started with special instructions from an
// Intent, pass the Intent's extras to the fragment as arguments
firstFragment.setArguments(getIntent().getExtras());
// Add the fragment to the 'fragment_container' FrameLayout
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_container, firstFragment).commit();
}
#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_home_page, 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);
}
}
Below is my Home_pageFragment.java (the fragment which is supposed to be inserted in the container)
package com.technology.computer.mit.ctechmit;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
/**
* A placeholder fragment containing a simple view.
*/
public class Home_pageFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_home_page, container, false);
}
}
Below is my activity_home_page.xml (fragment_container layout)
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/fragment_container"
android:name="com.technology.computer.mit.ctechmit.Home_pageFragment"
tools:layout="#layout/fragment_home_page"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Below is my fragment_home_page.xml (fragment layout)
<LinearLayout
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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:orientation="horizontal"
tools:context=".Home_pageFragment">
<TextView
android:text="#string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_send" />
</LinearLayout>
Can u please help me with this error?
Why is the fragment getting loaded twice in the home activity?
I am getting an overlapped hello world text.
It's simple. The layout you are inserting your Fragment is not a view that you are using as a Container. In fact, it's fragment itself.
So either use a FrameLayout as a fragment container, or keep the Fragment in your XML and do not call Fragment Manager to insert to this Fragment. I would suggest the first one.
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

Android tutorial issues [duplicate]

This question already has answers here:
ActionBarActivity cannot resolve a symbol
(4 answers)
Closed 8 years ago.
I've been working through an Android Application tutorial on the developer android site for quite a while, but I can't get it to work perfectly for the life of me. My DisplayMessageActivity.java is filled with errors (i.e. getting undefined methods and unresolved types) Here are my files...
MainActivity.java
package com.miller.lab3;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends Activity {
public final static String EXTRA_MESSAGE = "com.mycompany.myfirstapp.MESSAGE";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
/** Called when the user clicks the Send button */
public void sendMessage(View view) {
// Do something in response to button
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
}
DisplayMessageActivity.java
package com.miller.lab3;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
public class DisplayMessageActivity extends ActionBarActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the message from the intent
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
// Create the text view
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
// Set the text view as the activity layout
setContentView(textView);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
#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();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() { }
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_display_message,
container, false);
return rootView;
}
}
}
activity_main.xml
<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="${relativePackage}.${activityClass}" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_send"
android:onClick="sendMessage" />
<EditText
android:id="#+id/edit_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="#string/edit_message" />
</RelativeLayout>
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Lab3</string>
<string name="hello_world">Hello world!</string>
<string name="title_activity_display_message">My Message</string>
<string name="edit_message">Enter a message</string>
<string name="button_send">Send</string>
</resources>
I'm wondering if anyone sees anything out of the ordinary. It would be greatly appreciated if you could point it out. I heard that this may or may not be an outdated version of the tutorial and the fact that I must use eclipse to do it doesn't exactly help. Thanks in advance.
If anyone doesn't know what I'm talking about here is the tutorial link http://developer.android.com/training/basics/firstapp/starting-activity.html
You code seems correct. Try cleaning the project. Go to Project>Clean>Clean selected project.If this doesn't work as happens in some cases, try creating a new project. However, if this is a big project, this method is useless. In such cases, there is a much better solution to this. Make use of git which is a version control system that keeps your project super safe and clean.
You are not importing ActionBarActivity
Add to your imports in DisplayMessageActivity.java:
import android.support.v7.app.ActionBarActivity;
or click on ActionBarActivity and press ctrl+1, and click Import 'ActionBarActivity'

How do I make this into one activity?

I'm doing this tutorial, but I'm having some trouble with understanding how to make this into one activity. (In the tutorial, you would have Main Activity and Display Message Activity, but for my purposes, I need it to be in one activity) I understand how everything works, but I just can't figure out how to make this into one activity. Any help is appreciated!
Here is the tutorial I'm working on: https://developer.android.com/training/basics/firstapp/building-ui.html
And I'll include my code below, but it's probably easier to see where I am in the tutorial (I'm at the step, "Starting Another Activity").
fragment_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="horizontal">
<EditText android:id="#+id/edit_message"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="#string/edit_message" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_send"
android:onClick="sendMessage" />
</LinearLayout>
MainActivity.java
package com.example.helloworld;
import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.content.Intent;
import android.os.Build;
public class MainActivity extends Activity {
public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.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();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
return rootView;
}
}
public void sendMessage(View view) {
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
}
If you want to change the layout when a button is pressed and display hello world you can use your fragment PlaceholderFragment inside your MainActivity to display it
sample:
public void sendMessage(View view) {
getFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
Fragment:
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
TextView tx = (TextView)rootView.findViewById(R.id.hello_world);
tx.setText(editText.getText().toString());
return rootView;
}
}
In your fragment_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/start_screen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="#+id/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40sp"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>

Not finding ImageView?

I am trying to do something very basic and I cannot figure out why it will not find the ImageView from the Java code. When I type R.id.scanButton I get an error saying that resource does not exist.. but as you can see in my XML it has been created. What am I missing here?
MainActivity.java
package com.erinkabbash.coolmeter;
import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView button = (ImageView) findViewById(R.id.scanButton); // ImageView not Found
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.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();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
return rootView;
}
}
}
activity_main.xml
<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="com.erinkabbash.coolmeter.MainActivity$PlaceholderFragment" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:orientation="vertical" >
<TextView
android:id="#+id/resultView"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ImageView
android:id="#+id/scanButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/scanButton" />
</LinearLayout>
</RelativeLayout>
import R.java
com.erinkabbash.coolmeter.R; //Your.base.pkg.com.R /* You base package .R*/
And clean your project. it might be work,
If you working with your base package domain ,then there is no need of importing R.java. just Clean your project or workspace. . It will work.
Only use lowercase and underscore for res/, drawables/ and others res fies
There is nothing wrong in your code, You just need to Clean and Build your project to register your id that was added.
resultView and scanButton should be lower-cased to resultview and scanbutton. The R.java file is very picky about upper-case letters and special characters anywhere in your res folder.

Categories