从Firebase调用外部动态网址

时间:2018-12-10 16:29:23

标签: android firebase android-studio

我试图获取包含在Firebase数据库中的url。该url是动态的,并且由客户端手动更改,这就是为什么我从数据库调用的原因。

我在下面使用代码。

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(link1));
        startActivity(browserIntent);

我在firebase事件后使用此行,因为字符串是从firebase调用的网址。

public class linkbir extends AppCompatActivity  {

    FirebaseDatabase database = FirebaseDatabase.getInstance();
    DatabaseReference soyRef = database.getReference();

    String link1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_linkbir);







        try {
            soyRef.addValueEventListener(new ValueEventListener() {
                @Override
                public void onDataChange(final DataSnapshot dataSnapshot) {


                    link1 = dataSnapshot.child("alinkbir").getValue().toString();





                }
                @Override
                public void onCancelled(DatabaseError error) {
                }
            });

        } catch (Exception e) {
            Toast.makeText(getApplicationContext(), "Database hatası : " + e.getMessage(), Toast.LENGTH_LONG).show();
        }





        Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(link1));
        startActivity(browserIntent);

    }



}

但是我遇到错误,应用停止运行。这是错误日志。

E/AndroidRuntime: FATAL EXCEPTION: main
                      Process: com.sacitkralin.askerleriyiz, PID: 11262
                      java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sacitkralin.askerleriyiz/com.sacitkralin.askerleriyiz.linkbir}: java.lang.NullPointerException: uriString
                          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2984)
                          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)
                          at android.app.ActivityThread.-wrap14(ActivityThread.java)
                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642)
                          at android.os.Handler.dispatchMessage(Handler.java:102)
                          at android.os.Looper.loop(Looper.java:154)
                          at android.app.ActivityThread.main(ActivityThread.java:6776)
                          at java.lang.reflect.Method.invoke(Native Method)
                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1518)
                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
                       Caused by: java.lang.NullPointerException: uriString
                          at android.net.Uri$StringUri.<init>(Uri.java:475)
                          at android.net.Uri$StringUri.<init>(Uri.java)
                          at android.net.Uri.parse(Uri.java:437)
                          at com.sacitkralin.askerleriyiz.linkbir.onCreate(linkbir.java:76)
                          at android.app.Activity.performCreate(Activity.java:6956)
                          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
                          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
                          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045) 
                          at android.app.ActivityThread.-wrap14(ActivityThread.java) 
                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642) 
                          at android.os.Handler.dispatchMessage(Handler.java:102) 
                          at android.os.Looper.loop(Looper.java:154) 
                          at android.app.ActivityThread.main(ActivityThread.java:6776) 
                          at java.lang.reflect.Method.invoke(Native Method) 
                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1518) 
                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408) 
    Application terminated.

第76行是

    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(link1));

0 个答案:

没有答案