点击myincome按钮后,我的应用程序崩溃了,我不知道为什么。我的表现看起来对我而言。是什么导致它崩溃?类似于我的大多数其他问题都被遗漏所回答,包括清单上的活动,但我已经在那里了。我感谢任何反馈。
StartingActivity:
public class StartingActivity extends AppCompatActivity
{
private TextView myincome;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_starting);
myincome = (TextView) findViewById(R.id.myIncome);
myincome.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
// Start DetailActivity
Intent j = new Intent(StartingActivity.this, DetailActivity.class);
startActivity(j);
}
});
}
}
DetailActivity:
public class DetailActivity extends AppCompatActivity
{
private TextView back;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail); //default
back = (TextView)findViewById(R.id.back);
//back button
back.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
finish();
}
});
}
清单:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".StartingActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".DetailActivity">
</activity>
<activity android:name=".CategoriesActivity">
</activity>
</application>
答案 0 :(得分:1)
查看Run
日志。必须说像
java.lang.NullPointerException: Attempt to invoke virtual method 'setOnClickListener()' on a null object reference
指着
行myincome.setOnClickListener(new View.OnClickListener()
所以myincome
为空,因为你没有为它指定任何东西。