Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java中作为参数的字符串_Java_String_Parameters_Nullpointerexception - Fatal编程技术网

java中作为参数的字符串

java中作为参数的字符串,java,string,parameters,nullpointerexception,Java,String,Parameters,Nullpointerexception,首先,我是java语言的初学者,我想在一个问题中测试一下自己,这个问题是对用户给出的消息进行加密, 该类如图所示,不幸的是,当我试图在Main类中使用该类时,它在“线程”Main“java.lang.NullPointerException”中给了我一个异常 但它也给了我同样的例外,所以我知道我在传递字符串参数时遇到了问题, 请帮忙 问题是: public String Message; // Message == null public char []c = new char [Messag

首先,我是java语言的初学者,我想在一个问题中测试一下自己,这个问题是对用户给出的消息进行加密, 该类如图所示,不幸的是,当我试图在Main类中使用该类时,它在“线程”Main“java.lang.NullPointerException”中给了我一个异常


但它也给了我同样的例外,所以我知道我在传递字符串参数时遇到了问题, 请帮忙

问题是:

public String Message; // Message == null
public char []c = new char [Message.length()]; // NullPointerException
试试这个:

public String Message;
public char []c;
然后:

问题是:

public String Message; // Message == null
public char []c = new char [Message.length()]; // NullPointerException
试试这个:

public String Message;
public char []c;
然后:

问题是:

public String Message; // Message == null
public char []c = new char [Message.length()]; // NullPointerException
试试这个:

public String Message;
public char []c;
然后:

问题是:

public String Message; // Message == null
public char []c = new char [Message.length()]; // NullPointerException
试试这个:

public String Message;
public char []c;
然后:


您尚未为
消息
数据成员分配内存

做一些类似于:-

Message = new String();

在构造函数中,然后在
readMessage
中为
c[]分配内存

您尚未为
消息
数据成员分配内存

做一些类似于:-

Message = new String();

在构造函数中,然后在
readMessage
中为
c[]分配内存

您尚未为
消息
数据成员分配内存

做一些类似于:-

Message = new String();

在构造函数中,然后在
readMessage
中为
c[]分配内存

您尚未为
消息
数据成员分配内存

做一些类似于:-

Message = new String();
在构造函数中,然后在
readMessage
中为
c[]分配内存

尝试以下代码:

public class engToEnc {


public String Message;
public char []c ;



public String readMessage(String pMessage)            
{


    this.Message = pMessage;
    this.c = new char [Message.length()]
    for(int i = 0 ; i < Message.length() ; i++)
    {
        c[i] = Message.charAt(i);
        c[i] += (char)27;
    }

    Message = String.copyValueOf(c);

    return Message;
  }
}
公共类英语{
公共字符串消息;
公共字符[]c;
公共字符串读取消息(字符串pMessage)
{
this.Message=pMessage;
this.c=新字符[Message.length()]
对于(int i=0;i
尝试以下代码:

public class engToEnc {


public String Message;
public char []c ;



public String readMessage(String pMessage)            
{


    this.Message = pMessage;
    this.c = new char [Message.length()]
    for(int i = 0 ; i < Message.length() ; i++)
    {
        c[i] = Message.charAt(i);
        c[i] += (char)27;
    }

    Message = String.copyValueOf(c);

    return Message;
  }
}
公共类英语{
公共字符串消息;
公共字符[]c;
公共字符串读取消息(字符串pMessage)
{
this.Message=pMessage;
this.c=新字符[Message.length()]
对于(int i=0;i
尝试以下代码:

public class engToEnc {


public String Message;
public char []c ;



public String readMessage(String pMessage)            
{


    this.Message = pMessage;
    this.c = new char [Message.length()]
    for(int i = 0 ; i < Message.length() ; i++)
    {
        c[i] = Message.charAt(i);
        c[i] += (char)27;
    }

    Message = String.copyValueOf(c);

    return Message;
  }
}
公共类英语{
公共字符串消息;
公共字符[]c;
公共字符串读取消息(字符串pMessage)
{
this.Message=pMessage;
this.c=新字符[Message.length()]
对于(int i=0;i
尝试以下代码:

public class engToEnc {


public String Message;
public char []c ;



public String readMessage(String pMessage)            
{


    this.Message = pMessage;
    this.c = new char [Message.length()]
    for(int i = 0 ; i < Message.length() ; i++)
    {
        c[i] = Message.charAt(i);
        c[i] += (char)27;
    }

    Message = String.copyValueOf(c);

    return Message;
  }
}
公共类英语{
公共字符串消息;
公共字符[]c;
公共字符串读取消息(字符串pMessage)
{
this.Message=pMessage;
this.c=新字符[Message.length()]
对于(int i=0;i
公共类英语{
公共字符串消息;//消息未声明=>message==null。
//您正在对空消息调用length()。
public char[]c=新字符[message.length()];
//而是这样做:
公共字符串消息;
公共字符[]c;
公共字符串读取消息(字符串pMessage)
{
//this.Message=pMessage;
this.message=pMessage;//现在声明了消息,我们可以调用length()。
this.c=新字符[message.length()];
对于(int i=0;i
公共类英语{
公共字符串消息;//消息未声明=>message==null。
//您正在对空消息调用length()。
public char[]c=新字符[message.length()];
//而是这样做:
公共字符串消息;
公共字符[]c;
公共字符串读取消息(字符串pMessage)
{
//this.Message=pMessage;
this.message=pMessage;//现在声明了消息,我们可以调用length()。
this.c=新字符[message.length()];
对于(int i=0;i
公共类英语{
公共字符串消息;//消息未声明=>message==null。
//您正在对空消息调用length()。
public char[]c=新字符[message.length()];
//而是这样做:
公共字符串消息;
公共字符[]c;
公共字符串读取消息(字符串pMessage)
{
//this.Message=pMessage;
this.message=pMessage;//现在声明了消息,我们可以调用length()。
this.c=新字符[message.length()];
对于(int i=0;i
公共类英语{
公共字符串消息;//消息未声明=>message==null。
//您正在对空消息调用length()。
public char[]c=新字符[message.length()];
//而是这样做:
公共字符串消息;
公共字符[]c;
公共字符串读取消息(字符串pMessage)
{
//this.Message=pMessage;
this.message=pMessage;//现在声明了消息,我们可以调用length()。
this.c=新字符[message.length()];
对于(int i=0;i