I'm pretty new to android and was wondering how I could add some type of functionality to and ImageView is I press it. My current code in my activity java file is as follows
package com.example.crystalbabyheaven;
import android.app.Activity;
import android.util.Log;
import android.view.*;
import android.view.View.OnTouchListener;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ScrollView;
import android.widget.ImageView;
public class MainActivity extends Activity implements Runnable {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ScrollView sv = (ScrollView) findViewById(R.id.ScrollView);
Handler h = new Handler();
h.postDelayed(new Runnable() {
#Override
public void run() {
sv.scrollTo(0, 8000);
}
}, 100);
ImageView player = new ImageView(this);
player.setImageDrawable(getResources().getDrawable(R.drawable.crystalbaby));
player.setOnTouchListener(new OnTouchListener(){
#Override
public boolean onTouch(View v, MotionEvent event){
sv.scrollTo(0, 5000);
return true;
}
});
}
#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 void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
ScrollView sv = (ScrollView) findViewById(R.id.ScrollView);
sv.scrollTo(300, 300);
}*/
#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);
}
#Override
public void run() {
// TODO Auto-generated method stub
}
}
And here is my XML:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainLayout"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.crystalbabyheaven.MainActivity" >
<ScrollView
android:id = "#+id/ScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="#drawable/bg" />
</ScrollView>
<ImageView
android:id="#+id/crystalBaby"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_gravity="bottom"
android:src="#drawable/crystalbaby" />
</FrameLayout>
I have a very large image that starts from a picture of the earth and scrolls upward through the atmosphere into space. I have another image view on top of this background. The first portion of my code in onCreate sets the scrollview view to the bottom of the image. What I want to do in this case is scroll approximately to the middle of the image when I press the image in the corner. I actually want something different, but I want to test this before anything. Is there something wrong in my code? I'm at a loss.
You're creating an ImageView player, but this is not the same as the imageview in your xml. Why not do: Imageview player = (ImageView)findViewById(R.id.imageview_player)
and in your xml, put android:id="#+id/imagview_player" inside the imageview.
Or if you must create the imageview programatically, then add it to your layout. You are not adding it to your layout anywhere in the code.
Related
I'm working on a course list app which loads each course title together with the course image in a listview through ArrayAdapter, I want to implement asynctask for loading of images in between listview and ArrayAdapter because the listview is lagging while scrolling, Please Help me.
MainActivity.java
package com.emmakade.okt;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
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.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.List;
public class MainActivity extends AppCompatActivity {
protected List<Course> data;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
data = DataProvider.getData();
ArrayAdapter<Course> courseArrayAdapter =
new CourseArrayAdapter(this, 0, data);
ListView listView = (ListView) findViewById(android.R.id.list);
listView.setAdapter(courseArrayAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Course course = data.get(position);
displayDetail(course);
}
});
}
#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);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == DETAIL_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
String msg = data.getStringExtra("resultMessage");
Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
}
}
}
class CourseArrayAdapter extends ArrayAdapter<Course>{
Context context;
List<Course> objects;
public CourseArrayAdapter(Context context, int resource, List<Course> objects) {
super(context, resource, objects);
this.context = context;
this.objects = objects;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
Course course = objects.get(position);
LayoutInflater inflater =
(LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.course_item, null);
TextView tv = (TextView) view.findViewById(R.id.tvTitle);
tv.setText(course.getTitle());
ImageView iv = (ImageView) view.findViewById(R.id.imageCourse);
int res = context.getResources().getIdentifier(
"image_" + course.getCourseNumber(), "drawable",
context.getPackageName()
);
iv.setImageResource(res);
return view;
}
}
}
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"
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=".MainActivity">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageLogo"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:src="#drawable/academy"/>
<TextView
android:id="#+id/txtOutput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/course_catalog"
android:layout_alignBottom="#+id/imageLogo"
android:layout_toEndOf="#+id/imageLogo"
android:layout_marginStart="20dp"
android:layout_marginBottom="15dp"
android:textSize="28sp" />
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#android:id/list"
android:layout_below="#+id/imageLogo"
android:layout_marginTop="10dp"
android:layout_alignParentStart="true" />
</RelativeLayout>
course_item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/imageCourse" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tvTitle"
android:layout_toEndOf="#+id/imageCourse"
android:layout_marginStart="10dp"
android:textSize="18sp"/>
</RelativeLayout>
enter image description here
I recommend you to use Glide library for asynchronous image loading, caching and displaying.
Add Dependency
implementation 'com.github.bumptech.glide:glide:4.5.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.5.0'
Use like this in adapter
Glide.with(this).load("url").into(imageView);
ImageView iv = (ImageView) view.findViewById(R.id.imageCourse);
int res = context.getResources().getIdentifier(
"image_" + course.getCourseNumber(), "drawable",
context.getPackageName()
);
Glide.with(this).load(res).into(iv);
You can use handler because asynctask will work on another thread but you cant update ui from another thread instead of main thread. Also consider to use glide, picasso like libraries. These libraries caches images efficiently and works with more performence.
There is an example with Handler.
Handler handler = new Handler();
handler.post(() -> {
profilephoto.setImageBitmap(pp);
});
I am following this tutorial into making an app for Android and ran into a problem. Disclaimer: I know next to nothing about Java or Eclipse, so bear with me.
I created a bitmap, which I put into an ImageView(?), and now the tutorial says to add the ImageView to the root_layout, but to be fair, I have no idea what the root_layout is (I Googled some, but couldn't find the right answer). Also, Eclipse gives me the 'layoutroot cannot be resolved or is not a field'-error, which I do not know how to solve. My question then is, how do I get the image to display on the screen? Thanks in advance :-)
Here is my (full) code:
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.LinearLayout;
public class ShowImage extends ActionBarActivity {
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.show_image, 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);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
// shows the activity
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_image);
try {
// load large image from resources
Bitmap game_image = BitmapFactory.decodeResource(this.getResources(), R.drawable.sample_0);
// create cropped image from loaded image
Bitmap cropped = Bitmap.createBitmap(game_image, 0, 0, 100, 100);
// no longer need larger image
game_image.recycle();
// create ImageView to display image
ImageView imageView = new ImageView(this);
imageView.setImageBitmap(cropped);
// add ImageView to root layout
LinearLayout root = (LinearLayout)this.findViewById(R.id.root_layout);
root.addView(imageView);
}
// catch comes here
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
// shows GamePlay-activity after three seconds
Intent intent = new Intent(ShowImage.this, GamePlay.class);
ShowImage.this.startActivity(intent);
ShowImage.this.finish();
}
}, 3000);
}
}
Added .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"
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="nl.mprog.projects.nPuzzle10206353.ShowImage" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Wait three seconds..." />
</RelativeLayout>
root_layout is basically the existing layout in your xml in which you want to add newly created View.
Assign id root_layout to the RelativeLayout in your xml file.
OR
Keep a new Layout inside it with root_layout id.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/root_layout"
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="nl.mprog.projects.nPuzzle10206353.ShowImage" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Wait three seconds..." />
</RelativeLayout>
So now when you use this in Activity:
RelativeLayout root = (RelativeLayout)this.findViewById(R.id.root_layout);
root.addView(imageView);
imageView would be added to that RelativeLayout with id root_layout
add the imageView to your xml:
<ImageView android:id="#+id/mImageView"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:contentDescription="solecito"
android:layout_weight = "1"
android:layout_gravity="center"
/>
then add it on you onCreate Method
ImageView im = (ImageView)findViewById(R.id.mImageView);
after you can add the image
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.image);
im.setImageBitmap(bitmap);
package com.tommymacwilliam.androidwalkthroughapp3;
import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.ImageView;
import android.widget.Toast;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
public class AndroidWalkthroughApp3 extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
// load large image from resources
Bitmap background = BitmapFactory.decodeResource(this.getResources(), R.drawable.puzzle_0);
// create cropped image from loaded image
Bitmap cropped = Bitmap.createBitmap(background, 0, 0, 230, 230);
// no longer need larger image
background.recycle();
// create ImageView to display image
ImageView imageView = new ImageView(this);
imageView.setImageBitmap(cropped);
// add ImageView to root layout
LinearLayout root = (LinearLayout)this.findViewById(R.id.root_layout);
root.addView(imageView);
int screenWidth = this.getResources().getDisplayMetrics().widthPixels;
Toast.makeText(this, String.valueOf(screenWidth), Toast.LENGTH_LONG).show();
}
catch (OutOfMemoryError e) {
// uh oh.
}
}
}
I am trying to validate a edittext using the seterror method.I am using the focus changed listener for checking whether the edittext has length of zero or not.But when i try to type into the required edittext, i cannot type into it and the text is being typed into the second one.Please help!!
The code:
package com.example.usernamevalidation;
import android.os.Bundle;
import android.app.Activity;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Menu;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.widget.EditText;
public class MainActivity extends Activity {
EditText txtusername,txtpassword;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtusername=(EditText) findViewById(R.id.txtusername);
txtpassword=(EditText) findViewById(R.id.txtpassword);
txtusername.setOnFocusChangeListener(new OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if(!hasFocus)
{
if(txtusername.getText().toString().length()==0)
{
txtusername.requestFocus();
txtusername.setError("Username cannot be left blank");
}
}
}
});
}
#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;
}
}
The xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<EditText
android:layout_width="300px"
android:layout_height="wrap_content"
android:id="#+id/txtusername"
/>
<EditText
android:layout_width="300px"
android:layout_height="wrap_content"
android:id="#+id/txtpassword"
/>
</LinearLayout>
Remove this line : txtusername.requestFocus();
Use a TextWatcher and in its onTextChanged() check whatever you want.
it is very simple you have create more your code more complex let try this code Use TextUtils TextUtils.isEmpty-Returns true if the string is null or 0-length.
EditText txtusername = (EditText) findViewById(R.id.txtusername);
EditText txtpassword = (EditText) findViewById(R.id.txtpassword);
if(TextUtils.isEmpty(txtusername.getText().toString())){
txtusername.setError("Username cannot be left blank");
txtusername.requestFocus();
}
if(TextUtils.isEmpty(txtpassword.getText().toString())){
txtpassword.setError("password cannot be left blank");
txtpassword.requestFocus();
}
//do logging process
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.
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);