Note that there are some explanatory texts on larger screens.

plurals
  1. POjava.lang.NullPointerException at Intent
    text
    copied!<p>I am quite new to Java and Android programming, and just working on my 3rd App - however I am encountering a Problem which I am not able to solve (I already tried and researched for days).</p> <p>I have a list of Elements in a LinearLayout inside a Fragment - the Elements have a OnLongClickListener attached, with a popup showing up when the User long-presses the Element. That works fine. However, one of the Buttons in the Popup is "Edit", and when a user presses this Button, I want to start another Activity with Editing Options for this Element.</p> <p>So there comes my Problem: when I want to start the new Activity with an Intent, I get following Error:</p> <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main java.lang.NullPointerException at android.app.Activity.startActivityForResult(Activity.java:3370) at android.app.Activity.startActivityForResult(Activity.java:3331) at android.app.Activity.startActivity(Activity.java:3566) at android.app.Activity.startActivity(Activity.java:3534) at at.fekle.zipmanager.start.startzipinfo(start.java:299) at at.fekle.zipmanager.start$2.onLongClick(start.java:277) at android.view.View.performLongClick(View.java:4247) at android.view.View$CheckForLongPress.run(View.java:17341) at android.os.Handler.handleCallback(Handler.java:725) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5227) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562) at dalvik.system.NativeStart.main(Native Method) </code></pre> <p>But, if i start the same Activity with the same Intent from a simple Button defined in the Layout, the Activity Starts fine without any Errors... weird, isn't it?</p> <p>So, does anyone have an Idea how I can solve this problem?</p> <p>Here are some extractions from my code:</p> <p><strong>The Creation of the Elements with the OnLongClickListener:</strong></p> <pre><code>ScrollView parent = (ScrollView) maininflater.inflate(R.layout.start_ziplist_fragment_superwrapper, null, false); inf = maininflater; LinearLayout ll = (LinearLayout) maininflater.inflate(R.layout.start_ziplist_fragment_wrapper, parent, false); for (Integer i = 0; i &lt; count; i++) { ArrayList&lt;String&gt; data = new DB(cont).getAllZips().get(i); View custom = maininflater.inflate(R.layout.start_ziplist_fragment_inner, ll, false); TextView tv = (TextView) custom.findViewById(R.id.ziplist_name); TextView tv2 = (TextView) custom.findViewById(R.id.ziplist_text); tv.setText(data.get(2)); tv2.setText(data.get(1)); Integer id = Integer.valueOf(data.get(0)); custom.setId(id); custom.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { Integer id = view.getId(); startzipinfo(id); return true; } }); ll.addView(custom); } parent.addView(ll); </code></pre> <p><strong>The void which starts the Activity:</strong></p> <pre><code>public void startzipinfo(Integer id){ Intent in = new Intent(getApplicationContext(), zipinfo.class); startActivity(in); } </code></pre> <p>I'm looking forward to your Answers,</p> <p>Felix</p> <p><strong>EDIT: This is the Activity which is about to be started:</strong></p> <pre><code>package at.fekle.zipmanager; import android.app.Activity; import android.os.Bundle; /** * Created by felix on 27.06.13. */ public class zipinfo extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.zipinfo); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload