初学者一枚%% 2022-12-03 10:22 采纳率: 86.4%
浏览 48
已结题

写Androidstudio时,提示class/Method "XXX“ is never used”

问题遇到的现象和发生背景

写Androidstudio 时,定义一个SaveInfo类,提示“class 'SaveInfo' is never used”,
class Saveinfo 里的方法 SaveInformation‘’,提示“Method 'SaveInformation' is never used”
class Saveinfo 里的方法‘getSaveInformation’, 提示“Method 'getSaveInformation' is never used”
所以在其它.jave文件里引用这两个方法的时候,提示‘can't resovle method SaveInformation/getSaveInformation in 'SaveInfo'’

用代码块功能插入代码,请勿粘贴截图

SaveInfo .java

package com.example.myapplication9;

import android.content.Context;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class SaveInfo {
    public static boolean SaveInformation(Context context, String username, String password, String password2, String mail) {
        try {
            FileOutputStream fos = context.openFileOutput("data.txt", Context.MODE_APPEND);
            fos.write(("用户名:" + username + " 密码:" + password + "邮箱:" + mail).getBytes());
            fos.close();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
    public static Map<String, String> getSaveInformation(Context context) {
        try {
            FileInputStream fis = context.openFileInput("data.txt");
            BufferedReader br = new BufferedReader(new InputStreamReader(fis));
            String str = br.readLine();
            String[] infos = str.split("用户名:"+"密码:"+"邮箱:");
            Map<String, String> map = new HashMap<String, String>();
            map.put("username", infos[0]);
            map.put("password", infos[1]);
            fis.close();
            return map;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}

运行结果及报错内容

定义一个SaveInfo类,提示“class 'SaveInfo' is never used”,
class Saveinfo 里的方法 SaveInformation‘’,提示“Method 'SaveInformation' is never used”
class Saveinfo 里的方法‘getSaveInformation’, 提示“Method 'getSaveInformation' is never used”
所以在其它.jave文件里引用这两个方法的时候,提示‘can't resovle method SaveInformation/getSaveInformation in 'SaveInfo'’

我的解答思路和尝试过的方法

百度没有答案

我想要达到的结果

解决这个问题

  • 写回答

1条回答 默认 最新

  • 萌面超人me 2022-12-03 11:05
    关注

    因为这个类没有被使用过,不是报错,其他类中实例化他并且使用他就行了

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 4月9日
  • 已采纳回答 4月1日
  • 创建了问题 12月3日