【问题标题】:The method is undefined for the type in EclipseEclipse 中的类型未定义该方法
【发布时间】:2013-09-07 10:28:49
【问题描述】:

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);
    }

【问题讨论】:

  • 请发布您的堆栈跟踪
  • @ankit 没有堆栈跟踪,它不会告诉你任何事情。在发布此类 cmets 之前,请仔细阅读。谢谢。

标签: java eclipse methods undefined


【解决方案1】:

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

【讨论】:

  • 也尝试重新启动 Eclipse。
【解决方案2】:

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

您的代码中没有PopMessageimport 语句,因此我假设它是您已实现的类,并且包含在与您发布的Activity 相同的包中。

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

【讨论】:

    【解决方案3】:

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

    【讨论】:

      猜你喜欢
      • 2022-11-03
      • 1970-01-01
      • 1970-01-01
      • 2012-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-08
      相关资源
      最近更新 更多