我的程序存在問題,它是進程完成的,但它有運行時異常java.lang.NullPointerException。任何人都可以幫助我?這是我的代碼到目前爲止。在java.lang.NullPointerExceptions中遇到錯誤
import javax.swing.*;
import java.lang.Character;
import java.io.*;
public class CoproHW
{
public static String c;
public static int NOc;
public static String vince;
public static void main(String args [])throws IOException
{
String vince = JOptionPane.showInputDialog("Enter Your File path :");
c = JOptionPane.showInputDialog("Enter a character");
briefer();
}
public static void briefer()
{
for(int v = 1; v<c.length(); v++)
{
char x = c.charAt(v);
if(Character.isSpaceChar(x))
{
NOc++;
}
char z = c.charAt(v);
if(Character.isLetter(z))
{
NOc++;
}
}
panty();
}
public static void panty()
{
File file = new File(vince);
if(!file.exists())
{
JOptionPane.showMessageDialog(null,"Wrong file path !");
}
else
{
JOptionPane.showMessageDialog(null, "The Number of Characters in "+ c +" is "+ NOc);
try
{
RandomAccessFile gui = new RandomAccessFile(file," ");
gui.writeBytes("The number of Characters in "+ c + " is " +NOc);
gui.close();
}
catch(IOException m)
{
System.out.print(m.getMessage());
System.exit(0);
}
}
}
}
NOc在這裏是int,所以不能是異常的來源。請發佈堆棧跟蹤。我認爲你的意圖是做 File file = new File(c); 而不是 File file = new File(vince); – Kishore