Android新手。不知道我应该上传多少方法,所以我将上传带有错误的just方法。
我正在关注Android应用程序开发傻瓜版第3版,但即使我检查了代码差异,也会收到错误。
这是方法。
package com.dan190.tasks.activity;
import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toolbar;
import com.dan190.tasks.R;
import com.dan190.tasks.fragment.TaskEditFragment;
public class TaskEditActivity extends Activity {
public static final String EXTRA_TASKID = "taskId";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_task_edit);
setActionBar((Toolbar) findViewById(R.id.toolbar));
long id = getIntent().getLongExtra(TaskEditActivity.EXTRA_TASKID, 0L);
Fragment fragment = TaskEditFragment.newInstance(id);
String fragment_tag = TaskEditFragment.DEFAULT_FRAGMENT_TAG;
/** This part below is where the bug happens
** If I comment this part out, app still runs
**/
if (savedInstanceState == null) {
getFragmentManager().beginTransaction().add(
R.id.container,
fragment,
fragment_tag).commit();
}
}
}
这是错误
07-17 11:52:47.110 29969-29969/com.dan190.tasks E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.dan190.tasks, PID: 29969
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dan190.tasks/com.dan190.tasks.activity.TaskEditActivity}: java.lang.IllegalArgumentException: Target must not be null.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.IllegalArgumentException: Target must not be null.
at com.squareup.picasso.RequestCreator.into(RequestCreator.java:553)
at com.squareup.picasso.RequestCreator.into(RequestCreator.java:536)
at com.dan190.tasks.fragment.TaskEditFragment.onCreate(TaskEditFragment.java:56)
at android.app.Fragment.performCreate(Fragment.java:2031)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:863)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.app.BackStackRecord.run(BackStackRecord.java:833)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1452)
at android.app.Activity.performStart(Activity.java:5952)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
由于