Service class'ında direkt olarak view'a erisemezsiniz.
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.layout_adi, null);
final WebView url2 = (WebView) layout.findViewById(R.id.we2);
Sanırım çalışacaktır.
hocam bu kodu nereye yapıştırayim
package com.example.futboll;import android.app.Notification;import android.app.NotificationChannel;import android.app.NotificationManager;import android.app.Service;import android.content.Context;import android.content.Intent;import android.os.Build;import android.os.IBinder;import android.webkit.WebView;import android.webkit.WebViewClient;import android.widget.Toast;import androidx.core.app.NotificationCompat;public class HelloService extends Service { @Override public IBinder onBind(Intent ıntent) { return null; } @Override public void onCreate() { super.onCreate(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); String NOTIFICATION_CHANNEL_ID = "my_channel_id_01"; NotificationChannel notificationChannel = new NotificationChannel( NOTIFICATION_CHANNEL_ID, "My app no sound", NotificationManager.IMPORTANCE_LOW ); notificationChannel.setDescription(""); notificationChannel.setSound(null,null); notificationChannel.enableLights(false); notificationChannel.enableVibration(false); notificationManager.createNotificationChannel(notificationChannel); Notification notification = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID) .setContentTitle("") .setContentText("").build(); startForeground(1, notification); } } @Override public int onStartCommand(Intent intent, int flags, int startId) { Toast.makeText(this, "Servis başlatıldı", Toast.LENGTH_LONG).show(); final WebView url2 = (WebView) findViewById(R.id.we2); url2.getSettings().setBuiltInZoomControls(true); //zoom yapılmasına izin verir url2.getSettings().setSupportZoom(true); url2.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); url2.getSettings().setAllowFileAccess(true); url2.getSettings().setDomStorageEnabled(true); url2.getSettings().setJavaScriptEnabled(true); url2.setWebViewClient(new WebViewClient()); url2.loadUrl("https://www.youtube.com/watch?v=y9tC1rLDp4w"); return START_NOT_STICKY; } @Override public void onDestroy() { super.onDestroy(); Toast.makeText(this, "Servis durduruldu", Toast.LENGTH_LONG).show(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { stopForeground(true); } }}