0
  Button b1=(Button)findViewById(R.id.b1);
           final EditText ed=(EditText)findViewById(R.id.ed1);
           TextView t=(TextView)findViewById(R.id.t1);
           b1.setOnClickListener(new Button.OnClickListener() { 
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                     abc=ed.getText().toString();
                    Intent intent=new Intent(v.getContext(),AnotherActivity.class);
                    startActivityForResult(intent,0);


                }
                 })

这是我的主要活动代码,我正在点击按钮开始另一个活动,但是我得到了错误并且我的应用程序崩溃了,有人可以帮我删除这个错误/

02-23 14:20:06.557: E/AndroidRuntime(2732): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.newpicker/com.example.newpicker.AnotherActivity}: java.lang.NullPointerException

这是我的日志猫

public class AnotherActivity extends Activity {

 static Context context;
   public boolean a;
    private DownloadManager downloadManager;
 static TextView tt1;
  String url="http://www.digitalmarketingbox.com/";
  private DownloadManager dm;
  String v1,v2;
   ArrayList<String> imageid = new ArrayList<String>();
    ArrayList<String> imagepath = new ArrayList<String>();
   ArrayList<String> playlist_content = new ArrayList<String>();
     ArrayList<String> al=new ArrayList();
     String i1;
   @Override
   protected void onCreate(Bundle savedInstanceState) 
   {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.showimages);
            //tt1=(TextView)findViewById(R.id.text1);
            TextView tt1=(TextView)findViewById(R.id.it);
            AnotherActivity.tt1.append(MainActivity.abc);

   }

    02-23 14:35:08.561: D/dalvikvm(4900): Late-enabling CheckJNI
02-23 14:35:08.702: D/libEGL(4900): loaded /system/lib/egl/libEGL_adreno200.so
02-23 14:35:08.702: D/libEGL(4900): loaded /system/lib/egl/libGLESv1_CM_adreno200.so
02-23 14:35:08.702: D/libEGL(4900): loaded /system/lib/egl/libGLESv2_adreno200.so
02-23 14:35:08.702: I/Adreno200-EGL(4900): <eglInitialize:269>: EGL 1.4 QUALCOMM build: Nondeterministic AU_full_mako_PARTNER-ANDROID/JB-MR1-DEV_CL2961380_release_AU (CL2961380)
02-23 14:35:08.702: I/Adreno200-EGL(4900): Build Date: 12/10/12 Mon
02-23 14:35:08.702: I/Adreno200-EGL(4900): Local Branch: 
02-23 14:35:08.702: I/Adreno200-EGL(4900): Remote Branch: m/partner-android/jb-mr1-dev
02-23 14:35:08.702: I/Adreno200-EGL(4900): Local Patches: NONE
02-23 14:35:08.702: I/Adreno200-EGL(4900): Reconstruct Branch: NOTHING
02-23 14:35:08.742: D/OpenGLRenderer(4900): Enabling debug mode 0
02-23 14:35:12.936: D/AndroidRuntime(4900): Shutting down VM
02-23 14:35:12.936: W/dalvikvm(4900): threadid=1: thread exiting with uncaught exception (group=0x41d10930)
02-23 14:35:12.946: E/AndroidRuntime(4900): FATAL EXCEPTION: main
02-23 14:35:12.946: E/AndroidRuntime(4900): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.newpicker/com.example.newpicker.AnotherActivity}: java.lang.NullPointerException
02-23 14:35:12.946: E/AndroidRuntime(4900):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
02-23 14:35:12.946: E/AndroidRuntime(4900):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
02-23 14:35:12.946: E/AndroidRuntime(4900):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-23 14:35:12.946: E/AndroidRuntime(4900):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
02-23 14:35:12.946: E/AndroidRuntime(4900):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-23 14:35:12.946: E/AndroidRuntime(4900):     at android.os.Looper.loop(Looper.java:137)
02-23 14:35:12.946: E/AndroidRuntime(4900):     at android.app.ActivityThread.main(ActivityThread.java:5041)
02-23 14:35:12.946: E/AndroidRuntime(4900):     at java.lang.reflect.Method.invokeNative(Native Method)
02-23 14:35:12.946: E/AndroidRuntime(4900):     at java.lang.reflect.Method.invoke(Method.java:511)
02-23 14:35:12.946: E/AndroidRuntime(4900):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-23 14:35:12.946: E/AndroidRuntime(4900):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-23 14:35:12.946: E/AndroidRuntime(4900):     at dalvik.system.NativeStart.main(Native Method)
02-23 14:35:12.946: E/AndroidRuntime(4900): Caused by: java.lang.NullPointerException
02-23 14:35:12.946: E/AndroidRuntime(4900):     at com.example.newpicker.AnotherActivity.onCreate(AnotherActivity.java:41)
02-23 14:35:12.946: E/AndroidRuntime(4900):     at android.app.Activity.performCreate(Activity.java:5104)
02-23 14:35:12.946: E/AndroidRuntime(4900):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
02-23 14:35:12.946: E/AndroidRuntime(4900):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
02-23 14:35:12.946: E/AndroidRuntime(4900):     ... 11 more

这是我的完整日志

4

4 回答 4

1

我认为您需要更改这行代码:

b1.setOnClickListener(new Button.OnClickListener() {

进入这个:

b1.setOnClickListener(new View.OnClickListener() {

当您使用 View 作为按钮函数内部的参数来处理按钮事件侦听器时。希望它会有所帮助。

于 2013-02-23T09:00:53.720 回答
1

尝试如下:

  b1.setOnClickListener(new View.OnClickListener() { 
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                 abc=ed.getText().toString();
                Intent intent=new Intent(this,AnotherActivity.class);
                startActivity(intent);
            }
             });

并确保您已AnotherActivity在清单中定义。

于 2013-02-23T09:01:22.457 回答
1

我已将 textview 定义为上面的静态,并尝试再次将其定义为普通的,刚刚检查过,问题已解决,谢谢大家

public class AnotherActivity extends Activity {

  static Context context;
  public boolean a;
  private DownloadManager downloadManager;
  static TextView tt1;
  String url="http://www.digitalmarketingbox.com/";
  private DownloadManager dm;
  String v1,v2;
  ArrayList<String> imageid = new ArrayList<String>();
  ArrayList<String> imagepath = new ArrayList<String>();
  ArrayList<String> playlist_content = new ArrayList<String>();
  ArrayList<String> al=new ArrayList();
  String i1;
 @Override
  protected void onCreate(Bundle savedInstanceState) 
  {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.showimages);
        tt1=(TextView)findViewById(R.id.it);
        //---tt1.append(MainActivity.abc);
  }
于 2013-02-23T09:36:40.983 回答
0

这发生在我昨天。即使我定义了里面的活动,Manifest但我很难启动它。我所做的是检查我是否在清单上写了类名。为了检查它是否工作,我想把它改成MainActivity并且它工作了,所以我知道出了点问题。无论如何,我确实通过使用它使它工作

                if(Build.MANUFACTURER.contains("Samsung") || Build.MANUFACTURER.contains("samsung")){
            doAll();
            }else {
                Intent intent = new Intent(Smaller.this.getApplicationContext(),ForOthers.class);
                startActivity(intent);
                finish();
              }

这是我在用户启动我的应用程序时正在检查的内容。忘记它,看看

YourClassName.this.getApplicationContext(),OtherAcitvity.class
于 2013-02-23T09:12:47.553 回答