Java 该方法未针对 Eclipse 中的类型定义

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18604965/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 09:26:03  来源:igfitidea点击:

The method is undefined for the type in Eclipse

javaeclipsemethodsundefined

提问by Joshua

Method is undefined for the type in Eclipse. Can't seem to solve it. The error is in the lines: msg.setTimestamp( System.currentTimeMillis() ); and msg.setBody("this is a test SMS message");

Eclipse 中的类型未定义方法。好像解决不了 错误在以下几行: msg.setTimestamp( System.currentTimeMillis() ); and msg.setBody("这是一条测试短信");

package com.example.smsnotification;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;

public class PopSMSActivity extends Activity{

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //Retrieve serializable sms message object by the key "msg" used to pass to it
        Intent in = this.getIntent();
        PopMessage msg = (PopMessage) in.getSerializableExtra("msg");

        //Case where we launch the app to test the UI EG: No incoming SMS
        if(msg==null){
            msg = new PopMessage();
            con.setPhone("0123456789");
            msg.setTimestamp( System.currentTimeMillis() );
            msg.setBody("this is a test SMS message");
        }
        showDialog(msg);
    }

回答by Kai

This means the PopMessageclass doesn't provide the methods setTimestamp(long)and setBody(String).

这意味着PopMessage该类不提供方法setTimestamp(long)setBody(String).

There is no importstatement for PopMessagein your code so I assume it is a class which you have implemented and is contained in the same package as the Activitywhich you have posted.

在您的代码中没有import声明,PopMessage所以我假设它是一个您已经实现的类,并且包含在与Activity您发布的相同的包中。

So you could either solve this by implementing those two methods in PopMessageor by removing the calls.

因此,您可以通过在其中实现这两种方法PopMessage或通过删除调用来解决此问题。

回答by gia

You may also extend your Eclipse Settings by activating the "save Actions" (Window->Preferences->Java->Editor->Save Actions) and use the Option "Organize Imports". This would at least add the propbably missing Import "...PopMessage" while you press Ctrl+S.

您还可以通过激活“保存操作”(窗口->首选项->Java->编辑器->保存操作)并使用选项“组织导入”来扩展您的 Eclipse 设置。这至少会在您按下 Ctrl+S 时添加可能丢失的导入“...PopMessage”。

回答by Ashutosh Singh

Remove the code and write it back to eclipse. It worked for me....You can try copy and paste to after writing signature of function/class.

删除代码并将其写回eclipse。它对我有用....您可以在编写函数/类的签名后尝试复制并粘贴到。