简体   繁体   English

RuntimeException:无法启动活动ComponentInfo:java.lang.NullPointerException

[英]RuntimeException: Unable to start activity ComponentInfo: java.lang.NullPointerException

Hi I am trying display the data from mysql into android listview by using web services axis2. 嗨,我正在尝试通过使用Web服务axis2将mysql中的数据显示到android listview中。 When I run my app getting the following exeption. 当我运行我的应用程序时,得到以下证据。 Here is the Logcat details 这是Logcat的详细信息

12-28 21:20:45.180: E/AndroidRuntime(406): FATAL EXCEPTION: main
12-28 21:20:45.180: E/AndroidRuntime(406): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.kbj/com.kbj.Invitation}: java.lang.NullPointerException
12-28 21:20:45.180: E/AndroidRuntime(406):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
12-28 21:20:45.180: E/AndroidRuntime(406):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
12-28 21:20:45.180: E/AndroidRuntime(406):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
12-28 21:20:45.180: E/AndroidRuntime(406):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
12-28 21:20:45.180: E/AndroidRuntime(406):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-28 21:20:45.180: E/AndroidRuntime(406):  at android.os.Looper.loop(Looper.java:123)
12-28 21:20:45.180: E/AndroidRuntime(406):  at android.app.ActivityThread.main(ActivityThread.java:4627)
12-28 21:20:45.180: E/AndroidRuntime(406):  at java.lang.reflect.Method.invokeNative(Native Method)
12-28 21:20:45.180: E/AndroidRuntime(406):  at java.lang.reflect.Method.invoke(Method.java:521)
12-28 21:20:45.180: E/AndroidRuntime(406):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-28 21:20:45.180: E/AndroidRuntime(406):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-28 21:20:45.180: E/AndroidRuntime(406):  at dalvik.system.NativeStart.main(Native Method)
12-28 21:20:45.180: E/AndroidRuntime(406): Caused by: java.lang.NullPointerException
12-28 21:20:45.180: E/AndroidRuntime(406):  at com.kbj.Invitation.onCreate(Invitation.java:49)
12-28 21:20:45.180: E/AndroidRuntime(406):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-28 21:20:45.180: E/AndroidRuntime(406):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
12-28 21:20:45.180: E/AndroidRuntime(406):  ... 11 more
12-28 21:20:50.690: I/Process(406): Sending signal. PID: 406 SIG: 9

Here are the my functions 这是我的功能

1. retrieveData in Web Services class 1. Web Services类中的retrieveData

public ArrayList<InvitePlayerDetails> retrievePlayer(String userName){

    Connection conn=null;
    PreparedStatement stmt=null;

      ResultSet result = null; 
      String retrievedUserName = "";
      //Boolean b = false;
     // String retrievedPassword = "";
      ArrayList<InvitePlayerDetails> playersList = new ArrayList<InvitePlayerDetails>();

    try{


       conn = Util.getConnection();
       stmt =  conn.prepareStatement("SELECT kbj_username FROM kbj_registration");
       result = stmt.executeQuery();
       System.out.println(result);

       while(result.next()){
        retrievedUserName = result.getString("kbj_username");
        System.out.println(retrievedUserName);
        InvitePlayerDetails p1 = new InvitePlayerDetails(retrievedUserName, false);
       // ArrayList<InvitePlayerDetails> playersList = new ArrayList<InvitePlayerDetails>(retrievedUserName, b);
        playersList.add(p1);

        System.out.println("PlayerListAdded" + playersList);
    }


      }
      catch(SQLException e)
      {
          e.printStackTrace();
      }

      finally
        {           
        Util.CloseDbResources(result, stmt, conn);

        }
return playersList;
}
}

Here is my android activity function.. 这是我的android活动函数。

public class Invitation extends Activity { 公共类邀请扩展了活动{

private final String NAMESPACE = "http://ws.kbj.com";
private final String URL = "http://10.0.2.2:8085/WS_KBJ/services/Kbj_WebService?wsdl";
private final String SOAP_ACTION = "http://ws.kbj.com/retrievePlayer";
private final String METHOD_NAME = "retrievePlayer";


@Override
protected void onCreate(Bundle savedInstanceState) {


    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.invitation);

    final TextView userName = (TextView) findViewById(R.id.CurPlayername);
    userName.setText(getIntent().getExtras().getString("UserName"));

    final Button fbBtn = (Button) findViewById(R.id.fbButton);
    final Button inviteBtn = (Button) findViewById(R.id.inviteBtn);
    ListView listView = (ListView) findViewById(R.id.invitePlayerList);  
    ArrayList<InvitePlayerDetails> playersList = new ArrayList<InvitePlayerDetails>();  


    playersList = retriveData();


    InvitePlayersBaseAdapter adapter = new InvitePlayersBaseAdapter(this, playersList);  
    listView.setAdapter(adapter);  
    listView.setOnItemClickListener(new OnItemClickListener() {  
        public void onItemClick(AdapterView<?> arg0, View v, int position,  
                long id) {  

        }  
    });  
    final Intent openFbOrTwLoginPage = new Intent(this, FbOrTwLogin.class);
    final Intent openNotificationPage = new Intent(this, Notification.class);
    fbBtn.setOnClickListener(new View.OnClickListener() {

        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            startActivity(openFbOrTwLoginPage);

        }
    });
    twBtn.setOnClickListener(new View.OnClickListener() {

        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            startActivity(openFbOrTwLoginPage);

        }
    });
    inviteBtn.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            startActivity(openNotificationPage);

        }
}

public ArrayList<InvitePlayerDetails> retriveData(){
ArrayList<InvitePlayerDetails> playersList = new ArrayList<InvitePlayerDetails>();
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo unameProp =new PropertyInfo();
    unameProp.setName("userName");//Define the variable name in the web service method
    unameProp.setValue(title);//set value for userName variable
    unameProp.setType(String.class);//Define the type of the variable
    request.addProperty(unameProp);

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

    try{
        androidHttpTransport.call(SOAP_ACTION, envelope);
           SoapPrimitive response = (SoapPrimitive)envelope.getResponse();


           System.out.println("SoapPriitive:"+response);
           //status1 = Boolean.parseBoolean(response.toString());

    }
    catch(Exception e){

    }


    return playersList;
}

} }

and I have created one pojo class which is 我创建了一个pojo类

public class InvitePlayerDetails {


private String invitedplayerName;
private boolean ckBox;
  public InvitePlayerDetails(String invitedplayerName,boolean cb1) {  
        this.invitedplayerName = invitedplayerName;  
        this.ckBox = cb1;  
    }  

public String getInvitedplayerName() {
    return invitedplayerName;
}
public void setInvitedplayerName(String invitedplayerName) {
    this.invitedplayerName = invitedplayerName;
}
public boolean getCkBox() {
    return ckBox;
}
public void setCkBox(boolean b) {
    this.ckBox = b;
}

}

Please help me about this.. Tell me where is wrong in my code.. If anyone have code about displaying a data from mysql in listviews using axis2 provide here.. Sorry for my english.. Thanks in advance.. 请帮助我。.告诉我我的代码哪里有问题。.如果有人有使用axis2在listviews中显示来自mysql数据的代码,请在这里提供。

You haven't indicate which line is 49, but I have a couple guesses: 您尚未指出哪一行是49,但我有两个猜测:

userName.setText(getIntent().getExtras().getString("UserName"));

Here you don't check if getIntent() , getExtras() , or even getString("UserName") return null. 在这里,您无需检查getIntent()getExtras()甚至getString("UserName")返回null。 You should make sure that each method returns valid data before trying to use it. 您应确保每种方法在尝试使用前都返回有效数据。

Also I don't see twBtn anywhere else: 另外我在其他任何地方都看不到twBtn

twBtn.setOnClickListener(new View.OnClickListener() {

    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        startActivity(openFbOrTwLoginPage);

    }
});

It is not initialized or even defined... 它没有初始化甚至没有定义...

If neither of these are on line 49, then double check your layout invitation.xml to make sure that every View that you search for with findViewById() is in this layout. 如果这些都不在第49行,则请仔细检查您的布局invitation.xml ,以确保您使用findViewById()搜索的每个 View都在此布局中。 Otherwise findViewById() will return null... 否则findViewById()将返回null。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java.lang.runtimeException无法启动活动componentinfo java.lang.nullpointerexception - Java.lang.runtimeexception unable to start activity componentinfo java.lang.nullpointerexception java.lang.runtimeexception无法启动活动componentinfo java.lang.nullpointerexception android - java.lang.runtimeexception unable to start activity componentinfo java.lang.nullpointerexception android (java.lang.RuntimeException):无法启动活动ComponentInfo:java.lang.NullPointerException:println需要消息 - (java.lang.RuntimeException): Unable to start activity ComponentInfo: java.lang.NullPointerException: println needs a message java.lang.RuntimeException:无法启动活动ComponentInfo:java.lang.NullPointerException:println需要消息 - java.lang.RuntimeException: Unable to start activity ComponentInfo: java.lang.NullPointerException: println needs a message java.lang.RuntimeException: 无法启动活动 ComponentInfo{....}: java.lang.NullPointerException - java.lang.RuntimeException: Unable to start activity ComponentInfo{....}: java.lang.NullPointerException java.lang.RuntimeException:无法启动活动ComponentInfo {…}:java.lang.NullPointerException - java.lang.RuntimeException: Unable to start activity ComponentInfo{…}: java.lang.NullPointerException java.lang.RuntimeException:无法启动活动ComponentInfo {...}:java.lang.NullPointerException - java.lang.RuntimeException: Unable to start activity ComponentInfo {…}: java.lang.NullPointerException java.lang.RuntimeException:无法启动活动ComponentInfo:java.lang.NullPointerException - java.lang.RuntimeException: Unable to start activity ComponentInfo: java.lang.NullPointerException Android Studio 1.0.2:java.lang.RuntimeException:无法启动活动ComponentInfo:java.lang.NullPointerException - Android Studio 1.0.2: java.lang.RuntimeException: Unable to start activity ComponentInfo: java.lang.NullPointerException java.lang.RuntimeException:无法启动活动ComponentInfo java.lang.nullpointerexception newbie code - java.lang.RuntimeException: Unable to start activity ComponentInfo java.lang.nullpointerexception newbie code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM