简体   繁体   English

无法从DialogFragment类型静态引用非静态方法show(FragmentManager,String)

[英]Cannot make a static reference to the non-static method show(FragmentManager, String) from the type DialogFragment

Hey Guys i'm having a few issues with I think importation. 嗨,我在输入方面遇到一些问题。 I'm getting the error message in the title under MyDialog.show(manager, "MyDialog"); 我在MyDialog.show(manager, "MyDialog");下的标题中收到错误消息MyDialog.show(manager, "MyDialog");

Anybody know what it means? 有人知道这是什么意思吗? I'm thinking some issue with importing but i'm not to sure. 我在考虑导入方面的问题,但不确定。

Rest of code: 其余代码:

package com.example.sub_assignment1_2;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;



/**
 * A simple {@link Fragment} subclass.
 * 
 */
public class FragmentB extends Fragment implements MyDialog.Communicator {

    public FragmentB() {
        // Required empty public constructor
    }


    public void showDialog(View v)

    {
            FragmentManager manager=getFragmentManager();
            MyDialog myDialog=new MyDialog();
            MyDialog.show(manager, "MyDialog");
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_b, container, false);
    }


    @Override
    public void onDialogMessage(String message) {
        Toast.makeText(this, message,Toast.LENGTH_SHORT).show(); 

    }

}

I'm also having an issue under Toast.makeText(this, message,Toast.LENGTH_SHORT).show(); 我在Toast.makeText(this, message,Toast.LENGTH_SHORT).show();下也遇到问题 The displayed error is: Toast.makeText(this, message,Toast.LENGTH_SHORT).show(); 显示的错误是: Toast.makeText(this, message,Toast.LENGTH_SHORT).show(); Which i'm also thinking is an import error? 我还在想哪个是导入错误?

If anybody could help that would be great. 如果有人可以帮助,那就太好了。

In MyDialog.show(manager, "MyDialog"); MyDialog.show(manager, "MyDialog"); should you not have myDialog.show - ie the instance not the class? 您应该没有myDialog.show-即实例而不是类吗? Calling the method on the class name would be a static reference, which doesn't require an instance. 在类名上调用该方法将是一个静态引用,不需要实例。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 获取错误“无法对类型为Intent的非静态方法putExtra(String,String)进行静态引用” - Getting error “Cannot make a static reference to the non-static method putExtra(String, String) from the type Intent” 无法从类型XHTMLImporter静态引用非静态方法setHyperlinkStyle(String) - Cannot make a static reference to the non-static method setHyperlinkStyle(String) from the type XHTMLImporter 无法从类型teaminfo对非静态方法acceptadd(String)进行静态引用 - Cannot make a static reference to the non-static method acceptadd(String) from the type teaminfo 无法解析webView且无法从Activity类型静态引用非静态方法findViewById(int) - webView cannot be resolved & cannot make a static reference to the non-static method findViewById(int) from the type Activity 类型无法从类型View静态引用非静态方法setVisibility(int) - Type Cannot make a static reference to the non-static method setVisibility(int) from the type View 错误:“无法从类型Activity中对非静态方法startActivity(Intent)进行静态引用” - Error: “Cannot make a static reference to the non-static method startActivity(Intent) from the type Activity” 无法从类型Cmd对非静态方法getVideoURL()进行静态引用 - Cannot make a static reference to the non-static method getVideoURL() from the type Cmd 无法从View MainActivity.java类型静态引用非静态方法invalidate() - Cannot make a static reference to the non-static method invalidate() from the type View MainActivity.java Java - 无法从类型“something”中对非静态方法“something”进行静态引用 - Java - Cannot make a static reference to the non-static method "something" from the type "something" 无法使 static 引用非静态方法 --- 从类型 --- Java Bukkit Minecraft - Cannot make a static reference to the non-static method --- from the type --- Java Bukkit Minecraft
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM