Always run directly error exit, check out the two xml, also identified in mainfest registered two activities. Back to see if the problem lies in the logcat oncreate method, I found that the shear exclude ab.setOnClickListener (new View.OnClickListener () {
@ Override
public void onClick (View v) {
/ / TODO Auto-generated method stub
switch (v.getId ()) {
case R.id.about_button:
Intent i = new Intent (SuDu.this, About.class);
startActivity (i);
break;
}
}
});
Cut the program can run, do not know what wrong. Also used SuDu class implements the onClick method, and then use this keyword to SuDu direct spread setOnClickListener method does not work, or can not run the same, cut aboutButton.setOnClickListener (new View.OnClickListener (this) can also be run.
Trouble to help me see, last night to check for syntax errors, the search still see the official documentation, get a few hours have not been resolved.
SuDu.java code:
package com.example.sudu;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
import android.view.View.OnClickListener;
import android.content.Intent;
public class SuDu extends ActionBarActivity
{
@ Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_su_du);
View aboutButton = findViewById (R.id.about_button);
aboutButton.setOnClickListener (new View.OnClickListener () {
@ Override
public void onClick (View v) {
/ / TODO Auto-generated method stub
switch (v.getId ()) {
case R.id.about_button:
Intent i = new Intent (SuDu.this, About.class);
startActivity (i);
break;
}
}
});
if (savedInstanceState == null) {
getSupportFragmentManager (). beginTransaction ()
. Add (R.id.container, new PlaceholderFragment ())
. Commit ();
}
}
@ Override
public boolean onCreateOptionsMenu (Menu menu) {
/ / Inflate the menu; this adds items to the action bar if it is present
.getMenuInflater () inflate (R.menu.su_du, menu);.
return true;
}
@ Override
public boolean onOptionsItemSelected (MenuItem item) {
/ / Handle action bar item clicks here. The action bar will
/ / Automatically handle clicks on the Home / Up button, so long
/ / As you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId ();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected (item);
}
/ **
* A placeholder fragment containing a simple view.
* /
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment () {
}
@ Override
public View onCreateView (LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate (R.layout.fragment_su_du, container, false);
return rootView;
}
}
}
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Nobody to help lower it?
Reply:
Posted the wrong look.
Reply:

Reply:
04-13 12:59:37.501: D / AndroidRuntime (1228): Shutting down VM
04-13 12:59:37.501: W / dalvikvm (1228): threadid = 1: thread exiting with uncaught exception (group = 0xb3aa4ba8)
04-13 12:59:37.511: E / AndroidRuntime (1228): FATAL EXCEPTION: main
04-13 12:59:37.511: E / AndroidRuntime (1228): Process: com.example.sudu, PID: 1228
04-13 12:59:37.511: E / AndroidRuntime (1228): java.lang.RuntimeException: Unable to start activity ComponentInfo {com.example.sudu / com.example.sudu.SuDu}: java.lang.NullPointerException
04-13 12:59:37.511: E / AndroidRuntime (1228): at android.app.ActivityThread.performLaunchActivity (ActivityThread.java: 2195)
04-13 12:59:37.511: E / AndroidRuntime (1228): at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java: 2245)
04-13 12:59:37.511: E / AndroidRuntime (1228): at android.app.ActivityThread.access $ 800 (ActivityThread.java: 135)
04-13 12:59:37.511: E / AndroidRuntime (1228): at android.app.ActivityThread $ H.handleMessage (ActivityThread.java: 1196)
04-13 12:59:37.511: E / AndroidRuntime (1228): at android.os.Handler.dispatchMessage (Handler.java: 102)
04-13 12:59:37.511: E / AndroidRuntime (1228): at android.os.Looper.loop (Looper.java: 136)
04-13 12:59:37.511: E / AndroidRuntime (1228): at android.app.ActivityThread.main (ActivityThread.java: 5017)
04-13 12:59:37.511: E / AndroidRuntime (1228): at java.lang.reflect.Method.invokeNative (Native Method)
04-13 12:59:37.511: E / AndroidRuntime (1228): at java.lang.reflect.Method.invoke (Method.java: 515)
04-13 12:59:37.511: E / AndroidRuntime (1228): at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java: 779)
04-13 12:59:37.511: E / AndroidRuntime (1228): at com.android.internal.os.ZygoteInit.main (ZygoteInit.java: 595)
04-13 12:59:37.511: E / AndroidRuntime (1228): at dalvik.system.NativeStart.main (Native Method)
04-13 12:59:37.511: E / AndroidRuntime (1228): Caused by: java.lang.NullPointerException
04-13 12:59:37.511: E / AndroidRuntime (1228): at com.example.sudu.SuDu.onCreate (SuDu.java: 27)
04-13 12:59:37.511: E / AndroidRuntime (1228): at android.app.Activity.performCreate (Activity.java: 5231)
04-13 12:59:37.511: E / AndroidRuntime (1228): at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java: 1087)
04-13 12:59:37.511: E / AndroidRuntime (1228): at android.app.ActivityThread.performLaunchActivity (ActivityThread.java: 2159)
04-13 12:59:37.511: E / AndroidRuntime (1228): ... 11 more
04-13 12:59:47.431: I / Process (1228): Sending signal PID:. 1228 SIG: 9
Is this
Reply:
Button also view it
Reply:
The findviewbyid and setonclick into PlaceholderFragment in the onCreateView.
Reply:
Thank you, by the use of XML Button onClick call in methods to achieve it. Wait for the next cut to the place where you say to try.
No comments:
Post a Comment