出于某种原因,每次尝试启动我的应用程序时,我都会出现以下错误:
Unable to instantiate activity ComponentInfo{com.example.lifeahead/com.example.lifeahead.MainActivity}:java.lang.NullPointerException
Run Code Online (Sandbox Code Playgroud)
我检查了清单文件,并添加了所有活动.
我启动应用程序时使用的唯一方法是:
private void logIn(){
Button logIn = (Button) findViewById(R.id.login);
logIn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent loginIntent = new Intent(MainActivity.this, HomeActivity.class);
loginIntent.putExtra("cmUN", cmUN);
loginIntent.putExtra("cmPW", cmPW);
startActivity(loginIntent);
}
});
}
Run Code Online (Sandbox Code Playgroud)
这是onCreate:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
logIn();
}
Run Code Online (Sandbox Code Playgroud)
完整日志:
Ë
/AndroidRuntime(1607): FATAL EXCEPTION: main
E/AndroidRuntime(1607): Process: com.example.lifeahead, PID: 1607
E/AndroidRuntime(1607): java.lang.RuntimeException: Unable to instantiate …Run Code Online (Sandbox Code Playgroud) 我目前正在开发一个 Android 应用程序,该应用程序从一个名为 CloudMine 的网站获取 JSON 响应。他们的回复通常采用以下格式:
{
"success": {
"key1": { "field": "value1" },
"key2": { "field1": "value1", "field2": "value2" }
},
"errors": {
"key3": { "code": 404, "message": "Not Found" }
}
}
Run Code Online (Sandbox Code Playgroud)
我目前想循环访问“成功”对象中的所有对象,以便可以访问每个对象中的不同字段。但是,我只学会了如何从 gson API 使用 JsonParser。我得到的最接近的是在成功对象上使用名称()方法,但 Eclipse 对我大喊大叫,因为该类型未定义该方法。
我感谢任何人能给我的所有帮助。
谢谢!