小编Ibu*_*idu的帖子

char和char*(指针)

我想了解指针是如何工作的,所以我创建了这个小程序.首先,我创建了一个指向char的ap指针.

第一个问题是在这一点上.如果我创建一个指针,它的值是一个memoryaddress(如果我指向一个非指针对象),但这次它在我的例子中是"哈哈".为什么它在char*中以这种方式工作?我怎么能用cin >> p增加它的价值呢?

我的第二个问题是,我创建了一个aq char,它在我创建它的点上具有*p指针的值.但它的价值和地址也是"h",但为什么呢?它必须是此char对象的内存地址!这没有意义:D(mingw - gcc)

#include <iostream>

int main() 
{
 /* char *p;
    cin >> p;                      //forexample: haha */

    char * p = "haha";
    char q = *p;
    std::cout << "&q = " << &q << std::endl;   //&q = h
    std::cout << "q  = " <<  q << std::endl;   //q = h

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

更多:如果我首先使用char a [100]分配内存; char*p = a; 然后&q = h»ŢĹ,所以"h"和一些混乱.但它应该是一个记忆地址!我的问题是,为什么不解决呢?

c++ pointers char type-mismatch dereference

8
推荐指数
1
解决办法
6万
查看次数

Java NullPointerException - 短程序

我是Java编程的新手,我不明白我的代码中发生了什么.

它告诉我:

Exception in thread "main" java.lang.NullPointerException
    at Main.Country.addMine(Country.java:37)
    at Main.Main.main(Main.java:21)
Java Result: 1
Run Code Online (Sandbox Code Playgroud)

我的main.java很简单:

    Continent Europe = new Continent("Europe");
    Country asd = new Country("asd", Europe);
    Mine mine = new Mine(100,100,100,100);
    System.out.println(mine == null);
    asd.addMine(mine); //dies here
Run Code Online (Sandbox Code Playgroud)

这是addMine方法:

public void addMine(Mine mine) {
     System.out.println(mine == null);
     this.mines.add(mine); //dies here
     this.iron += mine.iron;
     this.gold += mine.gold;
     this.stone += mine.stone;
     this.wood += mine.wood;
     System.out.println("Mine has been successfully added to the country with the given values."
);
Run Code Online (Sandbox Code Playgroud)

和Mine.java是:

public class Mine implements Building …
Run Code Online (Sandbox Code Playgroud)

java program-entry-point runtime-error exception nullpointerexception

5
推荐指数
1
解决办法
215
查看次数

javax.servlet.jsp.JspException:无法检索表单bean的定义,引起:java.lang.NullPointerException

我一直在研究JSP项目.它使用Struts 1框架.项目很旧,我有很多页面,所以我决定添加一个新页面.我复制了一个包含所有配置,模型动作的现有页面,所以一切都应该没问题.但事实并非如此!

我想先创建一个简单的JSP文件.没有<html:form>,我看到了我的"Hello World".然后我将我的文件修改为:

<% request.setCharacterEncoding("UTF8");%>
<%@page contentType="text/html;charset=UTF-8"%>
<%@page pageEncoding="UTF-8"%>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-nested" prefix="nested"%>
<%@ taglib prefix="fa" uri="/WEB-INF/tlds/finearts"%>

<fa:checkLogon/>

<fa:Header/>
<fa:Navigation navigationId="806"/>

<html:form action="/pages/editTexts.do" method="post" onsubmit="return doSubmit(this);"     >
</html:form>
<fa:Footer/>
Run Code Online (Sandbox Code Playgroud)

并得到此错误:

org.apache.jasper.JasperException:在第15行处理JSP页面/pages/editTexts.jsp时发生异常

12: <fa:Header/>
13: <fa:Navigation navigationId="806"/>
14: 
15: <html:form action="/pages/editTexts.do" method="post" onsubmit="return     doSubmit(this);" >
16: </html:form>
17: <fa:Footer/>


Stacktrace:
    at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at …
Run Code Online (Sandbox Code Playgroud)

html java jsp struts

0
推荐指数
1
解决办法
9962
查看次数