这里我陈列一下简版代码:public class IsiCamera extends Activity {
  ...
  public void onCreate(){
    final CameraSurfaceView cameraView = ...;
    setOnClickListener(){
      cameraView.takeAPicture()....
    }
  }
  ...
}
程序正常运行现在由于setOnClickListener()方法过于长,我把它外包出去,记作private void setListener() {
    setOnClickListener(){
      cameraView.takeAPicture()....
    }
}
因为setOnClickListener()里用到cameraView对象,把cameraView实例化的语句放到了public void onCreate()的外面,使之成为Member data.
总的代码如下:public class IsiCamera extends Activity {
  ...
  final CameraSurfaceView cameraView = ...;
  
  public void onCreate(){
    setListener();    
  }  private void setListener() {
    setOnClickListener(){
      cameraView.takeAPicture()....
    }
}
eclipse没有报错,但程序跑不起来了,求解答。

解决方案 »

  1. 怎么没有setContentView?是不是因为你,第一个你单击屏幕就会触发照相事件,因为你注册了一个OnClickListener事件。而第二个你是通过调用一个方法来实现你的照片功能。我觉得这里还是跟程序的初始化有关。
      

  2. setContentView有的,onClickListener具体来说是一个Button captureBtn.onClickListener(),第二段程序的cameraView.takeAPicture()仍然是在setOnClickListener方法里包着的啊,也是button触发的……
      

  3. 我不知道log什么时候产生的,8-30号9:40我又run了一次,但最新的log还是8-29号的。不知道是不是针对这个版本程序的。
    !ENTRY com.android.ide.eclipse.adt 4 0 2011-08-29 20:00:23.437
    !MESSAGE Malformed javadoc, rejected by FormText for node string: '@Strings@, with optional simple formatting, can be stored and retrieved as resources. You can add formatting to your string by using three standard HTML tags: b, i, and u. If you use an apostrophe or a quote in your string, you must either escape it or enclose the whole string in the other kind of enclosing quotes.'
    !STACK 0
    java.lang.IllegalArgumentException: Argument not valid Content is not allowed in prolog.
    at org.eclipse.swt.SWT.error(SWT.java:3865)
    at org.eclipse.ui.internal.forms.widgets.FormTextModel.parseInputStream(FormTextModel.java:133)
    at org.eclipse.ui.internal.forms.widgets.FormTextModel.parseTaggedText(FormTextModel.java:111)
    at org.eclipse.ui.forms.widgets.FormText.setText(FormText.java:673)
    at com.android.ide.eclipse.adt.internal.editors.ui.SectionHelper.createFormText(SectionHelper.java:352)
    at com.android.ide.eclipse.adt.internal.editors.ui.tree.UiElementDetail.createUiAttributeControls(UiElementDetail.java:268)
    at com.android.ide.eclipse.adt.internal.editors.ui.tree.UiElementDetail.selectionChanged(UiElementDetail.java:109)
    at org.eclipse.ui.forms.DetailsPart$1.run(DetailsPart.java:274)
    at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
    at org.eclipse.ui.forms.DetailsPart.showPage(DetailsPart.java:261)
    at org.eclipse.ui.forms.DetailsPart.update(DetailsPart.java:234)
    at org.eclipse.ui.forms.DetailsPart.selectionChanged(DetailsPart.java:219)
    at org.eclipse.ui.forms.ManagedForm.fireSelectionChanged(ManagedForm.java:148)
    at com.android.ide.eclipse.adt.internal.editors.ui.tree.UiTreeBlock$1.selectionChanged(UiTreeBlock.java:265)
    at org.eclipse.jface.viewers.Viewer$2.run(Viewer.java:162)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.core.runtime.Platform.run(Platform.java:888)
    at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:48)
    at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
    at org.eclipse.jface.viewers.Viewer.fireSelectionChanged(Viewer.java:160)
    at org.eclipse.jface.viewers.StructuredViewer.updateSelection(StructuredViewer.java:2132)
    at org.eclipse.jface.viewers.StructuredViewer.handleSelect(StructuredViewer.java:1160)
    at org.eclipse.jface.viewers.StructuredViewer$4.widgetSelected(StructuredViewer.java:1190)
    at org.eclipse.jface.util.OpenStrategy.fireSelectionEvent(OpenStrategy.java:228)
    at org.eclipse.jface.util.OpenStrategy.access$4(OpenStrategy.java:222)
    at org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrategy.java:389)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3910)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3503)
    at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2405)
    at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2369)
    at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2221)
    at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:500)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:493)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
    at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:113)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:194)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:368)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:559)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:514)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1311)
      

类似问题 »