我是Android的初学者。我正在开发一个应用程序。我收到了这个问题,我不知道该怎么办。
这是我在logcat中收到的:
12-01 11:53:32.485 1509-1509/? D/dalvikvm: Not late-enabling CheckJNI (already on)
12-01 11:53:32.495 1509-1509/? E/Trace: error opening trace file: No such file or directory (2)
12-01 11:53:32.509 1509-1509/? W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
12-01 11:53:32.509 1509-1509/? I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.view.WindowCallbackWrapper.onSearchRequested
12-01 11:53:32.509 1509-1509/? W/dalvikvm: VFY: unable to resolve interface method 17962: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
12-01 11:53:32.509 1509-1509/? D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
12-01 11:53:32.509 1509-1509/? I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode
12-01 11:53:32.509 1509-1509/? W/dalvikvm: VFY: unable to resolve interface method 17966: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
12-01 11:53:32.509 1509-1509/? D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
12-01 11:53:32.515 1509-1509/? I/dalvikvm: Could not find method android.content.res.Resources.getDrawable, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawable
12-01 11:53:32.515 1509-1509/? W/dalvikvm: VFY: unable to resolve virtual method 385: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
12-01 11:53:32.515 1509-1509/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
12-01 11:53:32.515 1509-1509/? I/dalvikvm: Could not find method android.content.res.Resources.getDrawableForDensity, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawableForDensity
12-01 11:53:32.515 1509-1509/? W/dalvikvm: VFY: unable to resolve virtual method 387: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
12-01 11:53:32.515 1509-1509/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
12-01 11:53:32.526 1509-1509/? D/AndroidRuntime: Shutting down VM
12-01 11:53:32.526 1509-1509/? W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xb4f5a288)
12-01 11:53:32.526 1509-1509/? E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mouna.androidproject/com.example.mouna.androidproject.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
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:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.mouna.androidproject.MainActivity.onCreate(MainActivity.java:25)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
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:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
12-01 11:53:53.896 1509-1509/? I/Process: Sending signal. PID: 1509 SIG: 9
这是
这是MainActivity.java: 包com.example.mouna.androidproject;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
Button bLogout;
EditText etUsername, etAge,etName;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etUsername = (EditText)findViewById(R.id.etUsername);
etName = (EditText)findViewById(R.id.etUsername);
etAge = (EditText)findViewById(R.id.etUsername);
bLogout=(Button)findViewById(R.id.bLogin);
bLogout.setOnClickListener(this);}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.bLogin:
break;
}}}
and this `<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mouna.androidproject">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Login"
android:label="@string/title_activity_login"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".Register"
android:label="@string/title_activity_register"
android:theme="@style/AppTheme.NoActionBar"></activity>
</application>
</manifest>
` 这是Register.java:
package com.example.mouna.androidproject;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class Register extends AppCompatActivity implements View.OnClickListener {
Button bRegister;
EditText etUsername, etName, etPassword, etAge;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
etUsername = (EditText) findViewById(R.id.etUsername);
etName = (EditText) findViewById(R.id.etUsername);
etPassword = (EditText) findViewById(R.id.etUsername);
etAge = (EditText) findViewById(R.id.etUsername);
bRegister = (Button) findViewById(R.id.bRegister);
bRegister.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.bRegister:
break;
}
}
}'
答案 0 :(得分:0)
看起来您的 MainActivity 无法从您的布局中找到bLogout按钮。 检查您的布局文件。必须有 bLogin ID的按钮。
答案 1 :(得分:0)
堆栈跟踪的重要部分是:
public class javaapplication24 {
public static void main(String[] args) {
int[][] table = new int[10][10];
int i,j,k;
for(i=0;i<table.length;i++){
for(j=0;j<table.length;j++){
System.out.print(table[i][j]+" ");
}
System.out.println();
}
}
}
这意味着在MainActivity.java文件的第25行,您可以访问null变量的成员。