• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps setVisibility on a null object reference

hello. i have error like this :


E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.yk.danaberkah, PID: 15413
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.LinearLayout.setVisibility(int)' on a null object reference
at com.yk.danaberkah.MainActivity.onNavigationItemSelected(MainActivity.java:154)
at com.google.android.material.navigation.NavigationView$1.onMenuItemSelected(NavigationView.java:170)
at androidx.appcompat.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:840)
at androidx.appcompat.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:158)
at androidx.appcompat.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:991)
at com.google.android.material.internal.NavigationMenuPresenter$1.onClick(NavigationMenuPresenter.java:352)
at android.view.View.performClick(View.java:4863)
at android.view.View$PerformClick.run(View.java:19981)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:902)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:697)
I/Process: Sending signal. PID: 15413 SIG: 9
Application terminated.


this my MainActivity.java

Java:
public class MainActivity extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener {

    LinearLayout kontenhome, kontendonasi, kontenwakaf, kontenzakat, kontennotifikasi, konteninformasi, kontensyaratdanketentuan;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    FloatingActionButton fab = findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });
    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    NavigationView navigationView = findViewById(R.id.nav_view);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
        this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();

@Override
public void onBackPressed() {
    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}
@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();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    if (id == R.id.nav_home) {
        kontenhome.setVisibility(View.VISIBLE);
        kontendonasi.setVisibility(View.GONE);
        kontenwakaf.setVisibility(View.GONE);
        kontenzakat.setVisibility(View.GONE);
        kontennotifikasi.setVisibility(View.GONE);
        konteninformasi.setVisibility(View.GONE);
        kontensyaratdanketentuan.setVisibility(View.GONE);
    }
    if (id == R.id.nav_donasi) {
        kontendonasi.setVisibility(View.VISIBLE);
        kontenhome.setVisibility(View.GONE);
        kontenwakaf.setVisibility(View.GONE);
        kontenzakat.setVisibility(View.GONE);
        kontennotifikasi.setVisibility(View.GONE);
        konteninformasi.setVisibility(View.GONE);
        kontensyaratdanketentuan.setVisibility(View.GONE);
    } else if (id == R.id.nav_wakaf) {
        kontenwakaf.setVisibility(View.VISIBLE);
        kontenhome.setVisibility(View.GONE);
        kontendonasi.setVisibility(View.GONE);
        kontenzakat.setVisibility(View.GONE);
        kontennotifikasi.setVisibility(View.GONE);
        konteninformasi.setVisibility(View.GONE);
        kontensyaratdanketentuan.setVisibility(View.GONE);

    } else if (id == R.id.nav_zakat) {
        kontenzakat.setVisibility(View.VISIBLE);
        kontenhome.setVisibility(View.GONE);
        kontendonasi.setVisibility(View.GONE);
        kontenwakaf.setVisibility(View.GONE);
        kontennotifikasi.setVisibility(View.GONE);
        konteninformasi.setVisibility(View.GONE);
        kontensyaratdanketentuan.setVisibility(View.GONE);

    } else if (id == R.id.nav_notification) {
        kontennotifikasi.setVisibility(View.VISIBLE);
        kontenhome.setVisibility(View.GONE);
        kontendonasi.setVisibility(View.GONE);
        kontenwakaf.setVisibility(View.GONE);
        kontenzakat.setVisibility(View.GONE);
        konteninformasi.setVisibility(View.GONE);
        kontensyaratdanketentuan.setVisibility(View.GONE);

    } else if (id == R.id.nav_informasi) {
        konteninformasi.setVisibility(View.VISIBLE);
        kontenhome.setVisibility(View.GONE);
        kontendonasi.setVisibility(View.GONE);
        kontenwakaf.setVisibility(View.GONE);
        kontenzakat.setVisibility(View.GONE);
        kontennotifikasi.setVisibility(View.GONE);
        kontensyaratdanketentuan.setVisibility(View.GONE);

    } else if (id == R.id.nav_syarat_dan_ketentuan) {
        kontensyaratdanketentuan.setVisibility(View.VISIBLE);
        kontenhome.setVisibility(View.GONE);
        kontendonasi.setVisibility(View.GONE);
        kontenwakaf.setVisibility(View.GONE);
        kontenzakat.setVisibility(View.GONE);
        kontennotifikasi.setVisibility(View.GONE);
        konteninformasi.setVisibility(View.GONE);

    }

    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}
}

setVisibility on a null object reference, why?
Thanks :)

Maintain a persistent connection with the server in background from android oreo client

I built a VoIP calling app which maintains a persistent connection with the server to listen to any incoming calls. I implemented a background service to do this.

But since Oreo, this running code is now broken because of the introduction of [Background Execution Limits] (https://developer.android.com/about/versions/oreo/background.html)

After looking into forums, I found that some people are suggesting Convert Service to JobService and let android schedule it Doing so, my app won't be able to receive calls when it is stopped Run your operations in foreground services It is annoying for some users to see a constant notification in the notification bar. So these above-mentioned options aren't working for me to fix my code for Oreo. How can I maintain a persistent connection with the server to be ready for incoming VOIP calls?

Help Can't Set Up Email

To give some context...I had to reset my phone about a month ago when it was acting up (the battery would drain quickly for no reason). The reset worked but now I'm having trouble setting up my email!

I go into the default email app (which I like) and type in my Gmail account information, all is good. Then I click on the password field and I am met with a 403 error, stating "disallowed_useragent"!

I didn't do anything special with the phone and email was working just fine before the reset. I prefer using this app because it allows me to switch between accounts and I like the UI. I'm currently using Outlook which I don't like as much.

How do I get Google to allow me to login?

Floating menu icon wont go away!

Hello, I am looking for someone to help me. Recently on my S10+ a floating menu button appeared on my screen. I can't get it to go away. I can't even move it. When I click on it. 6 options appear. Notifications, quick settings, home, back, point scan, Overview, Disabled auto select. I have tried everything to remove it. I've even done a soft reset. I've deleted all 3rd party apps. I did put it in safe mode and it was gone. I've been on Samsung's help line and they remotely into my phone. It's still there. Help me please. I feel like this thing is recording my every move.

Help Location Services Keep Turning On

If it helps, here is the about for my phone:
Galaxy A5 (2017)
Model : SM-A520W
Android : 8.0.0
Kernal : 3.18.14-15252667-QB24005864 (plus some other stuffs)
Build : R16NW.A520WVLS9CSE2

I don't recall how long ago it started... but at least a few months now.
The Location services keep turning on randomly.
I've gradually been cutting out more and more apps and stuff from permission to use it.
As of last night, I went through all my apps and disabled permission to access Location for every single one... except 'Google Play services' because it won't let me.
I have also turned off the 'can change system settings' for most of the apps that have that option.
I even went so far as to turn off the option to send location information to emergency services.

Sure enough, I check for messages on my phone and Location services turns on again.
It only turns on while I am using my phone... and every time it asks if I would like to improve the accuracy.

A little more information : I close apps when I'm not using them. I just hit the 'open tabs' thing and tell it to close them. I could probably leave texting or such open, but I'm not even using them daily.

The services turn on at any time... from the moment I unlock the screen to the moment I turn off the screen.
Playing a game, writing a text message, middle of a call, or having just unlocked it to do one of those... and it suddenly turns on Location services and asks to turn on 'Advanced Location'.

If you have any guidance on what might be doing this, let me know please.
- Esperologist

Notifications missing

Hi all I need help with the notification settings on my samsung s10+. Exept for whatsapp, I'm not receiving any notifications at all. When I go to the App info of an app, the notification settings are set to allowed, in the lock screen settings notifications is turned on, do not disturb is turned off. Even in the notification settings, there is a list of recently send notifications but I haven't seen any of them. Somewhere there is probably a hidden setting where it says it shouldn't show notifications but I cannot find it. Can anyone please give some tips?

Losing internet connection

My Galaxy Tab S2 has recently started to lose its Internet connection - when everything else on the same network is doing fine. Trying to reconnect often gives an authentication error, or it just spins and spins. The only thing that helps is restarting the tablet. Anyone else had this happen and found a solution? I've had the tablet a few years now. It's always been fine until now. Thanks.

Apps What is the difference android and androidx

Hai i just learn about android developement, why i can't add despendencies support.
example if i add this despendencies :

implementation 'com.android.support:cardview-v7:28.0.0'

Always out notification:

Version 28 (intended for Android Pie and below) is the last version of the legacy support library, so we recommend that you migrate to AndroidX libraries when using Android Q and moving forward. The IDE can help with this: Refactor > Migrate to AndroidX... less... (Ctrl+F1)

So i must migrate to androidx, and then despendencies change to :

implementation 'androidx.cardview:cardview:1.0.0'

Because if i learn on tutorial, always use android not androidx, but i can't use android despendencies.
Thanks :)

SpannableStringBuilder is clearing formatting!?

hello everybody
i'm learning to program in Java for Android. i'm trying to format text on a TextView using SpannableStringBuilder. but, for some reason, when the code gets to line 42, the first part of the text loses the formatting.
(button is a simple Button and textView is a simple TextView, both defined in activity_main.xml)

Java:
package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.RelativeSizeSpan;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    boolean answer_ison;
    Button button;
    TextView textView;
    SpannableStringBuilder str;
    final RelativeSizeSpan title_span = new RelativeSizeSpan(1.6f);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        answer_ison = true;
        button = findViewById(R.id.button);
        textView = findViewById(R.id.textView);
        str = new SpannableStringBuilder();

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (answer_ison) {
                    str.clear();
                    str.clearSpans();
                    str.append("Question:\n", title_span, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                    str.append("The question goes here :)");
                    button.setText("Show Answer");
                    answer_ison = false;
                }
                else {
                    str.append("\n\nAnswer:\n", title_span, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                    str.append("Aand the answer goes here");
                    button.setText("Next Question");
                    answer_ison = true;
                }
                textView.setText(str);
            }
        });

    }
}

first its like this (its what I expect):
Screenshot_20190714-105219_My Application.jpg

but if I press the button, it seems to clear the the formatting of the first part:
Screenshot_20190714-105222_My Application.jpg

any help is apreciated. thanks in advance!

Sensetive ProgressBar - Retrofit

I want to change the save button to show the download status instantly when the user clicked the "save" button in the image upload process in the Android application. In other words, when the upload is complete, the "save" button will show progress and the okey button will appear when the upload is complete.

What kind of structure do I have to use for this? I've searched, but I guess I'm not a complete solution because I'm a beginner. Do you have a library, video tutorial or a suggestion?

Google drive and game play

I hope i can explain this good !!

But with Google coming out with the *Stadia * for streaming games , I was just wondering if they have made a app for your cell phones to stream your games ?

Like you have the Google Drive ok ..But how about let us us down load games to our google drives and save space on phones , and let us stream from the google drive too!

or is there a app that will let you do this already ?

Or is this just a crazy idea ?

S8 front lens

So...wife dicked her phone. Dropped it and cracked the glass top corner and the bottom corner.

Is this actual glass? I bought an 'original S8 replacement lens' it seems more plastic. But I think it goes down with two sided tape not the glue I've seen on videos. Anyone try this or do it? Looking at the videos I'm less adventurous than when I bought it.

Do places actually replace this as opposed to the whole screen and digitizer? Really dont want to spend 300$ to have it fixed right now.

Looking on your experiences....have you done it?

Help Question about shortcut Wifi Icon

I use my wifi connection 95% of the time. I have no problems with it connecting to my phone and to the internet. Occasionally, the wifi shortcut icon has an exclamation mark in it and I can't find what that means. Everything I've read is about the wifi icon on the notification bar. Mine is on the shortcut and its definitely not that it isn't connected to the internet. I always check my internet connection when that happens and it is fine. Does anyone know what it means?
Thanks in advance,
Screenshot_20190713-205218.png

Help Symphony i95 rooting

I thought _Chinese Manfacted device is easy to route. But I can not root my "Symphony i95" (spreadtrum-Oreo 8.1.0). Because ... the lack of Flashable file and my allergy about "S.P. Flashtool" !!! Do not get device connection even after trying harder ... Is there anyone, who worked with the device?! Please... Work with the device. Thanks.

Screenshot_20190714-031101~2.png

advantage or disadvantage of moving to VZ

I have my pixel2 with FI since it came out. This phone has lot of good stuff that no other phone has, but also some stupid glitches which takes Google for ever to fix, like " mixing up beep and greeting" (fixed for now) or "VM not loading" or "after dialing the call doesn't connect". I'm out of big red for 2 years now and thinking of if joining them these problems won't happen. How about the bloatware they load on the phone? would I have it on my phone when joining them?
thanks

False/Misleading ads becoming commonplace

I have noticed a big increase in the number of ads that are nothing like the game they advertise. I have noticed several latelybwhich are almost exactly the same but with diferent graphics. Yhis is quite annoying to me, anyone else? I wonder is there a wau fir google/facebook/ironsource/etc to start doing something about this, I mean I wont even try anything new anymore because of it. Your thoughts?

Filter

Back
Top Bottom