method OnCreate(bundle) never gets called and application crashes - java

I've been trying to make an application that uses lock screen concepts for which as a dry run I've created an app that locks the screen once the given button is clicked, well I've used the basic concepts nothing new here's my Java code
package com.example.gaurav.locknowtest2;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.app.admin.DevicePolicyManager;
import android.app.admin.DeviceAdminReceiver;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends DeviceAdminReceiver{
public class controller extends Activity{
DevicePolicyManager dpm;
ComponentName comname;
Button b1;
TextView display;
public void OnCreate(Bundle xyz){
super.onCreate(xyz);
dpm=(DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
comname=new ComponentName(this,MainActivity.class);
setContentView(R.layout.activity_main);
b1=(Button)findViewById(R.id.start);
display=(TextView)findViewById(R.id.xyz);
b1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, comname);
startActivityForResult(intent,1);
display.setText("just to test the method");
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case 1:
if (resultCode == Activity.RESULT_OK) {
dpm.lockNow();
} else {
Log.i("DeviceAdminSample", "Administration enable FAILED!");
}
return;
}
}
}
}
next up here's my manifest that I think is creating all the problems
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gaurav.locknowtest2" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity$controller"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name=".MainActivity"
android:permission="android.permission.BIND_DEVICE_ADMIN" >
<meta-data
android:name="android.app.device_admin"
android:resource="#xml/device_admin_sample" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>
</application>
</manifest>
I need to get this done by this week so please take a look..

Your method is not written correcrt.
public void OnCreate(Bundle xyz){
you have a CAPITAL O
it should be like this:
#Override
public void onCreate(Bundle savedInstanceState) {
...
}

Java is case-sensitive, so naming your method
public void OnCreate(Bundle bundle) {
is not
protected void onCreate(Bundle bundle) {
use the #Override annotation to ensure that you actually are overriding a method.
Also, public class controller extends Activity { should be public static class controller extends Activity { apart from the fact that as per Java naming conventions, classes should start with a Capital letter.

A class extending Activity cannot be an inner class of another class because the android system needs to be able to create new instances of your Activity class without an instance of another class. Your controller class is an inner class of MainActivity so cannot be instantiated without an instance of MainActivity.
See this answer:
Nested inner Activity class in android
Also, as pointed out by others, you have a typo in onCreate. This means that you have made a completely separate method, not overridden onCreate. However this doesn't explain why the application crashes. (You can write an Activity class that doesn't override onCreate, and it works without any exceptions being thrown.)

Related

Android Plugin not working in unity with class not found exception?

I tried creating a plugin but not working in unity.I do not have much idea about Android studio but watched this video to create an android plugin.I created a new android project without any activity.So I have written two classes UnityBinder.java and Gallery.java.They are given below
UnityBinder.java
package com.techripples.unityplugin;
import android.app.Activity;
import android.content.Intent;
public class UnityBinder {
public static void OpenGallery(Activity activity)
{
Intent intent =new Intent(activity,Gallery.class);
activity.startActivity(intent);
}
}
Gallery.java class given below
package com.techripples.unityplugin;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.provider.MediaStore;
import android.net.Uri;
import android.database.*;
import com.unity3d.player.*;
public class Gallery extends Activity {
int PHOTO_GALLERY=1;
#Override
protected void onCreate(Bundle bundle)
{
super.onCreate(bundle);
Intent intent=new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent,PHOTO_GALLERY);
}
//it will run when user picks a photo from the gallery
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode==RESULT_OK && requestCode==PHOTO_GALLERY && data!=null)
{
Uri uri=data.getData();
String[] fileColoumn={MediaStore.Images.Media.DATA};
Cursor cursor=getContentResolver().query(uri,fileColoumn,null,null,null);
cursor.moveToFirst();
int coloumnIndex=cursor.getColumnIndex(fileColoumn[0]);
String photoPath=cursor.getString(coloumnIndex);
//Send path to unity to get photo
//GamObject Name,method name,argument
UnityPlayer.UnitySendMessage("Gallery","OnPhotoPick",photoPath);
Gallery.this.finish();//close activity
}
}
}
Next I have build and copied the jar file into Unity.The c# code written is as follows
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShowPicture : MonoBehaviour
{
Texture2D galleryImage;
bool isGalleryImageLoaded = false;
WWW www;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void OnGUI()
{
if(isGalleryImageLoaded)
{
GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), galleryImage);
}
if(GUI.Button(new Rect(50,50,100,100),"Open"))
{
isGalleryImageLoaded = false;
AndroidJavaClass ajc = new AndroidJavaClass("com.unity.player.UnityPlayer");
//While asking question used AndroidJavaClass instead of AndroidJavaObject
AndroidJavaObject ajo = new AndroidJavaObject("com.techripples.unityplugin.UnityBinder");
ajo.CallStatic("OpenGallery", ajc.GetStatic<AndroidJavaObject>("currentActivity"));
}
if(www!=null && www.isDone)
{
galleryImage = new Texture2D(www.texture.width, www.texture.height);
galleryImage.SetPixels32(www.texture.GetPixels32());
galleryImage.Apply();
www = null;
isGalleryImageLoaded = true;
}
}
public void OnPhotoPick(string filePath)
{
Debug.Log(filePath);
www = new WWW("file://" + filePath);
}
}
The manifest file which I copied into the Unity folder.Assets>Plugins>Android. is as follows.
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.unity3d.player"
xmlns:tools="http://schemas.android.com/tools"
android:installLocation="preferExternal">
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true"/>
<application
android:theme="#style/UnityThemeSelector"
android:icon="#mipmap/app_icon"
android:label="#string/app_name">
<activity android:name="com.unity3d.player.UnityPlayerActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
<activity android:name="com.techripples.unityplugin.Gallery"></activity>
</application>
The error I got from terminal is as follows
01-28 13:25:06.305 27032 27061 E Unity : java.lang.ClassNotFoundException: Didn't find class "com/unity/player/UnityPlayer" on path: DexPathList[[zip file "/data/app/com.testing.androidplugin-Aq1j3vpTxsomWMvd4kK7NQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.testing.androidplugin-Aq1j3vpTxsomWMvd4kK7NQ==/lib/arm, /data/app/com.testing.androidplugin-Aq1j3vpTxsomWMvd4kK7NQ==/base.apk!/lib/armeabi-v7a, /system/lib, /system/vendor/lib]]
Video of plugin done.What I am doing wrong here.
Making Of Android plugin
I dont know how the calls are being made or what should I write in the manifest for the activity to run.
If you open UnityPlayerActivity, you can see, that its package name is "com.unity3d.player" and class name is "UnityPlayer"
So you should change you unity player class name in C# script to "com.unity3d.player.UnityPlayer".
Another solution is add to your android plugin Unity classes and extend your activity from UnityPlayerActivity and you can call your methods directly from your plugin

How to receive ACTION_SCREEN_OFF with a "always running" service

I want to create an app that set/reset a timer to reproduce a song if the mobile spend 8 hours with the screen off.
I want to create a service that receive ACTION_SCREEN_OFF, but the problem is that when the app is killed from recent apps, the service is killed. I try with START_STICKY but the service is not restarted (onCreate is called sometimes but not onStart Command). I try to set in Manifest but the receiver must be register.
By now I only want that receiver detect ACTION_SCREEN_OFF.
I Have this code:
MainScreen.java (MainActivity)
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
public class MainScreen extends Activity implements View.OnClickListener{
public static final String MSG_TAG = "NoSleepMore";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_screen);
findViewById(R.id.start_service_button).setOnClickListener(this);
findViewById(R.id.stop_service_button).setOnClickListener(this);
}
#Override
public void onClick(View v){
Intent intent = new Intent(getApplicationContext(), LockService.class);
switch (v.getId()) {
case R.id.start_service_button:
Log.e(MSG_TAG,"Service started");
//starts service for the given Intent
startService(intent);
break;
case R.id.stop_service_button:
Log.e(MSG_TAG,"Service stopped");
//stops service for the given Intent
stopService(intent);
break;
}
}
}
LockService.java
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;
import android.util.Log;
public class LockService extends Service {
#Override
public IBinder onBind(Intent arg0) {
Log.i(MainScreen.MSG_TAG, "onBind()" );
return null;
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i(MainScreen.MSG_TAG, "Service Created");
/* Filtrar Acciones Capturadas */
final IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_USER_PRESENT);
// Listener
final BroadcastReceiver mReceiver = new ScreenReceiver();
// Registar Listener
registerReceiver(mReceiver, filter);
return Service.START_STICKY;
//return super.onStartCommand(intent, flags, startId);
}
#Override
public void onCreate() {
Log.i(MainScreen.MSG_TAG, "onCreate()");
}
#Override
public void onDestroy() {
Log.i(MainScreen.MSG_TAG, "onDestroy()");
}
}
ScreenRecive.java
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class ScreenReceiver extends BroadcastReceiver {
#Override
public void onReceive(final Context context, final Intent intent) {
Log.i(MainScreen.MSG_TAG,"OnReceive->");
// Log Handel
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
// do whatever you need to do here
Log.i(MainScreen.MSG_TAG,"Screen action OFF");
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
// and do whatever you need to do here
Log.i(MainScreen.MSG_TAG,"Screen action ON");
}else if(intent.getAction().equals(Intent.ACTION_USER_PRESENT)){
Log.e(MainScreen.MSG_TAG,"Action UserPresent");
}
}
}
AndroidManifext.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="es.mangel.nosleepmore">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".ScreenReceiver">
<intent-filter>
<action android:name="android.intent.action.ACTION_SCREEN_ON"/>
<action android:name="android.intent.action.ACTION_SCREEN_OFF"/>
<action android:name="android.intent.action.ACTION_USER_PRESENT"/>
</intent-filter>
</receiver>
<service android:name=".LockService" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</service>
</application>
</manifest>
The Main activity is just two buttons.
BTW I just need that run over Android 8.0.

My android app stops responding after the Splash Screen

I'm programming a new app which contains a splash screen.
I've finished it and it was all good. After I've opened android studio again to work on the navigation bar I've tried to run the app to see the result but the application stopped and crashed after the display of the splash screen.
this is Main class
package com.example.computer.bsinfoshop;
public class Main extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
and this is the class od splash screen
package com.example.computer.bsinfoshop;
import android.graphics.Typeface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class Screen extends AppCompatActivity {
TextView tv;
ImageView img;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_screen);
tv = (TextView)findViewById(R.id.textView);
img = (ImageView)findViewById(R.id.imageView);
Typeface font = Typeface.createFromAsset(getAssets(),"fonts/Satisfy-Regular.ttf");
tv.setTypeface(font);
img.setImageResource(R.drawable.rsz_2rsz_img);
Thread timerThread = new Thread(){
public void run(){
try
{
sleep(3700);
}
catch(InterruptedException e)
{
e.printStackTrace();
}
finally {
Intent intent = new Intent(Screen.this , Main.class);
startActivity(intent);
}
}
};
timerThread.start();
}
#Override
protected void onPause() {
super.onPause();
finish();
}
}
and here where i think is the problem
the manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.computer.bsinfoshop">
<application
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="#string/app_name">
<activity
android:name=".Screen"
android:theme="#style/App">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Information"
android:label="Information"
android:theme="#style/AppTheme">
</activity>
<activity
android:name="com.example.computer.bsinfoshop.Main"
android:theme="#style/AppTheme">
</activity>
</application>
</manifest>
I just want to know what is the problem in my code and how can I fix it. thank you ^^
Change Thread to something like this:
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
finish();
startActivity(new Intent(Screen.this, Main.class));
}
}, 1500);
To be honest, I think this is not the correct way of creating a Splash Screen. That way you force the user to wait for 3 seconds which causes a bad user-experience.
Have a look at that tutorial and your users will thank you! https://www.bignerdranch.com/blog/splash-screens-the-right-way/

Where am I wrong with broadcasting info from Java and receiving in Unity?

So I just started working on this project and part of it is sending packages of information from an app in Java to another Unity app.
I have been trying to follow this tutorial but I have problems getting it to work and even somewhat understanding it a bit since I have not worked with Java before.
Here is the current code I have so far.
Main Activity Class
package com.example.service3;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.content.Intent;
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.os.Build;
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.container, new PlaceholderFragment()).commit();
}
startService(new Intent(this, MyService.class));
}
#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;
}
}
}
Sender class
package com.example.service3;
import android.app.Service;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
public class MyService extends Service
{
private final Handler handler = new Handler();
private int numIntent;
// It's the code we want our Handler to execute to send data
private Runnable sendData = new Runnable() {
// the specific method which will be executed by the handler
public void run() {
numIntent++;
// sendIntent is the object that will be broadcast outside our app
Intent sendIntent = new Intent();
// We add flags for example to work from background
sendIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION|Intent.FLAG_FROM_BACKGROUND|Intent.FLAG_INCLUDE_STOPPED_PACKAGES );
// SetAction uses a string which is an important name as it identifies the sender of the itent and that we will give to the receiver to know what to listen.
// By convention, it's suggested to use the current package name
sendIntent.setAction("com.example.service3");
// Here we fill the Intent with our data, here just a string with an incremented number in it.
sendIntent.putExtra(Intent.EXTRA_TEXT, "Intent "+numIntent);
// And here it goes ! our message is send to any other app that want to listen to it.
sendBroadcast(sendIntent);
// In our case we run this method each second with postDelayed
handler.removeCallbacks(this);
handler.postDelayed(this, 1000);
}
};
#Override
public void onStart(Intent intent, int startid) {
numIntent = 0;
// We first start the Handler
handler.removeCallbacks(sendData);
handler.postDelayed(sendData, 1000);
}
#Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
}
XML for Sender
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.service3"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.service3.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:enabled="true" android:name="com.example.service3.MyService" />
</application>
Receiver Class
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class Receiver extends BroadcastReceiver
{
private static Receiver instance;
public static String text ="1";
#Override
public void onReceive(Context context, Intent intent)
{
// TODO Auto-generated method stub
String sentIntent = intent.getStringExtra(Intent.EXTRA_TEXT);
text = "-1";
}
public static void createInstance()
{
if(instance == null)
{
instance = new Receiver();
}
}
}
Unity Android Manifest
<application android:theme="#android:style/Theme.NoTitleBar.Fullscreen" android:icon="#drawable/app_icon" android:label="#string/app_name" android:debuggable="false" android:isGame="true" android:banner="#drawable/app_banner">
<activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="#string/app_name" android:screenOrientation="fullSensor" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
<receiver android:name="com.example.receiver3.MyReceiver" >
<intent-filter>
<action android:name="com.example.receiver3" ></action>
</intent-filter>
</receiver>
</application>
I realise this is a massively large post but I simply do not know what to do at this point and am somewhat considering backing out of the project for the fact that I have no idea how to get Java to communicate with Unity.
Thanks in advance.

trying to understand Java activities by following a book

I am new to programming and I am trying to figure out how Activities in android programming work by making a small app,which should let me know in which state of the activity I am.
I am getting an error in the setContentView because Android Studio says "cannot resolve symbol "R""
Here is my code:
package com.example.daniele.activity;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends Activity {
String tag = "Lifecycle";
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.d(tag, "in the onCreate() event");
}
public void onStart() {
super.onStart();
Log.d(tag, "in the onStart() event");
}
public void onRestart() {
super.onRestart();
Log.d(tag, "in the onRestart() event");
}
public void onResume() {
super.onResume();
Log.d(tag, "in the onResume() event");
}
public void onPause() {
super.onPause();
Log.d(tag, "in the onPause() event");
}
public void onStop() {
super.onStop();
Log.d(tag, "in the onStop() event");
}
public void onDestroy() {
super.onDestroy();
Log.d(tag, "in the onDestroy() event");
}
}
here is my AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.daniele.activity" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Everyone is suggesting you the fix. Good. But since you are learning, you should also understand what is happening here:
All layout files are in xml
Every xml file is compiled and made available to java classes
The compiled class is called R.java
To make
R.java available to your class you need to import it
Under
import android.util.Log;
add this
import com.example.daniele.R;
Alternatively when you see a red underline under something, you can hover above it and Android Studio usually tells you what you need to do. In this case, "Optimize Imports" or something similar.
"R" errors usually happen when one or more of your XML files is corrupt. Start by seeing if your apps manifest looks correct!
You will need to import R because your activity is in a different package.
import com.example.daniele.R;

Categories